From 433e36b049f1ffcec9f7aca27c33ab35b433d4b2 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Sun, 19 Feb 2017 00:08:43 +0100 Subject: [PATCH] posix writer: when creating hardinks call open() on regular files only Fixes #724 --- libarchive/archive_write_disk_posix.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 49e79dc23..20450bafc 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -2067,6 +2067,7 @@ create_filesystem_object(struct archive_write_disk *a) int r; /* these for check_symlinks_fsobj */ char *linkname_copy; /* non-const copy of linkname */ + struct stat st; struct archive_string error_string; int error_number; @@ -2131,11 +2132,20 @@ create_filesystem_object(struct archive_write_disk *a) a->todo = 0; a->deferred = 0; } else if (r == 0 && a->filesize > 0) { - a->fd = open(a->name, O_WRONLY | O_TRUNC | O_BINARY - | O_CLOEXEC | O_NOFOLLOW); - __archive_ensure_cloexec_flag(a->fd); - if (a->fd < 0) +#ifdef HAVE_LSTAT + r = lstat(a->name, &st); +#else + r = stat(a->name, &st); +#endif + if (r != 0) r = errno; + else if ((st.st_mode & AE_IFMT) == AE_IFREG) { + a->fd = open(a->name, O_WRONLY | O_TRUNC | + O_BINARY | O_CLOEXEC | O_NOFOLLOW); + __archive_ensure_cloexec_flag(a->fd); + if (a->fd < 0) + r = errno; + } } return (r); #endif -- 2.47.2