summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-07-01 08:27:11 +0800
committerruki <[email protected]>2016-07-01 08:27:11 +0800
commit65d6fd75bb258723b17df3bea466b63b97e229d8 (patch)
tree4caced09fff2a8d1c4d13c2300708f50ff617842
parentfe0b87c4090060f7f223b980f4d9b55f8b163bcc (diff)
remove empty when cleaning
-rwxr-xr-xxmake/actions/clean/main.lua5
-rw-r--r--xmake/core/base/os.lua14
-rw-r--r--xmake/core/sandbox/modules/os.lua4
-rw-r--r--xmake/platforms/installer.lua4
4 files changed, 17 insertions, 10 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 040b43f8c..319c14b77 100755
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -38,7 +38,7 @@ function _remove(filedirs)
if os.exists(filedir) then
-- remove it
- os.rm(filedir)
+ os.rm(filedir, true)
-- remove "*.o/obj" files?
elseif filedir:find("%*") then
@@ -47,8 +47,7 @@ function _remove(filedirs)
for _, file in ipairs(os.match(filedir)) do
-- remove it
- os.rm(file)
-
+ os.rm(file, true)
end
end
end
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 228219513..702d97c82 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -172,8 +172,8 @@ function os.mv(src, dst)
return true
end
--- remove file or directory
-function os.rm(file_or_dir, emptydir)
+-- remove file or directory and remove it if the super directory be empty
+function os.rm(file_or_dir, rm_superdir_if_empty)
-- check
assert(file_or_dir)
@@ -187,11 +187,19 @@ function os.rm(file_or_dir, emptydir)
-- is directory?
elseif os.isdir(file_or_dir) then
-- remove directory
- if not os.rmdir(file_or_dir, emptydir) then
+ if not os.rmdir(file_or_dir) then
return false, string.format("cannot remove directory %s %s", file_or_dir, os.strerror())
end
end
+ -- remove the super directory if be empty
+ if rm_superdir_if_empty then
+ local superdir = path.directory(file_or_dir)
+ if os.isdir(superdir) then
+ os.rmdir(superdir, true)
+ end
+ end
+
-- ok
return true
end
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 9babc4318..963ba3f55 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -72,7 +72,7 @@ function sandbox_os.mv(src, dst)
end
-- remove file or directory
-function sandbox_os.rm(file_or_dir, emptydir)
+function sandbox_os.rm(file_or_dir, rm_superdir_if_empty)
-- check
assert(file_or_dir)
@@ -81,7 +81,7 @@ function sandbox_os.rm(file_or_dir, emptydir)
file_or_dir = vformat(file_or_dir)
-- done
- local ok, errors = os.rm(file_or_dir, emptydir)
+ local ok, errors = os.rm(file_or_dir, rm_superdir_if_empty)
if not ok then
os.raise(errors)
end
diff --git a/xmake/platforms/installer.lua b/xmake/platforms/installer.lua
index 1f5b1296a..52df1985f 100644
--- a/xmake/platforms/installer.lua
+++ b/xmake/platforms/installer.lua
@@ -111,12 +111,12 @@ function uninstall_library_on_unix(target)
-- reove the config.h from the include directory
local _, configoutput = target:configheader(includedir)
if configoutput then
- os.rm(configoutput)
+ os.rm(configoutput, true)
end
-- remove headers from the include directory
local _, dstheaders = target:headerfiles(includedir)
for _, dstheader in ipairs(dstheaders) do
- os.rm(dstheader)
+ os.rm(dstheader, true)
end
end