I have a program that takes a file, compresses it using /usr/bin/zip
or /bin/gzip
or /bin/bzip2
, and removes the original if and only if the compress operation completes successfully.
However, this program can be killed (via kill -9
), or, in principle, can even crash on its own!
Question: Can I assume that the zipped output file that gets created on disk is always valid, without ever having to decompress it and comparing it with the original?
In other words, no matter the point the compress operation gets ungracefully interrupted at, does the fact that the compressed output file exists on disk imply it's valid?
In other words, are the compress operation and the file creation on disk together an atomic transaction?
The main concern here is not removing the original file if the compressed file is invalid, but without having to undergo the costly decompress and compare operations.
Note:
Ignore OS file buffers not flushing to disk due to UPS failure.
Ignore disk/media related failure. This can happen much later anyway, and quite independently of the program's interruption.