diff options
| author | ruki <[email protected]> | 2017-02-08 23:14:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-08 23:14:47 +0800 |
| commit | 893ac8653a3c8525dcc7236721ca251d027ad818 (patch) | |
| tree | 52291e992b61991074d00ceeda22a1cb3eac27f0 | |
| parent | f5571dea410131991ae7f836cc6a52d82890d894 (diff) | |
improve clean action
| -rwxr-xr-x | core/src/xmake/os/emptydir.c | 2 | ||||
| -rwxr-xr-x | xmake/actions/clean/main.lua | 23 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 16 |
3 files changed, 24 insertions, 17 deletions
diff --git a/core/src/xmake/os/emptydir.c b/core/src/xmake/os/emptydir.c index 6fe2c8cee..73746d804 100755 --- a/core/src/xmake/os/emptydir.c +++ b/core/src/xmake/os/emptydir.c @@ -44,7 +44,7 @@ static tb_bool_t xm_os_emptydir_walk(tb_char_t const* path, tb_file_info_t const tb_assert_and_check_return_val(path && info && is_emptydir, tb_false); // is emptydir? - if (info->type == TB_FILE_TYPE_DIRECTORY || info->type == TB_FILE_TYPE_FILE) + if (info->type == TB_FILE_TYPE_FILE) { // not emptydir *is_emptydir = tb_false; diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index b7ddd0f84..3f2d39fa9 100755 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -35,22 +35,15 @@ function _remove(filedirs) -- done for _, filedir in ipairs(filedirs) do - - -- exists? remove it - if os.exists(filedir) then - - -- remove it - os.rm(filedir) - - -- remove "*.o/obj" files? - elseif filedir:find("%*") then - -- match all files - for _, file in ipairs(os.match(filedir)) do - - -- remove it - os.rm(file) - end + -- remove it first + os.tryrm(filedir) + + -- remove it if the parent directory is empty + local parentdir = path.directory(filedir) + while parentdir and os.isdir(parentdir) and os.emptydir(parentdir) do + os.rm(parentdir) + parentdir = path.directory(parentdir) end end end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index d1af87a1e..29cf115f4 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -39,6 +39,7 @@ sandbox_os.argv = os.argv sandbox_os.argw = os.argw sandbox_os.mtime = os.mtime sandbox_os.mclock = os.mclock +sandbox_os.emptydir = os.emptydir -- copy file or directory function sandbox_os.cp(...) @@ -81,13 +82,26 @@ function sandbox_os.rm(...) table.insert(args, vformat(arg)) end - -- done + -- remove it local ok, errors = os.rm(unpack(args)) if not ok then os.raise(errors) end end +-- try to remove files or directories +function sandbox_os.tryrm(...) + + -- format arguments + local args = {} + for _, arg in ipairs({...}) do + table.insert(args, vformat(arg)) + end + + -- remove it + os.rm(unpack(args)) +end + -- change to directory function sandbox_os.cd(dir) |
