summaryrefslogtreecommitdiff
path: root/libarchive/archive_write_disk_windows.c
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2020-01-22 17:13:43 +0100
committerMartin Matuska <martin@matuska.org>2020-01-22 17:54:13 +0100
commit2f3fea2105c2a17af705f5f125d4e5d6b2cec8ff (patch)
tree2ad481773dfaa05f25da37f1b6102f2c0663b121 /libarchive/archive_write_disk_windows.c
parent0c9f04e7a93463cb0a2e27c210904393498e252f (diff)
downloadlibarchive-2f3fea2105c2a17af705f5f125d4e5d6b2cec8ff.tar.gz
Fix error when overwriting files on Windows
Introduced in 467d193dd61ca7669a5ba8d38e09836babf64e58
Diffstat (limited to 'libarchive/archive_write_disk_windows.c')
-rw-r--r--libarchive/archive_write_disk_windows.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/libarchive/archive_write_disk_windows.c b/libarchive/archive_write_disk_windows.c
index adf89bc5..111b5412 100644
--- a/libarchive/archive_write_disk_windows.c
+++ b/libarchive/archive_write_disk_windows.c
@@ -1569,14 +1569,7 @@ restore_entry(struct archive_write_disk *a)
ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS) {
(void)clear_nochange_fflags(a);
}
- if (dirlnk) {
- /* Edge case: dir symlink pointing to a file */
- if (disk_rmdir(a->name) != 0) {
- archive_set_error(&a->archive, errno,
- "Can't unlink directory symlink");
- return (ARCHIVE_FAILED);
- }
- } else if ((a->flags & ARCHIVE_EXTRACT_SAFE_WRITES) &&
+ if ((a->flags & ARCHIVE_EXTRACT_SAFE_WRITES) &&
S_ISREG(st_mode)) {
int fd = la_mktemp(a);
@@ -1588,17 +1581,30 @@ restore_entry(struct archive_write_disk *a)
a->pst = NULL;
en = 0;
-
- } else if (disk_unlink(a->name) != 0) {
- /* A non-dir is in the way, unlink it. */
- archive_set_error(&a->archive, errno,
- "Can't unlink already-existing object");
- return (ARCHIVE_FAILED);
+ } else {
+ if (dirlnk) {
+ /* Edge case: dir symlink pointing
+ * to a file */
+ if (disk_rmdir(a->name) != 0) {
+ archive_set_error(&a->archive,
+ errno, "Can't unlink "
+ "directory symlink");
+ return (ARCHIVE_FAILED);
+ }
+ } else {
+ if (disk_unlink(a->name) != 0) {
+ /* A non-dir is in the way,
+ * unlink it. */
+ archive_set_error(&a->archive,
+ errno, "Can't unlink "
+ "already-existing object");
+ return (ARCHIVE_FAILED);
+ }
+ }
a->pst = NULL;
/* Try again. */
en = create_filesystem_object(a);
}
-
} else if (!S_ISDIR(a->mode)) {
/* A dir is in the way of a non-dir, rmdir it. */
if (a->flags & ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS)