From 2f0be17e48e848bc8eac4446ccd8a1b101e54e6e Mon Sep 17 00:00:00 2001 From: Zack Weger Date: Mon, 8 Oct 2018 11:17:10 -0400 Subject: [PATCH 1/3] Files with invalid names don't exist, so don't set an error --- libarchive/archive_read_support_format_mtree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 4a2816325f..3e797289ee 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -1251,7 +1251,10 @@ parse_file(struct archive_read *a, struct archive_entry *entry, mtree->fd = open(path, O_RDONLY | O_BINARY | O_CLOEXEC); __archive_ensure_cloexec_flag(mtree->fd); if (mtree->fd == -1 && - (errno != ENOENT || + /* On Windows, attempting to open a file with an invalid name + * result in EINVAL (Error 22) + */ + ((errno != ENOENT && errno != EINVAL) || archive_strlen(&mtree->contents_name) > 0)) { archive_set_error(&a->archive, errno, "Can't open %s", path); From eb147233c252b97d81a39ce73111e3f416441765 Mon Sep 17 00:00:00 2001 From: Zack Weger Date: Fri, 12 Oct 2018 11:36:44 -0400 Subject: [PATCH 2/3] Skip match_time tests when running on Windows, since the ctime can't be set --- libarchive/test/test_archive_match_time.c | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libarchive/test/test_archive_match_time.c b/libarchive/test/test_archive_match_time.c index c6864b3265..23754a1538 100644 --- a/libarchive/test/test_archive_match_time.c +++ b/libarchive/test/test_archive_match_time.c @@ -321,6 +321,11 @@ test_newer_ctime_than_file_mbs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -435,6 +440,11 @@ test_newer_ctime_than_file_wcs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -782,6 +792,11 @@ test_older_ctime_than_file_mbs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -897,6 +912,11 @@ test_older_ctime_than_file_wcs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -1073,6 +1093,11 @@ test_ctime_between_files_mbs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -1132,6 +1157,11 @@ test_ctime_between_files_wcs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { From 4471283392192f9ad38fd3085f8d32dbd07d6126 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Thu, 30 Jun 2022 14:12:43 +0100 Subject: [PATCH 3/3] Clean up the condition so we check EINVAL on Windows only. --- libarchive/archive_read_support_format_mtree.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 3e797289ee..55f391cff0 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -1250,12 +1250,17 @@ parse_file(struct archive_read *a, struct archive_entry *entry, archive_entry_filetype(entry) == AE_IFDIR) { mtree->fd = open(path, O_RDONLY | O_BINARY | O_CLOEXEC); __archive_ensure_cloexec_flag(mtree->fd); - if (mtree->fd == -1 && - /* On Windows, attempting to open a file with an invalid name - * result in EINVAL (Error 22) - */ - ((errno != ENOENT && errno != EINVAL) || - archive_strlen(&mtree->contents_name) > 0)) { + if (mtree->fd == -1 && ( +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * On Windows, attempting to open a file with an + * invalid name result in EINVAL (Error 22) + */ + (errno != ENOENT && errno != EINVAL) +#else + errno != ENOENT +#endif + || archive_strlen(&mtree->contents_name) > 0)) { archive_set_error(&a->archive, errno, "Can't open %s", path); r = ARCHIVE_WARN;