From 55df6d225ba06745514386ae02b040679a705f2b Mon Sep 17 00:00:00 2001 From: Nir Bar Date: Tue, 26 Nov 2024 11:43:41 +0200 Subject: [PATCH] Fix file iterator- graceful recovery if base folder doesn't exist or is empty --- src/PanelSwCustomActions/FileIterator.cpp | 11 ++++++++++- src/TidyBuild.custom.props | 2 +- src/UnitTests/FileOperationsUT/FileOperationsUT.wxs | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/PanelSwCustomActions/FileIterator.cpp b/src/PanelSwCustomActions/FileIterator.cpp index 3fd1f63..71e5926 100644 --- a/src/PanelSwCustomActions/FileIterator.cpp +++ b/src/PanelSwCustomActions/FileIterator.cpp @@ -51,7 +51,16 @@ CFileEntry CFileIterator::Find(LPCWSTR szBasePath, LPCWSTR szPattern, bool bRecu // We're searching without filespec wildcard pattern so we can match subfolders _hFind = ::FindFirstFile(szBasePattern, &_findData); - ExitOnInvalidHandleWithLastError(_hFind, _hrStatus, "Failed to find files in '%ls'", szBasePath); + if (_hFind == INVALID_HANDLE_VALUE) + { + DWORD dwError = ::GetLastError(); + if ((dwError == ERROR_FILE_NOT_FOUND) || (dwError == ERROR_PATH_NOT_FOUND) || (dwError == ERROR_NO_MORE_FILES)) + { + _hrStatus = E_NOMOREFILES; + ExitFunction(); + } + ExitOnWin32Error(dwError, _hrStatus, "Failed to find files in '%ls'", szBasePath); + } return ProcessFindData(); diff --git a/src/TidyBuild.custom.props b/src/TidyBuild.custom.props index 9cbe27d..86f7a11 100644 --- a/src/TidyBuild.custom.props +++ b/src/TidyBuild.custom.props @@ -2,7 +2,7 @@ - 3.22.0 + 3.22.1 $(FullVersion).$(GITHUB_RUN_NUMBER) PanelSwWixExtension Panel::Software diff --git a/src/UnitTests/FileOperationsUT/FileOperationsUT.wxs b/src/UnitTests/FileOperationsUT/FileOperationsUT.wxs index d6c5279..1a32b48 100644 --- a/src/UnitTests/FileOperationsUT/FileOperationsUT.wxs +++ b/src/UnitTests/FileOperationsUT/FileOperationsUT.wxs @@ -11,7 +11,8 @@ - + + @@ -27,6 +28,7 @@ +