From: Pat Thoyts Date: Thu, 14 May 2009 19:02:32 +0000 (+0000) Subject: Handle directory names that include glob chars. X-Git-Url: http://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=72708a01d8eeeb2b16789f2b4efc664d92860a86;p=tclvfs Handle directory names that include glob chars. --- diff --git a/ChangeLog b/ChangeLog index 85b24af..a7ab496 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-05-14 Pat Thoyts + + * library/zipvfs.tcl: Handle directory names that include + * tests/vfsZip.test: glob chars. Added some tests. + * win/makefile.vc: fix running the tests. + 2009-02-06 Andreas Kupries * library/vfs.tcl.in: New file encapsulating the package load diff --git a/library/zipvfs.tcl b/library/zipvfs.tcl index b9b44c9..45cfbed 100644 --- a/library/zipvfs.tcl +++ b/library/zipvfs.tcl @@ -551,16 +551,20 @@ proc zip::getdir {fd path {pat *}} { upvar #0 zip::$fd.toc toc if { $path == "." || $path == "" } { - set path [string tolower $pat] + set path [set tmp [string tolower $pat]] } else { - set path [string tolower $path] + set globmap [list "\[" "\\\[" "*" "\\*" "?" "\\?"] + set tmp [string tolower $path] + set path [string map $globmap $tmp] if {$pat != ""} { + append tmp /[string tolower $pat] append path /[string tolower $pat] } } - set depth [llength [file split $path]] + # file split can be confused by the glob quoting so split tmp string + set depth [llength [file split $tmp]] - #puts stderr "getdir $fd $path $depth $pat [array names toc $path]" + #vfs::log "getdir $fd $path $depth $pat [array names toc $path]" if {$depth} { set ret {} foreach key [array names toc $path] { diff --git a/tests/vfsZip.test b/tests/vfsZip.test index 08dd3c9..383fda2 100644 --- a/tests/vfsZip.test +++ b/tests/vfsZip.test @@ -34,6 +34,13 @@ if {[testConstraint zipfs] && [testConstraint zipexe]} { eval exec [auto_execok zip] [list -r zipfs.zip zipfs.test] eval exec [auto_execok zip] [list zipnest.zip zipfs.zip] + file mkdir zipglob.test + makeFile {Glob one} "zipglob.test/one\[1\].txt" + makeFile {Glob two} "zipglob.test/two \[2\].txt" + file mkdir zipglob.test/a\[0\] + makeFile {Glob three} "zipglob.test/a\[0\]/three.txt" + eval exec [auto_execok zip] [list -r zipglob.zip zipglob.test] + testConstraint zipcat [expr {![catch { makeFile {} zipcat.zip set f [open zipcat.zip w] ; fconfigure $f -translation binary @@ -144,6 +151,47 @@ test vfsZip-1.11 "cd directory" -constraints {zipfs zipexe} -setup { vfs::unmount local } -result {One.txt Two.txt} +test vfsZip-1.12 "globby filenames" -constraints {zipfs zipexe} -setup { + vfs::zip::Mount zipglob.zip local +} -body { + glob -type f -tail -directory local/zipglob.test * +} -cleanup { + vfs::unmount local +} -result [list "one\[1\].txt" "two \[2\].txt"] + +test vfsZip-1.13 "globby filenames" -constraints {zipfs zipexe} -setup { + vfs::zip::Mount zipglob.zip local +} -body { + set result {} + foreach file [glob -type f -directory local/zipglob.test *] { + set f [open $file r] + lappend result [string trim [read $f]] + } + set result +} -cleanup { + vfs::unmount local +} -result [list "Glob one" "Glob two"] + +test vfsZip-1.14 "globby subdir" -constraints {zipfs zipexe} -setup { + vfs::zip::Mount zipglob.zip local +} -body { + glob -type d -tail -directory local/zipglob.test * +} -cleanup { + vfs::unmount local +} -result [list "a\[0\]"] + +test vfsZip-1.15 "globby subdir" -constraints {zipfs zipexe} -setup { + vfs::zip::Mount zipglob.zip local +} -body { + set result {} + foreach dir [glob -type d -directory local/zipglob.test *] { + lappend result [glob -nocomplain -tail -directory $dir *] + } + set result +} -cleanup { + vfs::unmount local +} -returnCodes {ok error} -result {three.txt} + test vfsZip-2.0 "nested stat file" -constraints {zipfs zipexe} -setup { vfs::zip::Mount zipnest.zip local unset -nocomplain stat @@ -299,8 +347,10 @@ test vfsZip-9.0 "attempt to delete mounted file" -constraints {zipfs zipexe} -se # cleanup if {[testConstraint zipfs] && [testConstraint zipexe]} { file delete -force zipfs.test + file delete -force zipglob.test file delete zipfs.zip file delete zipnest.zip + file delete zipglob.zip } tcltest::cleanupTests return diff --git a/win/makefile.vc b/win/makefile.vc index f494cd7..b8a932b 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -356,8 +356,8 @@ pkgIndex: setup $(OUT_DIR)\pkgIndex.tcl $(OUT_DIR)\vfs.tcl test: setup $(PROJECT) @set TCL_LIBRARY=$(TCL_LIBRARY:\=/) - @set TCLLIBPATH=$(OUT_DIR_PATH:\=/) - @set VFS_LIBRARY=$(LIBDIR:\=/) + @set TCLLIBPATH=$(OUT_DIR_PATH:\=/) + $(CPY) $(LIBDIR)\*.tcl $(OUT_DIR) !if $(TCLINSTALL) @set PATH=$(_TCLDIR)\bin;$(PATH) !else