]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
When using -l, if a link fails because of a cross-device link,
authorTim Kientzle <kientzle@gmail.com>
Sat, 21 Jun 2008 10:56:12 +0000 (06:56 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 21 Jun 2008 10:56:12 +0000 (06:56 -0400)
ignore the -l for this entry and copy instead.

SVN-Revision: 136

cpio/cpio.c

index 3788611ca88fc4b5b544130b2f12eb2645fc7ead..1012f74c1a3bb596550049d7a935b2e45cc59725 100644 (file)
@@ -26,7 +26,7 @@
 
 
 #include "cpio_platform.h"
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.2 2008/06/21 02:20:20 kientzle Exp $");
 
 #include <sys/types.h>
 #include <archive.h>
@@ -537,9 +537,16 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry)
         * Obviously, this only gets invoked in pass mode.
         */
        if (cpio->option_link) {
-               /* Note: link(2) doesn't create parent directories. */
-               archive_entry_set_hardlink(entry, srcpath);
-               r = archive_write_header(cpio->archive, entry);
+               struct archive_entry *t;
+               /* Save the original entry in case we need it later. */
+               t = archive_entry_clone(entry);
+               if (t == NULL)
+                       cpio_errc(1, ENOMEM, "Can't create link");
+               /* Note: link(2) doesn't create parent directories,
+                * so we use archive_write_header() instead. */
+               archive_entry_set_hardlink(t, srcpath);
+               r = archive_write_header(cpio->archive, t);
+               archive_entry_free(t);
                if (r != ARCHIVE_OK)
                        cpio_warnc(archive_errno(cpio->archive),
                            archive_error_string(cpio->archive));
@@ -547,8 +554,9 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry)
                        exit(1);
 #ifdef EXDEV
                if (r != ARCHIVE_OK && archive_errno(cpio->archive) == EXDEV) {
+                       /* Cross-device link:  Just fall through and use
+                        * the original entry to copy the file over. */
                        cpio_warnc(0, "Copying file instead");
-                       archive_entry_set_hardlink(entry, NULL);
                } else
 #endif
                return (0);