Changeset 807

Show
Ignore:
Timestamp:
01/16/10 00:15:46 (8 months ago)
Author:
ghoulsblade
Message:

bugfix in mkdir default permissions and linux ifdef, new lua utils : GetHomePath,CopyDir,CopyFile

Location:
trunk/lugre
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lugre/lua/lib.util.lua

    r795 r807  
    7070        fp:write(data) 
    7171        fp:close() 
     72end 
     73 
     74function CopyFile (src,dst) -- not tested with binary/nontext files, should work, but not sure yet 
     75        --~ print("CopyFile",src,dst) 
     76        local data = FileGetContents(src) 
     77        if (data) then FilePutContents(dst,data) end 
     78end 
     79function CopyDir (src,dst,bIncludeSpecial) 
     80        --~ print("CopyDir",src,dst) 
     81        assert(file_exists(dst)) 
     82        for k,name in ipairs(dirlist(src,false,true)) do CopyFile(src..name,dst..name) end 
     83        for k,name in ipairs(dirlist(src,true,false)) do if (name ~= "." and name ~= ".." and (name ~= ".svn" or bIncludeSpecial)) then mkdir(dst..name) CopyDir(src..name.."/",dst..name.."/") end end 
     84end 
     85function GetHomePath () -- returns /home/username  without trailing slash 
     86        if (WIN32) then return end -- not yet implemented 
     87        local file = io.popen("echo $HOME") 
     88        if (not file) then return end -- popen or home dir not available 
     89        for line in file:lines() do file:close() return string.sub(line,1,-1) end -- remove newline 
     90        file:close() 
    7291end 
    7392 
  • trunk/lugre/src/lugre_scripting.general.cpp

    r805 r807  
    262262 
    263263// lua :  int   mkdir   (path,mode)             -- mode is ignored for win, 0x700 as default for linux (restrictive, only owner) 
     264//~ d--x--x--x   1+1*8+1*8*8 
     265//~ d-wx--x--x   3+3*8+3*8*8 
     266//~ drwxr-xr-x   7+7*8+7*8*8   
     267//~ drwx------         7*8*8 = oct: 0700 
     268//~ d------r-x   7           
    264269static int l_mkdir (lua_State *L) { PROFILE 
    265270        std::string sPath = luaL_checkstring(L,1); 
    266         int iMode = cLuaBindDirectQuickWrapHelper::ParamIntDefault(L,2,0x700); 
     271        int iMode = cLuaBindDirectQuickWrapHelper::ParamIntDefault(L,2,0700); 
    267272        lua_pushnumber(L,rob_mkdir(sPath.c_str(),iMode)); 
    268273        return 1; 
     
    285290        for (unsigned int i=0;i<res.size();++i) { 
    286291                lua_pushstring( L, res[i].c_str() ); 
    287                 lua_rawseti( L, -2, i ); 
     292                lua_rawseti( L, -2, i+1 ); // i+1 : lua indices start at 1 
    288293        } 
    289294        return 1; 
  • trunk/lugre/src/lugre_shell.cpp

    r806 r807  
    4545 
    4646int     rob_mkdir                       (const char* path,int perm) { 
    47         // found on http://www.devx.com/cplus/10MinuteSolution/26748/1954 
    48         #ifdef mkdir 
    49                 #ifdef WIN32 
    50                 return mkdir(path); 
    51                 #else 
    52                 return mkdir(path,(mode_t)perm); 
    53                 #endif 
     47        // found on http://www.devx.com/cplus/10MinuteSolution/26748/1954   // perm ignored for win 
     48        //~ printf("rob_mkdir(%s,0x%x)\n",path,perm); 
     49        #ifdef WIN32 
     50        return mkdir(path); // simply comment out for win if it causes trouble during compile, currently (15.01.2010) only needed for iris install using home path 
    5451        #else 
    55                 return -1; 
     52        return mkdir(path,(mode_t)perm); 
    5653        #endif 
     54        return -2; 
    5755} 
    5856 
    5957int     rob_rmdir                       (const char* path) { 
    60         #ifdef rmdir 
    61                 return rmdir(path); 
     58        #ifdef WIN32 
     59        return rmdir(path); // simply comment out for win if it causes trouble during compile, currently (15.01.2010) only needed for iris install using home path 
    6260        #else 
    63                 return -1; 
     61        return rmdir(path); 
    6462        #endif 
     63        return -2; 
    6564} 
    6665