diff options
| author | ruki <[email protected]> | 2023-11-17 11:03:51 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-17 11:03:51 +0800 |
| commit | cf3afe37b546efb93079fd6314c0769884ca0fb1 (patch) | |
| tree | 732f74fe2fd2922f3c95e8542de82cb6ee108f1c /xmake/modules | |
| parent | b6bb372d19bd2f6ac931d3e0e096b4fa07024cfb (diff) | |
| parent | e0f074c79be1f712d09df9f7b4b32245ba95f1c9 (diff) | |
Merge pull request #4392 from xmake-io/emptydirs
improve os.rm to support remove emptydirs
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/action/clean/remove_files.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/private/utils/batchcmds.lua | 26 |
2 files changed, 7 insertions, 29 deletions
diff --git a/xmake/modules/private/action/clean/remove_files.lua b/xmake/modules/private/action/clean/remove_files.lua index 606bb405d..3d62c6b78 100644 --- a/xmake/modules/private/action/clean/remove_files.lua +++ b/xmake/modules/private/action/clean/remove_files.lua @@ -25,14 +25,6 @@ import("core.base.option") function main(filedirs, opt) opt = opt or {} for _, filedir in ipairs(filedirs) do - os.tryrm(filedir) - if option.get("all") or opt.emptydir then - -- 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.tryrm(parentdir) - parentdir = path.directory(parentdir) - end - end + os.tryrm(filedir, {emptydirs = option.get("all") or opt.emptydir}) end end diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index fe518cbec..eda3887c8 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -140,15 +140,7 @@ end function _runcmd_rm(cmd, opt) local filepath = cmd.filepath if not opt.dryrun then - os.tryrm(filepath) - end -end - --- run command: os.tryrm -function _runcmd_tryrm(cmd, opt) - local filepath = cmd.filepath - if not opt.dryrun then - os.tryrm(filepath) + os.tryrm(filepath, opt) end end @@ -156,7 +148,7 @@ end function _runcmd_rmdir(cmd, opt) local dir = cmd.dir if not opt.dryrun and os.isdir(dir) then - os.tryrm(dir) + os.tryrm(dir, opt) end end @@ -197,7 +189,6 @@ function _runcmd(cmd, opt) rmdir = _runcmd_rmdir, cd = _runcmd_cd, rm = _runcmd_rm, - tryrm = _runcmd_tryrm, cp = _runcmd_cp, mv = _runcmd_mv, ln = _runcmd_ln @@ -352,18 +343,13 @@ function batchcmds:mkdir(dir) end -- add command: os.rmdir -function batchcmds:rmdir(dir) - table.insert(self:cmds(), {kind = "rmdir", dir = dir}) +function batchcmds:rmdir(dir, opt) + table.insert(self:cmds(), {kind = "rmdir", dir = dir, opt = opt}) end -- add command: os.rm -function batchcmds:rm(filepath) - table.insert(self:cmds(), {kind = "rm", filepath = filepath}) -end - --- add command: os.tryrm -function batchcmds:tryrm(filepath) - table.insert(self:cmds(), {kind = "tryrm", filepath = filepath}) +function batchcmds:rm(filepath, opt) + table.insert(self:cmds(), {kind = "rm", filepath = filepath, opt = opt}) end -- add command: os.cp |
