From 1f511b8df1599b50d1f0416acd063a82c68a2e6e Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:42:05 -0500 Subject: [PATCH 1/5] Fix Windows Alternate Data Stream (ADS) Support --- mz_os_win32.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mz_os_win32.c b/mz_os_win32.c index b12d980f..8ede40f3 100644 --- a/mz_os_win32.c +++ b/mz_os_win32.c @@ -234,8 +234,7 @@ static void mz_os_unix_to_file_time(time_t unix_time, FILETIME *file_time) { } int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date) { - WIN32_FIND_DATAW ff32; - HANDLE handle = NULL; + WIN32_FILE_ATTRIBUTE_DATA wfad; wchar_t *path_wide = NULL; int32_t err = MZ_INTERNAL_ERROR; @@ -245,21 +244,19 @@ int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *acc if (!path_wide) return MZ_PARAM_ERROR; - handle = FindFirstFileW(path_wide, &ff32); - free(path_wide); - - if (handle != INVALID_HANDLE_VALUE) { + if (GetFileAttributesExW(path_wide, GetFileExInfoStandard, &wfad)) { if (modified_date) - mz_os_file_to_unix_time(ff32.ftLastWriteTime, modified_date); + mz_os_file_to_unix_time(wfad.ftLastWriteTime, modified_date); if (accessed_date) - mz_os_file_to_unix_time(ff32.ftLastAccessTime, accessed_date); + mz_os_file_to_unix_time(wfad.ftLastAccessTime, accessed_date); if (creation_date) - mz_os_file_to_unix_time(ff32.ftCreationTime, creation_date); + mz_os_file_to_unix_time(wfad.ftCreationTime, creation_date); - FindClose(handle); err = MZ_OK; } + free(path_wide); + return err; } From 312d49a92cc788bfac7f07597d1c4a4e0060cb28 Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:09:11 -0500 Subject: [PATCH 2/5] Add gtest validating `mz_os_get_file_date` works on ADS --- test/CMakeLists.txt | 4 ++++ test/test_file.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/test_file.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e244d45..9a477a98 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,6 +58,10 @@ if(NOT MZ_COMPRESS_ONLY AND NOT MZ_DECOMPRESS_ONLY) list(APPEND TEST_SRCS test_stream_compress.cc) endif() +if(MSVC) + list(APPEND TEST_SRCS test_file.cc) +endif() + add_executable(gtest_minizip test_main.cc ${TEST_SRCS}) target_compile_definitions(gtest_minizip PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) target_include_directories(gtest_minizip PRIVATE diff --git a/test/test_file.cc b/test/test_file.cc new file mode 100644 index 00000000..2fa57b4a --- /dev/null +++ b/test/test_file.cc @@ -0,0 +1,45 @@ +/* test_path.cc - Test path functionality + part of the minizip-ng project + + Copyright (C) Nathan Moinvaziri + https://github.com/zlib-ng/minizip-ng + + This program is distributed under the terms of the same license as zlib. + See the accompanying LICENSE file for the full text of the license. +*/ + +#include "mz.h" +#include "mz_os.h" + +#include +#include +#include + +TEST(os, get_file_date_ads) { + + const std::string mainStreamName = "minizip_ads_test"; + const std::string adsName = mainStreamName + ":ads"; + const std::string adsContents = "Alternate Data Stream"; + + // Create main stream + std::ofstream mainStream(mainStreamName); + mainStream.close(); + + // Attach ADS + std::ofstream ads(adsName); + ads << adsContents; + ads.close(); + + // Get file date + time_t modified_date = 0; + time_t accessed_date = 0; + time_t creation_date = 0; + + EXPECT_EQ(MZ_OK, mz_os_get_file_date(adsName.c_str(), &modified_date, &accessed_date, &creation_date)); + + std::remove(mainStreamName.c_str()); + + ASSERT_GT(modified_date, 0); + ASSERT_GT(accessed_date, 0); + ASSERT_GT(creation_date, 0); +} From 219d0f02a8e6b7636e7031c7eb387a1d8c0bbdc1 Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:41:18 -0500 Subject: [PATCH 3/5] snake_case --- test/test_file.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/test_file.cc b/test/test_file.cc index 2fa57b4a..eb04461e 100644 --- a/test/test_file.cc +++ b/test/test_file.cc @@ -17,17 +17,17 @@ TEST(os, get_file_date_ads) { - const std::string mainStreamName = "minizip_ads_test"; - const std::string adsName = mainStreamName + ":ads"; - const std::string adsContents = "Alternate Data Stream"; + const std::string main_stream_name = "minizip_ads_test"; + const std::string ads_name = main_stream_name + ":ads"; + const std::string ads_contents = "Alternate Data Stream"; // Create main stream - std::ofstream mainStream(mainStreamName); - mainStream.close(); + std::ofstream main_stream(main_stream_name); + main_stream.close(); // Attach ADS - std::ofstream ads(adsName); - ads << adsContents; + std::ofstream ads(ads_name); + ads << ads_contents; ads.close(); // Get file date @@ -35,9 +35,9 @@ TEST(os, get_file_date_ads) { time_t accessed_date = 0; time_t creation_date = 0; - EXPECT_EQ(MZ_OK, mz_os_get_file_date(adsName.c_str(), &modified_date, &accessed_date, &creation_date)); + EXPECT_EQ(MZ_OK, mz_os_get_file_date(ads_name.c_str(), &modified_date, &accessed_date, &creation_date)); - std::remove(mainStreamName.c_str()); + std::remove(main_stream_name.c_str()); ASSERT_GT(modified_date, 0); ASSERT_GT(accessed_date, 0); From e6ade897fb81736aa03804349786b4a1b4ec048c Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:20:03 -0500 Subject: [PATCH 4/5] Update test/test_file.cc --- test/test_file.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_file.cc b/test/test_file.cc index eb04461e..af574350 100644 --- a/test/test_file.cc +++ b/test/test_file.cc @@ -16,7 +16,6 @@ #include TEST(os, get_file_date_ads) { - const std::string main_stream_name = "minizip_ads_test"; const std::string ads_name = main_stream_name + ":ads"; const std::string ads_contents = "Alternate Data Stream"; From 4b9251ba42086dff6b71a8fa46824d6c4e20cc1a Mon Sep 17 00:00:00 2001 From: Gabriel Landau <42078554+gabriellandau@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:20:08 -0500 Subject: [PATCH 5/5] Update test/test_file.cc --- test/test_file.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_file.cc b/test/test_file.cc index af574350..6b179657 100644 --- a/test/test_file.cc +++ b/test/test_file.cc @@ -1,4 +1,4 @@ -/* test_path.cc - Test path functionality +/* test_file.cc - Test file functionality part of the minizip-ng project Copyright (C) Nathan Moinvaziri