]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Fix compression of symlinks with --force.
authorLasse Collin <lasse.collin@tukaani.org>
Mon, 1 Feb 2010 09:44:45 +0000 (11:44 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Mon, 1 Feb 2010 09:44:45 +0000 (11:44 +0200)
xz --force accepted symlinks, but didn't remove
them after successful compression. Instead, an error
message was displayed.

src/xz/file_io.c

index c1bca19632c5b13d9226e12e50c41dbbdbe6327d..020f33dda520cf9560b7c3862342d3b26d30c359 100644 (file)
@@ -100,7 +100,19 @@ io_unlink(const char *name, const struct stat *known_st)
 #else
        struct stat new_st;
 
-       if (lstat(name, &new_st)
+       // If --force was used, use stat() instead of lstat(). This way
+       // (de)compressing symlinks works correctly. However, it also means
+       // that xz cannot detect if a regular file foo is renamed to bar
+       // and then a symlink foo -> bar is created. Because of stat()
+       // instead of lstat(), xz will think that foo hasn't been replaced
+       // with another file. Thus, xz will remove foo even though it no
+       // longer is the same file that xz used when it started compressing.
+       // Probably it's not too bad though, so this doesn't need a more
+       // complex fix.
+       const int stat_ret = opt_force
+                       ? stat(name, &new_st) : lstat(name, &new_st);
+
+       if (stat_ret
 #      ifdef __VMS
                        // st_ino is an array, and we don't want to
                        // compare st_dev at all.