Skip to content

Commit 1866c3d

Browse files
committed
Improved cleanup of temporary files.
1 parent 44e4609 commit 1866c3d

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/lib/app-support/support.tcl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ namespace eval ::support {
8888
# Detect temporary directory.
8989
variable TEMP_DIR [file join [::support::utils::get_temp_dir] "temp-support-[pid]"]
9090
if {![file exists $TEMP_DIR]} {
91-
if [catch {file mkdir $TEMP_DIR}] {
92-
puts "ERROR: Didn't find temporary directory"
93-
puts "ERROR: Couldn't make temporary directory \"$TEMP_DIR\""
91+
if {[catch {file mkdir $TEMP_DIR}]} {
92+
puts "ERROR: The temporary directory \"$TEMP_DIR\" was not created!"
9493
}
9594
} elseif {![file isdirectory $TEMP_DIR]} {
96-
puts "ERROR: Didn't find temporary directory"
97-
puts "ERROR: Temporary directory \"$TEMP_DIR\" exists, and is not a directory"
95+
puts "ERROR: The temporary directory \"$TEMP_DIR\" is not a directory!"
9896
}
9997

10098
# Print some informations.
@@ -310,6 +308,19 @@ proc exit {} {
310308
if {$::support::CONNECTED == 1} {
311309
::support::disconnect 1
312310
}
313-
file delete -force $::support::TEMP_DIR
311+
312+
# Remove temporary files explicitly.
313+
foreach f [::support::utils::get_files $::support::TEMP_DIR] {
314+
if {[file isfile $f] && [catch {file delete -force $f}]} {
315+
puts "WARNING: Can't remove temporary file \"$f\"!"
316+
puts $::errorInfo
317+
}
318+
}
319+
320+
# Remove temporary folder recursively.
321+
if {[catch {file delete -force $::support::TEMP_DIR}]} {
322+
puts "WARNING: Can't cleanup temporary directory \"$::support::TEMP_DIR\"!"
323+
puts $::errorInfo
324+
}
314325
__exit
315326
}

src/lib/app-support/utils.tcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,17 @@ namespace eval ::support::utils {
285285
}
286286
error "Can't get application path for this operating system!"
287287
}
288+
289+
# Get a recursive list of files in a directory.
290+
proc get_files {{dir .}} {
291+
set res {}
292+
foreach i [lsort [glob -nocomplain -dir $dir *]] {
293+
if {[file type $i] eq {directory}} {
294+
eval lappend res [get_files $i]
295+
} else {
296+
lappend res $i
297+
}
298+
}
299+
set res
300+
}
288301
}

0 commit comments

Comments
 (0)