summaryrefslogtreecommitdiff
path: root/libarchive/archive_write_disk_posix.c
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2017-02-19 00:08:43 +0100
committerMartin Matuska <martin@matuska.org>2017-02-19 01:03:24 +0100
commit433e36b049f1ffcec9f7aca27c33ab35b433d4b2 (patch)
tree7fb8ceb2c3346b0fa585dc72faeaea2894d8a9f9 /libarchive/archive_write_disk_posix.c
parent109d48410aaae69bd7e88e076e1fc6f6e13891b6 (diff)
downloadlibarchive-433e36b049f1ffcec9f7aca27c33ab35b433d4b2.tar.gz
posix writer: when creating hardinks call open() on regular files only
Fixes #724
Diffstat (limited to 'libarchive/archive_write_disk_posix.c')
-rw-r--r--libarchive/archive_write_disk_posix.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c
index 49e79dc2..20450baf 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