@@ -5,6 +5,9 @@ local ConfigHandler
55
66class FileOps
77 msgs = {
8+ generic : {
9+ deletionRescheduled : " Another deletion attempt has been rescheduled for the next restart."
10+ }
811 attributes : {
912 badPath : " Path failed verification: %s."
1013 genericError : " Can't retrieve attributes: %s."
@@ -34,7 +37,7 @@ class FileOps
3437 }
3538 rmdir : {
3639 emptyPath : " Argument #1 (path) must not be an empty string."
37- couldntRemoveFiles : " The specified directory contains files and folders that couldn't be removed. "
40+ couldntRemoveFiles : " Some of the files and folders in the specified directory couldn't be removed: \n %s "
3841 couldntRemoveDir : " Error removing empty directory: %s."
3942
4043 }
@@ -68,28 +71,37 @@ class FileOps
6871
6972 remove : ( paths, recurse, reSchedule) ->
7073 config = createConfig true
71- configLoaded, res = false , {}
74+ configLoaded, overallSuccess , details , firstErr = false , true , {}
7275 paths = { paths} unless type ( paths) == " table"
7376
7477 for path in * paths
7578 mode, path = FileOps . attributes path, " mode"
7679 if mode
7780 rmFunc = mode == " file" and os.remove or FileOps . rmdir
78- success, err = rmFunc path, recurse
79- if not success
80- unless reSchedule
81- res[ # res+ 1 ] = { nil , err}
81+ res, err = rmFunc path, recurse
82+ unless res
83+ firstErr or= err
84+ unless reSchedule -- delete operation failed entirely
85+ details[ path] = { nil , err}
86+ overallSuccess = nil
8287 continue
88+
89+ -- load the FileOps configuration file and reschedule deletions
8390 unless configLoaded
8491 FileOps . config\ load!
8592 configLoaded = true
8693 config. c. toRemove[ path] = os.time !
87- res[ # res+ 1 ] = { false , err}
88- else res[ # res+ 1 ] = { true }
89- else res[ # res+ 1 ] = { nil , path}
94+ -- mark the operations as failed "for now", indicating a second attempt has been scheduled
95+ details[ path] = { false , err}
96+ overallSuccess = false
97+
98+ -- delete operation succeeded
99+ else details[ path] = { true }
100+ -- file not found or permission issue
101+ else details[ path] = { nil , err}
90102
91103 config\ write! if configLoaded
92- return res , configLoaded
104+ return overallSuccess , details , firstErr
93105
94106 runScheduledRemoval : ( configDir) ->
95107 config = createConfig false , configDir
@@ -186,9 +198,10 @@ class FileOps
186198 if recurse
187199 -- recursively remove contained files and directories
188200 toRemove = [ " #{path}/#{file}" for file in lfs. dir path]
189- res, err = FileOps . remove toRemove, true
190- if err
191- return nil , msgs. rmdir. couldntRemoveFiles, res
201+ res, details = FileOps . remove toRemove, true
202+ unless res
203+ fileList = table.concat [ " #{path}: #{res[2]}" for path, res in pairs details when not res[ 1 ]] , " \n "
204+ return nil , msgs. rmdir. couldntRemoveFiles\ format fileList
192205
193206 -- remove empty directory
194207 success, err = lfs. rmdir path
0 commit comments