From 07a1136da5471e4dda4c7ee01757d226692ddaeb Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sun, 10 Sep 2023 08:15:43 +0000 Subject: Bug [78cd4f9ad3] - regression in zipfs mount --- doc/zipfs.n | 27 +++++++++++++++++++-------- generic/tclZipfs.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/doc/zipfs.n b/doc/zipfs.n index b5495c2..4e02c31 100644 --- a/doc/zipfs.n +++ b/doc/zipfs.n @@ -84,16 +84,27 @@ Return a list of all files in the mounted zipfs, or just those matching \fIpattern\fR (optionally controlled by the option parameters). The order of the names in the list is arbitrary. .TP -\fBzipfs mount\fR ?\fIzipfile\fR? ?\fImountpoint\fR? ?\fIpassword\fR? -. -The \fBzipfs mount\fR command mounts a ZIP archive file as a Tcl virtual -filesystem at \fImountpoint\fR. After this command executes, files contained -in \fIzipfile\fR will appear to Tcl to be regular files at the mount point. +\fBzipfs mount\fR +.TP +\fBzipfs mount\fR \fImountpoint\fR +.TP +\fBzipfs mount\fR \fIzipfile\fR \fImountpoint\fR ?\fIpassword\fR? .RS .PP -With no \fIzipfile\fR, returns the zipfile mounted at \fImountpoint\fR. With -no \fImountpoint\fR, return all zipfile/mount pairs. If \fImountpoint\fR is -specified as an empty string, mount on file path. +The \fBzipfs mount\fR command mounts ZIP archives as Tcl virtual file systems +and returns information about current mounts. +.PP +With no arguments, the command returns a dictionary mapping +current mount points to the file path of the corresponding ZIP archive. +.PP +In the single argument form, the command returns the file path +of the ZIP archive mounted at the specified mount point. +.PP +In the third form, the command mounts the ZIP archive \fIzipfile\fR as a Tcl virtual +filesystem at \fImountpoint\fR. After this command executes, files contained +in \fIzipfile\fR will appear to Tcl to be regular files at the mount point. +If \fImountpoint\fR is +specified as an empty string, it is defaulted to the file path. .PP \fBNB:\fR because the current working directory is a concept maintained by the operating system, using \fBcd\fR into a mounted archive will only work in the diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 910ba53..9d6749a 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -2240,22 +2240,30 @@ ZipFSMountObjCmd( "?zipfile? ?mountpoint? ?password?"); return TCL_ERROR; } + /* + * A single argument is treated as the mountpoint. Two arguments + * are treated as zipfile and mountpoint. + */ if (objc > 1) { - zipFileObj = Tcl_FSGetNormalizedPath(interp, objv[1]); - if (!zipFileObj) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "could not normalize zip filename", -1)); - Tcl_SetErrorCode(interp, "TCL", "OPERATION", "NORMALIZE", NULL); - return TCL_ERROR; + if (objc == 2) { + mountPoint = Tcl_GetString(objv[1]); + } else { + /* 2 < objc < 4 */ + zipFileObj = Tcl_FSGetNormalizedPath(interp, objv[1]); + if (!zipFileObj) { + Tcl_SetObjResult( + interp, + Tcl_NewStringObj("could not normalize zip filename", -1)); + Tcl_SetErrorCode(interp, "TCL", "OPERATION", "NORMALIZE", NULL); + return TCL_ERROR; + } + Tcl_IncrRefCount(zipFileObj); + zipFile = Tcl_GetString(zipFileObj); + mountPoint = Tcl_GetString(objv[2]); + if (objc > 3) { + password = Tcl_GetString(objv[3]); + } } - Tcl_IncrRefCount(zipFileObj); - zipFile = Tcl_GetString(zipFileObj); - } - if (objc > 2) { - mountPoint = Tcl_GetString(objv[2]); - } - if (objc > 3) { - password = Tcl_GetString(objv[3]); } result = TclZipfs_Mount(interp, zipFile, mountPoint, password); -- cgit v0.12