I am trying to add a file to a tar archive from a program output without generating it on disk first. Think of a file VERSION
, that is autogenerated, when the build script runs. I tried this but the dereferenced symlink is only a named pipe, not a regular file:
$ date +%s | \
tar cf test.tar \
--dereference \
--transform="s#/proc/self/fd/0#VERSION#" \
/proc/self/fd/0 \
other_files \
and_folders/
The result should be a file VERSION
with a timestamp inside the tar archive w/o locally generating a file:
$ tar tf test.tar
VERSION
other_files
and_folders
I don't know a way to create a "fake" file entry in a JAR archive. I'd create a normal file, add it to the archive and then delete it afterwards.
You may want to try the option -A
(or --concatenate
), though. That would allow you to create the file in /tmp
, add it to the TAR archive and then append the rest of the files in a second step. That way, you can create arbitrary paths for the VERSION file.
While it's true that tar
works on files, that doesn't mean you have to create temporary files by yourself, and I would advice against it.
You can use process substitution for that (Bash supports that, Fish does as well in a slightly different syntax).
tar cvaf a.tgz <(echo 1.0.0) file1 file2 -P --transform 's:^/.*:VERSION:'
-P
(--absolute-names
) is here to identify the temporary file for name transformation to rename it. Hopefully other files are local.
If that's not the case and some other files are being added by absolute paths (which is probably not the common case), then you can either clarify the transformation regexp or use two-step solution with creating the archive first and then updating it (as Aaron pointed out).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With