summaryrefslogtreecommitdiff
path: root/xmake/core/base/os.lua
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 /xmake/core/base/os.lua
parentfe0b87c4090060f7f223b980f4d9b55f8b163bcc (diff)
remove empty when cleaning
Diffstat (limited to 'xmake/core/base/os.lua')
-rw-r--r--xmake/core/base/os.lua14
1 files changed, 11 insertions, 3 deletions
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