Check-in [c47ebead98]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:improve zipfs::unwrap convenience function
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c47ebead987333210f158bd12b48b14542b54228
User & Date: chw 2020-06-26 17:12:35.764
Context
2020-06-27
15:40
add selected tk upstream changes check-in: fd4a1753f4 user: chw tags: trunk
2020-06-26
17:13
merge with trunk check-in: 1a504e188b user: chw tags: wtf-8-experiment
17:12
improve zipfs::unwrap convenience function check-in: c47ebead98 user: chw tags: trunk
17:08
add tklib upstream changes check-in: 3b7f05717f user: chw tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to jni/tcl/doc/zipfs.n.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\fBzipfs::mkzip\fR \fIoutfile\fR \fIindir\fR \fI?strip?\fR \fI?password?\fR
\fBzipfs::mount\fR \fI?zipfile\fR \fI?mountpoint?\fR \fI?password?\fR
\fBzipfs::mount\fR \fB\-data\fR \fIbytearray\fR \fImountpoint\fR
\fBzipfs::mount\fR \fB\-chan\fR \fIchannelId\fR \fImountpoint\fR
\fBzipfs::mount\fR \fB\-file\fR \fIzipfile\fR \fImountpoint\fR \fI?password?\fR
\fBzipfs::mount\fR \fB\-\-\fR \fIzipfile\fR \fImountpoint\fR \fI?password?\fR
\fBzipfs::unmount\fR \fIzipfile\fR
\fBzipfs::unwrap\fR \fI?zipfile?\fR
.fi
.BE
.SH DESCRIPTION
.PP
The \fBzipfs\fR package provides tcl with the ability to mount
the contents of a ZIP file as a virtual file system.
.TP







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\fBzipfs::mkzip\fR \fIoutfile\fR \fIindir\fR \fI?strip?\fR \fI?password?\fR
\fBzipfs::mount\fR \fI?zipfile\fR \fI?mountpoint?\fR \fI?password?\fR
\fBzipfs::mount\fR \fB\-data\fR \fIbytearray\fR \fImountpoint\fR
\fBzipfs::mount\fR \fB\-chan\fR \fIchannelId\fR \fImountpoint\fR
\fBzipfs::mount\fR \fB\-file\fR \fIzipfile\fR \fImountpoint\fR \fI?password?\fR
\fBzipfs::mount\fR \fB\-\-\fR \fIzipfile\fR \fImountpoint\fR \fI?password?\fR
\fBzipfs::unmount\fR \fIzipfile\fR
\fBzipfs::unwrap\fR \fI?filename?\fR
.fi
.BE
.SH DESCRIPTION
.PP
The \fBzipfs\fR package provides tcl with the ability to mount
the contents of a ZIP file as a virtual file system.
.TP
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
a string of the form "\fBmemory_<size>_<id>\fR" which can later be
used as \fIzipfile\fR parameter in an unmount operation.
.TP
\fBzipfs::unmount \fIzipfile\fR
.
Unmounts a previously mounted ZIP archive file \fIzipfile\fR.
.TP
\fBzipfs::unwrap \fI?zipfile?\fR
.
If \fIzipfile\fR is given it is temporarily mounted and its contents
is unpacked to a local directory named \fIzipfile.vfs\fR which must
not exist prior to the call. If \fIzipfile\fR is omitted the result

of \fBinfo nameofexecutable\fR is used instead, i.e. the main ZIP
file system of the running process is unpacked.
.PP
The commands described above are available as subcommands in the \fBzipfs\fR
ensemble, i.e. \fBzipfs list\fR is equivalent to \fBzipfs::list\fR.
.PP
It is possible to mount an arbitrary number of ZIP archives even
below each other yielding a "union" view of all mounted ZIP archives.
However, should file names overlap, the first mount operation creating







|

|
|
|
>
|
|







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
a string of the form "\fBmemory_<size>_<id>\fR" which can later be
used as \fIzipfile\fR parameter in an unmount operation.
.TP
\fBzipfs::unmount \fIzipfile\fR
.
Unmounts a previously mounted ZIP archive file \fIzipfile\fR.
.TP
\fBzipfs::unwrap \fI?filename?\fR
.
If \fIfilename\fR is the root of a mounted ZIP archive its content is
unpacked to a local directory named \fIfilename.vfs\fR. This directory
must not exists prior to the call. Otherwise, \fIfilename\fR is temporarily
mounted before the unpack operation takes place and unmounted afterwards.
If \fIfilename\fR is omitted the result of \fBinfo nameofexecutable\fR is
used instead, i.e. the main ZIP archive of the running process is unpacked.
.PP
The commands described above are available as subcommands in the \fBzipfs\fR
ensemble, i.e. \fBzipfs list\fR is equivalent to \fBzipfs::list\fR.
.PP
It is possible to mount an arbitrary number of ZIP archives even
below each other yielding a "union" view of all mounted ZIP archives.
However, should file names overlap, the first mount operation creating
Changes to jni/tcl/generic/zipfs.c.
5361
5362
5363
5364
5365
5366
5367

5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381

5382

5383
5384
5385
5386

5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402








5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
	{ "exists",	ZipFSExistsObjCmd,	NULL, NULL, NULL, 0 },
	{ "info",	ZipFSInfoObjCmd,	NULL, NULL, NULL, 0 },
	{ "list",	ZipFSListObjCmd,	NULL, NULL, NULL, 0 },
	{ NULL, NULL, NULL, NULL, NULL, 0 }
    };

    static const char findproc[] =

	"proc ::zipfs::find dir {\n"
	" set result {}\n"
	" if {[catch {glob -directory $dir -tails -nocomplain * .*} list]} {\n"
	"  return $result\n"
	" }\n"
	" foreach file $list {\n"
	"  if {$file eq \".\" || $file eq \"..\"} {\n"
	"   continue\n"
	"  }\n"
	"  set file [file join $dir $file]\n"
	"  lappend result $file\n"
	"  foreach file [::zipfs::find $file] {\n"
	"   lappend result $file\n"
	"  }\n"

	" }\n"

	" return [lsort $result]\n"
	"}\n";

    static const char unwrproc[] =

	"proc ::zipfs::unwrap {{zipfile {}}} {\n"
	" set noe [::info nameofexecutable]\n"
	" if {$zipfile eq{}} {\n"
	"  set zipfile $noe\n"
	" } else {\n"
	"  set zipfile [file normalize $zipfile]\n"
	" }\n"
	" set outdir [file rootname $zipfile].vfs\n"
	" if {[file isdirectory $outdir]} {\n"
	"  return -code error \"directory \\\"$outdir\\\" already exists\"\n"
	" }\n"
	" file mkdir $outdir\n"
	" if {$zipfile eq $noe} {\n"
	"  file copy {*}[glob -directory $zipfile -- * .*] $outdir\n"
	" } else {\n"
	"  set f [file tempfile temp]\n"








	"  mount $zipfile $temp\n"
	"  file copy {*}[glob -directory $temp -- * .*] $outdir\n"
	"  unmount $zipfile\n"
	"  close $f\n"
	"  file delete -force $temp\n"
	" }\n"
	"}\n";

    /* one-time initialization */
    WriteLock();
    if (!ZipFS.initialized) {
#ifdef TCL_THREADS







>
|









|
<
<
|
>
|
>
|



>
|

|
|

|

|




|
|

|
>
>
>
>
>
>
>
>
|
|
|
|
<







5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379


5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416

5417
5418
5419
5420
5421
5422
5423
	{ "exists",	ZipFSExistsObjCmd,	NULL, NULL, NULL, 0 },
	{ "info",	ZipFSInfoObjCmd,	NULL, NULL, NULL, 0 },
	{ "list",	ZipFSListObjCmd,	NULL, NULL, NULL, 0 },
	{ NULL, NULL, NULL, NULL, NULL, 0 }
    };

    static const char findproc[] =
	"namespace eval ::zipfs {}\n"
	"proc ::zipfs::_find dir {\n"
	" set result {}\n"
	" if {[catch {glob -directory $dir -tails -nocomplain * .*} list]} {\n"
	"  return $result\n"
	" }\n"
	" foreach file $list {\n"
	"  if {$file eq \".\" || $file eq \"..\"} {\n"
	"   continue\n"
	"  }\n"
	"  set file [file join $dir $file]\n"
	"  lappend result $file {*}[_find $file]\n"


	" }\n"
	" return $result\n"
	"}\n"
	"proc ::zipfs::find dir {\n"
	" tailcall lsort [_find $dir]\n"
	"}\n";

    static const char unwrproc[] =
	"namespace eval ::zipfs {}\n"
	"proc ::zipfs::unwrap {{filename {}}} {\n"
	" set noe [::info nameofexecutable]\n"
	" if {$filename eq {}} {\n"
	"  set filename $noe\n"
	" } else {\n"
	"  set filename [file normalize $filename]\n"
	" }\n"
	" set outdir [file rootname $filename].vfs\n"
	" if {[file isdirectory $outdir]} {\n"
	"  return -code error \"directory \\\"$outdir\\\" already exists\"\n"
	" }\n"
	" file mkdir $outdir\n"
	" if {[info $filename] ne {}} {\n"
	"  file copy {*}[glob -directory $filename -- * .*] $outdir\n"
	" } else {\n"
	"  set domnt 1\n"
	"  foreach {zip dir} [mount] {\n"
	"   if {$filename eq $dir} {\n"
	"    set domnt 0\n"
	"    file copy {*}[glob -directory $zip -- * .*] $outdir\n"
	"    break\n"
	"   }\n"
	"  }\n"
	"  if {$domnt} {\n"
	"   mount $filename $filename\n"
	"   file copy {*}[glob -directory $filename -- * .*] $outdir\n"
	"   unmount $filename\n"
	"  }\n"

	" }\n"
	"}\n";

    /* one-time initialization */
    WriteLock();
    if (!ZipFS.initialized) {
#ifdef TCL_THREADS
5432
5433
5434
5435
5436
5437
5438


5439
5440
5441
5442
5443
5444
5445
	if (interp != NULL) {
	    Tcl_StaticPackage(interp, "zipfs", Zipfs_Init, Zipfs_SafeInit);
	}
#endif
    }
    Unlock();
    if (interp != NULL) {


	if (!safe) {
	    Tcl_CreateObjCommand(interp, "::zipfs::mount",
				 ZipFSMountObjCmd, 0, 0);
	    Tcl_CreateObjCommand(interp, "::zipfs::unmount",
				 ZipFSUnmountObjCmd, 0, 0);
	    Tcl_CreateObjCommand(interp, "::zipfs::mkkey",
				 ZipFSMkKeyObjCmd, 0, 0);







>
>







5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
	if (interp != NULL) {
	    Tcl_StaticPackage(interp, "zipfs", Zipfs_Init, Zipfs_SafeInit);
	}
#endif
    }
    Unlock();
    if (interp != NULL) {
	Tcl_Command ensemble;

	if (!safe) {
	    Tcl_CreateObjCommand(interp, "::zipfs::mount",
				 ZipFSMountObjCmd, 0, 0);
	    Tcl_CreateObjCommand(interp, "::zipfs::unmount",
				 ZipFSUnmountObjCmd, 0, 0);
	    Tcl_CreateObjCommand(interp, "::zipfs::mkkey",
				 ZipFSMkKeyObjCmd, 0, 0);
5463
5464
5465
5466
5467
5468
5469
5470

5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
	if (!safe) {
	    Tcl_LinkVar(interp, "::zipfs::wrmax", (char *) &ZipFS.wrmax,
			TCL_LINK_INT);
	    Tcl_LinkVar(interp, "::zipfs::nocpt", (char *) &ZipFS.nocpt,
			TCL_LINK_STRING);
	}

	TclMakeEnsemble(interp, "zipfs", safe ? initSafeMap : initMap);


	if (!safe) {
	    Tcl_Command zipfsCmd;
	    Tcl_Obj *mapDict;

	    zipfsCmd = Tcl_FindCommand(interp, "zipfs", NULL, TCL_GLOBAL_ONLY);
	    if (zipfsCmd) {
		Tcl_GetEnsembleMappingDict(NULL, zipfsCmd, &mapDict);
		Tcl_DictObjPut(NULL, mapDict, Tcl_NewStringObj("find", -1),
			       Tcl_NewStringObj("::zipfs::find", -1));
		Tcl_DictObjPut(NULL, mapDict, Tcl_NewStringObj("unwrap", -1),
			       Tcl_NewStringObj("::zipfs::unwrap", -1));
	    }
	}

	Tcl_PkgProvide(interp, "zipfs", "1.0");
    }
    return TCL_OK;
#else
    if (interp != NULL) {







|
>


<


<
<
|
|
|
|
|
<







5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484

5485
5486


5487
5488
5489
5490
5491

5492
5493
5494
5495
5496
5497
5498
	if (!safe) {
	    Tcl_LinkVar(interp, "::zipfs::wrmax", (char *) &ZipFS.wrmax,
			TCL_LINK_INT);
	    Tcl_LinkVar(interp, "::zipfs::nocpt", (char *) &ZipFS.nocpt,
			TCL_LINK_STRING);
	}

	ensemble = TclMakeEnsemble(interp, "zipfs", safe ?
				   initSafeMap : initMap);

	if (!safe) {

	    Tcl_Obj *mapDict;



	    Tcl_GetEnsembleMappingDict(NULL, ensemble, &mapDict);
	    Tcl_DictObjPut(NULL, mapDict, Tcl_NewStringObj("find", -1),
			   Tcl_NewStringObj("::zipfs::find", -1));
	    Tcl_DictObjPut(NULL, mapDict, Tcl_NewStringObj("unwrap", -1),
			   Tcl_NewStringObj("::zipfs::unwrap", -1));

	}

	Tcl_PkgProvide(interp, "zipfs", "1.0");
    }
    return TCL_OK;
#else
    if (interp != NULL) {
Changes to undroid/build-undroidwish-win32.sh.
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets







|







1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets/VecTcLab0
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets
Changes to undroid/build-undroidwish-win64.sh.
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets







|







1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets/VecTcLab0
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets
Changes to undroid/build-vanilla-win32.sh.
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets







|







1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets/VecTcLab0
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets
Changes to undroid/build-vanilla-win64.sh.
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets







|







1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
  if test -d assets/tclwmf* ; then
    cp -rp ${HERE}/tclwmf*/demos assets/tclwmf*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets/VecTcLab0
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets