From ff9ac26ccebc8ebe26a9236fc5d35aa52311ec73 Mon Sep 17 00:00:00 2001 From: Steve Huntley Date: Wed, 1 Nov 2006 03:44:59 +0000 Subject: [PATCH] 2006-10-31 Steve Huntley * library/template/versionvfs.tcl: added code to ensure all subfiles of a directory are deleted before dir deletion. --- library/template/versionvfs.tcl | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/library/template/versionvfs.tcl b/library/template/versionvfs.tcl index b7cc472..6bbe878 100644 --- a/library/template/versionvfs.tcl +++ b/library/template/versionvfs.tcl @@ -5,7 +5,7 @@ versionvfs.tcl -- Written by Stephen Huntley (stephen.huntley@alum.mit.edu) License: Tcl license -Version 1.01 +Version 1.0 A versioning virtual filesystem. Requires the template vfs in templatevfs.tcl. @@ -187,20 +187,17 @@ proc file_attributes {file {attribute {}} args} { } return $returnValue } + proc file_delete {file} { upvar path path root root relative relative set dir 0 # make sure subfiles of directory are deleted: if [file isdirectory $file] { - set dir 1 - set subfiles [globfind [file join $root $relative]] - set subfileloc [lsearch $subfiles [file join $root $relative]] - set subfiles [lreplace $subfiles $subfileloc $subfileloc] + set subfiles [globfind $file] set subfiles [lsort -decreasing $subfiles] - foreach sf $subfiles { - ::file delete -force -- $sf - } + foreach sf $subfiles {globdelete $sf} + set dir 1 } set fileName [VAcquireFile $path $root $relative] @@ -376,6 +373,19 @@ proc UnmountProcedure {path to} { return } +# utility proc called by file_delete for recursive deletion of dir contents: +proc globdelete {file} { + upvar root root + if [file isdirectory $file] {return} + set file [file join [file dirname $file] [lindex [split $file \;] 0]] + set fileName $file\;[VCreateTag $root] + set fileName [split $fileName \;] + set fileName [linsert $fileName 2 "deleted"] + set fileName [join $fileName \;] + close [open $fileName w] + if ![string first {.&} [file tail $fileName]] {catch {file attributes $fileName -hidden 1}} +} + # Can replace this proc with one that uses different hash function if preferred. proc Hash {channel} { seek $channel 0 @@ -399,9 +409,7 @@ proc VAcquireFile {path root relative {actualpath {}}} { } # grab all versions: - if [catch {set versions [glob -path $fileName -nocomplain -types f "\;*"]} result] { - set versions [glob -path $fileName -nocomplain -types f "\;*"] - } + set versions [glob -path $fileName -nocomplain -types f "\;*"] if [catch {::vfs::filesystem info $path}] {append versions " [glob -path $fileName -nocomplain -types "f hidden" "\;*"]"} set versions [string trim $versions] -- 2.23.0