Zip MD5 depends on file creation time - md5sum

My build artifact is packed in a archive. And I need a way to check if it's been changed after rebuild by comparing the MD5 (which is the easiest option so far).
So when I pack the same file but with different creation time - archive MD5 changes. So I need to generate a archive which MD5 relies on inner files MD5.
Consider the below snippet as an example:
touch file
md5 file
zip -X file.zip ./file
md5 file.zip
touch file
md5 file
zip -X file.zip ./file
md5 file.zip
My goal to have the same archive MD5 sum for file with the same MD5 sums.

Related

Exclude a directory from `podman/docker export` stream and save to a file

I have a container that I want to export as a .tar file. I have used a podman run with a tar --exclude=/dir1 --exclude=/dir2 … that outputs to a file located on a bind-mounted host dir. But recently this has been giving me some tar: .: file changed as we read it errors, which podman/docker export would avoid. Besides the export I suppose is more efficient. So I'm trying to migrate to using the export, but the major obstacle is I can't seem to find a way to exclude paths from the tar stream.
If possible, I'd like to avoid modifying a tar archive already saved on disk, and instead modify the stream before it gets saved to a file.
I've been banging my head for multiple hours, trying useless advices from ChatGPT, looking at cpio, and attempting to pipe the podman export to tar --exclude … command. With the last I did have small success at some point, but couldn't make tar save the result to a particularly named file.
Any suggestions?
(note: I do not make distinction between docker and podman here as their export command is completely the same, and it's useful for searchability)

How to Modify tar.gz file in windows?

I have a tr.gz backup file, and I need to delete some file inside of this tar.gz file without extract the tar.gz file.
Is there any solution (command line or software) in windows?
It is not possible to remove the file from tar, but you can exclude a file by the following command
tar -zxvf file.tar.gz --exclude "file_to_exclude"
or
take a backup too and proceed
OR
tar -cvf files.tar --remove-files my_directory

Different sha256 between nix-hash and nix-prefetch-url

When I want to precompute the sha256 of a downloaded file foo.txt, the output of nix-hash on the manually downloaded file is different from the one that is printed by nix-prefetch-url.
How can I compute the same hash with nix-hash?
The standard format of nix-hash is different from the one that nix-prefetch-url uses.
To get the same output from the manually downloaded file as nix-prefetch-url would give, run nix-hash like this:
nix-hash --type sha256 --flat --base32 <file>

tar: preserving only file names, contents and executable bit

I want to use tar to preserve only file names, file contents, and the executable bit for the owner (and ignore the executable bit for group and other). The command I have come up with is
tar -cf <name>.tar --numeric-owner --owner=0 --group=0 --mode="go-rwx,u-rw" <files>
I would like the output <name>.tar not to change unless I change the file name, file contents, or owner's executable bit in one or more of <files>. Assume that the <files> are in sorted order by name.
Will the command that I have written do that?

Encrypt file in Rails 3.2

I want to encrypt a binary file with an asymetric key from my filesystem within rails (and then deliver it via email).
Can you recommend me how to do this? is it possible via bcrypt?
Didnt found so much (not outdated) informations about this...
Ok, i found a solution by myself - i did it with gpg...
First you have to generate/install the public key on the server and copy the private to your local machine.. afterwards you can use following command to encrypt and compress the file(if you have gzip installed):
# encrypting
system "gpg --armor -e -r 'receiverid' -o #{MYFILE_ENC} #{MYFILE} "
# compressing
system "gzip #{MYFILE_ENC}"

Resources