From ef9ea15d10ceacfb89e94c3f73a3fab9c3601df1 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 19 Sep 2023 11:41:26 +0000 Subject: Bugs [14db54d81e], [6183f535c89]. Glob and find on zipfs root --- generic/tclZipfs.c | 13 ++++++++---- tests/zipfs.test | 62 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 02b0f72..47b294e 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -214,7 +214,6 @@ typedef struct ZipFile { /* * In-core description of file contained in mounted ZIP archive. - * ZIP_ATTR_ */ typedef struct ZipEntry { @@ -232,8 +231,9 @@ typedef struct ZipEntry { int timestamp; /* Modification time */ int isEncrypted; /* True if data is encrypted */ int flags; -#define ZE_F_CRC_COMPARED 0x1 /* If 1, the CRC has been compared. */ -#define ZE_F_CRC_CORRECT 0x2 /* Only meaningful if ZE_F_CRC_COMPARED is 1 */ +#define ZE_F_CRC_COMPARED 0x00000001 /* If 1, the CRC has been compared. */ +#define ZE_F_CRC_CORRECT 0x00000002 /* Only meaningful if ZE_F_CRC_COMPARED is 1 */ +#define ZE_F_VOLUME 0x00000004 /* Entry corresponds to //zipfs:/ */ unsigned char *data; /* File data if written */ struct ZipEntry *next; /* Next file in the same archive */ struct ZipEntry *tnext; /* Next top-level dir in archive */ @@ -1734,6 +1734,9 @@ ZipFSCatalogFilesystem( z->offset = zf->baseOffset; z->compressMethod = ZIP_COMPMETH_STORED; z->name = (char *) Tcl_GetHashKey(&ZipFS.fileHash, hPtr); + if (!strcmp(z->name, ZIPFS_VOLUME)) { + z->flags |= ZE_F_VOLUME; /* Mark as root volume */ + } z->next = zf->entries; zf->entries = z; } @@ -5253,7 +5256,9 @@ ZipFSMatchInDirectoryProc( || (!dirOnly && z->isDirectory))) { continue; } - if ((z->depth == scnt) && Tcl_StringCaseMatch(z->name, pat, 0)) { + if ((z->depth == scnt) && + ((z->flags & ZE_F_VOLUME) == 0) /* Bug 14db54d81e */ + && Tcl_StringCaseMatch(z->name, pat, 0)) { AppendWithPrefix(result, prefixBuf, z->name + strip, -1); } } diff --git a/tests/zipfs.test b/tests/zipfs.test index 6a8c204..f5fb9f9 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -459,7 +459,7 @@ namespace eval test_ns_zipfs { # Generates tests for file, file on root, memory buffer cases for an archive proc testmount {id zippath checkPath mountpoint args} { set zippath [zippath $zippath] - test zipfs-mount-$id $id -body { + test zipfs-mount-$id "zipfs mount $id" -body { mount $zippath $mountpoint set canon [zipfs canonical $mountpoint] list [file exists [file join $canon $checkPath]] \ @@ -469,7 +469,7 @@ namespace eval test_ns_zipfs { } -result [list 1 $zippath] {*}$args # Mount memory buffer - test zipfs-mount_data-$id $id -body { + test zipfs-mount_data-$id "zipfs mount_data $id" -body { zipfs mount_data [readbin $zippath] $mountpoint set canon [zipfs canonical $mountpoint] list [file exists [file join $canon $checkPath]] \ @@ -687,7 +687,7 @@ namespace eval test_ns_zipfs { file join [zipfs root] $path }] set resultpaths [lsort $resultpaths] - test zipfs-list-$id $id -body { + test zipfs-list-$id "zipfs list $id" -body { lsort [zipfs list {*}$cmdargs] } -setup { foreach {zippath mountpoint} $mounts { @@ -698,7 +698,7 @@ namespace eval test_ns_zipfs { } -result $resultpaths {*}$args # Mount memory buffer - test zipfs-list-memory-$id $id -body { + test zipfs-list-memory-$id "zipfs list memory $id" -body { lsort [zipfs list {*}$cmdargs] } -setup { foreach {zippath mountpoint} $mounts { @@ -737,7 +737,7 @@ namespace eval test_ns_zipfs { # Generates tests for zipfs exists proc testzipfsexists {id path result args} { - test zipfs-exists-$id $id -body { + test zipfs-exists-$id "zipfs exists $id" -body { zipfs exists $path } -setup { mount [zippath test.zip] @@ -778,12 +778,12 @@ namespace eval test_ns_zipfs { dict unset args -cleanup } set resultpaths [lsort $resultpaths] - test zipfs-find-$id $id -body { + test zipfs-find-$id "zipfs find $id" -body { lsort [zipfs find $findtarget] } -setup $setup -cleanup $cleanup -result $resultpaths {*}$args # Mount memory buffer - test zipfs-find-memory-$id $id -body { + test zipfs-find-memory-$id "zipfs find memory $id" -body { lsort [zipfs find $findtarget] } -setup $memory_setup -cleanup $cleanup -result $resultpaths {*}$args } @@ -808,6 +808,13 @@ namespace eval test_ns_zipfs { cd $cwd } + # bug-6183f535c8 + testzipfsfind root-path [zipfs root] { + test.zip {} test.zip testmountB/subdir + } [lmap path { + test testdir testdir/test2 + } {file join [zipfs root] $path}] + test zipfs-find-native-absolute "zipfs find on native file system" -setup { set dir [makeDirectory zipfs-native-absolute] set subdir [file join $dir subdir] @@ -836,11 +843,6 @@ namespace eval test_ns_zipfs { zipfs find [file tail $dir] } -result {zipfs-native-relative/subdir zipfs-native-relative/subdir/native} - testzipfsfind bug-6183f535c8 [zipfs root] { - test.zip {} test.zip testmountB/subdir - } [lmap path { - test testdir testdir/test2 - } {file join [zipfs root] $path}] -constraints bug-6183f535c8 # # zipfs info @@ -928,7 +930,7 @@ namespace eval test_ns_zipfs { proc testuncompress {id zippath result {filename abac-repeat.txt} args} { variable defaultMountPoint set zippath [zippath $zippath] - test zipfs-uncompress-$id $id -setup { + test zipfs-uncompress-$id "zipfs uncompress $id" -setup { unset -nocomplain fd zipfs mount $zippath $defaultMountPoint } -cleanup { @@ -953,7 +955,7 @@ namespace eval test_ns_zipfs { proc testpassword {id filename password result args} { variable defaultMountPoint set zippath [zippath test-password.zip] - test zipfs-password-read-$id $id -setup { + test zipfs-password-read-$id "zipfs password read $id" -setup { unset -nocomplain fd if {$password ne ""} { zipfs mount $zippath $defaultMountPoint $password @@ -986,7 +988,7 @@ namespace eval test_ns_zipfs { proc testcrc {id zippath filename result args} { variable defaultMountPoint set zippath [zippath $zippath] - test zipfs-crc-$id $id -setup { + test zipfs-crc-$id "zipfs crc $id" -setup { unset -nocomplain fd zipfs mount $zippath $defaultMountPoint } -cleanup { @@ -1000,7 +1002,7 @@ namespace eval test_ns_zipfs { } -result $result -returnCodes error {*}$args # Mount memory buffer - test zipfs-crc-memory-$id $id -setup { + test zipfs-crc-memory-$id "zipfs crc memory $id" -setup { zipfs mount_data [readbin [zippath $zippath]] $defaultMountPoint } -cleanup { cleanup @@ -1054,7 +1056,8 @@ namespace eval test_ns_zipfs { mount [zippath test.zip] } -cleanup cleanup -body { lsort -stride 2 [file stat [file join $defaultMountPoint test]] - } -result [fixupstat {atime {2003-10-06 15:46:42} ctime {2003-10-06 15:46:42} dev 0 gid 0 ino 0 mode 33133 mtime {2003-10-06 15:46:42} nlink 0 size 5 type file uid 0}] + } -result [fixupstat {atime {2003-10-06 15:46:42} ctime {2003-10-06 15:46:42} dev 0 gid 0 ino 0 mode 33133 mtime {2003-10-06 15:46:42} nlink 0 size + 5 type file uid 0}] test zipfs-file-stat-dir "Read stat of dir" -setup { mount [zippath test.zip] @@ -1081,7 +1084,30 @@ namespace eval test_ns_zipfs { } -result [fixupstat {atime 0 ctime 0 dev 0 gid 0 ino 0 mode 16749 mtime 0 nlink 0 size 0 type directory uid 0}] # - # TODO - glob of zipfs file + # glob of zipfs file + proc testzipfsglob {id mountpoint pat result {globopt {}} args} { + test zipfs-glob-$id "zipfs glob $id" -setup { + mount [zippath test.zip] $mountpoint + } -cleanup { + cleanup + } -body { + lsort [glob {*}$globopt $pat] + } -result $result {*}$args + } + # Bug 14db54d81e + testzipfsglob root-dir [zipfs root] * {//zipfs:/test //zipfs:/testdir} [list -dir [zipfs root]] + testzipfsglob root [zipfs root] [file join [zipfs root] *] {//zipfs:/test //zipfs:/testdir} + testzipfsglob pattern $defaultMountPoint [file join $defaultMountPoint testdir t*] \ + [file join $defaultMountPoint testdir test2] + testzipfsglob files $defaultMountPoint [file join $defaultMountPoint t*] \ + [list [file join $defaultMountPoint test]] {-type f} + testzipfsglob dirs $defaultMountPoint [file join $defaultMountPoint t*] \ + [list [file join $defaultMountPoint testdir]] {-type d} + testzipfsglob no-match $defaultMountPoint [file join $defaultMountPoint testdir x*] \ + {no files matched glob pattern "//zipfs:/testmount/testdir/x*"} {} -returnCodes error + testzipfsglob no-match-nocomplain $defaultMountPoint [file join $defaultMountPoint testdir x*] {} {-nocomplain} + testzipfsglob mountpoint $defaultMountPoint [file join [zipfs root] *] \ + [list $defaultMountPoint] {} # TODO tests for compress and save, + with password -- cgit v0.12