Don't unlink input file if it has other links.
Do not unlink the input file when it has other hard links, unless
--force or -f is specified. The compression proceeds normally, but
the input file remains untouched. This somewhat replicates the
behavior of gzip, except that gzip does nothing if there is a hard
link, and will only compress and unlink if -f is given.
diff --git a/pigz.c b/pigz.c
index 3f1098f..4c1bd1b 100644
--- a/pigz.c
+++ b/pigz.c
@@ -4191,8 +4191,12 @@
g.outd = -1; // now prevent deletion on interrupt
if (g.ind != 0) {
copymeta(g.inf, g.outf);
- if (!g.keep)
- unlink(g.inf);
+ if (!g.keep) {
+ if (st.st_nlink > 1 && !g.force)
+ complain("%s has hard links -- not unlinking", g.inf);
+ else
+ unlink(g.inf);
+ }
}
if (g.decode && (g.headis & 2) != 0 && g.stamp)
touch(g.outf, g.stamp);