Tcl Library Source Code

View Ticket
Login
Ticket UUID: 27bed812fa2ec3d5d1aa96a31f7cad2f7917ad14
Title: ::tar::create - Relative path to specific directory
Type: Bug Version:
Submitter: anonymous Created on: 2023-04-25 14:03:39
Subsystem: tar Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2023-04-25 14:03:39
Resolution: None Closed By: nobody
    Closed on:
Description:
We use Tcl in a multi-threaded setup on the NaviServer web server. The current behavior of the ::tar::create command when adding files is:

 1) files specified as absolute paths - in this case the archive will generate paths relative to the system root directory (e.g. /tmp/test.txt becomes in tar archive tmp/test.txt)
 2) files specified as relative paths - in this case the files will be looked up from the current working directory and, when found, will be added with the same path specified as an argument.

We now have a couple of places where we call tar via exec to generate archives and we are thinking we could replace these execs with the tcl tar implementation. 

We 99% of times need these archives to generate relative paths with respect to a certain arbitrary directory, what one achieves via -C with the tar command. In a single-threaded environment we could easily use the cd command to change the working directory beforehand, however this is unfeasible in a multithreaded environment, as we would end up affecting the behavior of other scripts running at the same time in unspecified ways.

We would need some way to specify in a thread-safe way (e.g. without having to change the working directory at any point) a portion of the input path that should be stripped from the resulting path in the tar archive, for instance:

...
::tar::create $wfd {/a/folder/file1.txt /a/folder/file2.txt} -chan -prefix /a/
...

An the resulting paths should be:

folder/file1.txt
folder/file2.txt

Many thanks for any feedback on this