From 5278b052910ae1d34503980a6b95dc59ac1a552a Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 14:22:35 +1100 Subject: [PATCH] fix: scan long paths via extended-length paths; dead-dir reports include scan stats --- CHANGELOG.md | 10 ++++++++++ src/logic.cpp | 14 ++++++++++++++ src/logic.h | 4 ++++ src/main_menu.cpp | 20 ++++++++++++++------ src/scanner.cpp | 25 +++++++++++++++++++++---- src/scanner.h | 5 +++-- src/version.h | 2 +- tests/test_main.cpp | 14 ++++++++++++++ 8 files changed, 81 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5bb1f4..53e1430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ Versions match `FIP_VERSION` in `src/version.h`. ## [Unreleased] +## [1.8.3] - 2026-10-18 + +### Fixed + +- Deep folder trees beyond MAX_PATH (260 characters) are now scanned and removable via extended-length (`\\?\`) paths. + +### Added + +- Find/Remove Dead-Empty Directories reports include scan statistics (library items seen, scan roots, directories visited, unreadable counts) to diagnose missed locations. + ## [1.8.2] - 2026-10-18 ### Fixed diff --git a/src/logic.cpp b/src/logic.cpp index a2a94c9..50da51c 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -115,6 +115,20 @@ std::vector common_scan_roots(const std::unordered_set return roots; } +// Windows extended-length path so > MAX_PATH trees still enumerate. The \\?\ +// prefix also keeps names like "[unnamed]" literal for the file APIs. +std::string extended_path(const std::string & path) { + std::string s = path; + std::replace(s.begin(), s.end(), '/', '\\'); + if (s.rfind("\\\\?\\", 0) == 0) + return s; // already extended + if (s.rfind("\\\\", 0) == 0) + return "\\\\?\\UNC" + s.substr(1); // UNC: \\server\share -> \\?\UNC\server\share + if (s.size() >= 2 && s[1] == ':') + return "\\\\?\\" + s; + return s; // relative or unusual: leave as is +} + bool record_track_playlist_match(const std::string & key, const std::string & playlistName, const std::unordered_map & indexOf, std::vector & reports) { diff --git a/src/logic.h b/src/logic.h index 05caf20..836eb13 100644 --- a/src/logic.h +++ b/src/logic.h @@ -95,3 +95,7 @@ dir_status classify_directory(const std::vector & filenames); // Deepest shared ancestor (per drive volume) of the given directory paths - the // top folders to scan so empty sibling folders in the watched tree are found. std::vector common_scan_roots(const std::unordered_set & dirPaths); + +// Windows extended-length path (\\?\ prefix) so folders deeper than MAX_PATH +// still work with Win32 file APIs and std::filesystem narrow operations. +std::string extended_path(const std::string & path); diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 118a780..7fcebf5 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -338,9 +338,11 @@ class main_find_playing : public mainmenu_commands { } static void run_dead_dirs() { - auto dirs = scan_dead_directories(); + std::string diag; + auto dirs = scan_dead_directories(&diag); pfc::string_formatter msg; msg << "Dead/empty directories found: " << dirs.size() << "\n"; + msg << "Scan stats: " << diag.c_str() << "\n\n"; for (const auto & d : dirs) msg << d.c_str() << "\n"; report("Find in Playlists: dead directories", msg); @@ -353,15 +355,19 @@ class main_find_playing : public mainmenu_commands { } static void run_remove_dead_dirs() { - auto dirs = scan_dead_directories(); + std::string diag; + auto dirs = scan_dead_directories(&diag); if (dirs.empty()) { pfc::string_formatter _sum; - _sum << "No dead/empty directories found."; + _sum << "No dead/empty directories found.\nScan stats: " << diag.c_str() + << "\nFull detail in the report file."; + report("Find in Playlists: dead directories (removal)", _sum); confirm("Find in Playlists", _sum); return; } pfc::string_formatter msg; msg << "Dead/empty directories to remove: " << dirs.size() << "\n"; + msg << "Scan stats: " << diag.c_str() << "\n\n"; for (const auto & d : dirs) msg << d.c_str() << "\n"; report("Find in Playlists: dead directories (removal)", msg); @@ -375,7 +381,9 @@ class main_find_playing : public mainmenu_commands { // wildcard pattern, so folder names like "[unnamed]" fail. namespace fs = std::filesystem; std::error_code ec; - for (fs::directory_iterator it(fs::path(dir), fs::directory_options::skip_permission_denied, ec), end; + for (fs::directory_iterator + it(fs::path(extended_path(dir)), fs::directory_options::skip_permission_denied, ec), + end; it != end && !ec; it.increment(ec)) { std::string name; try { @@ -383,7 +391,7 @@ class main_find_playing : public mainmenu_commands { } catch (const std::system_error &) { continue; // undecodable name: skip the entry } - const std::string fullPath = dir + std::string("\\") + name; + const std::string fullPath = extended_path(dir + std::string("\\") + name); if (it->is_directory(ec)) { if (ec) break; @@ -393,7 +401,7 @@ class main_find_playing : public mainmenu_commands { } } ec.clear(); - if (RemoveDirectoryA(dir.c_str())) + if (RemoveDirectoryA(extended_path(dir).c_str())) ++removed; else ++failed; diff --git a/src/scanner.cpp b/src/scanner.cpp index b33cbdc..b30c406 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -188,8 +188,10 @@ static bool list_dir_entries(const std::string & dir, std::vector & std::vector & subdirs) { namespace fs = std::filesystem; std::error_code ec; - for (fs::directory_iterator it(fs::path(dir), fs::directory_options::skip_permission_denied, ec), end; it != end; - it.increment(ec)) { + // extended_path: > MAX_PATH trees and literal "[unnamed]" names. + for (fs::directory_iterator it(fs::path(extended_path(dir)), fs::directory_options::skip_permission_denied, ec), + end; + it != end; it.increment(ec)) { if (ec) break; std::string name; @@ -209,8 +211,9 @@ static bool list_dir_entries(const std::string & dir, std::vector & return !ec; } -std::vector scan_dead_directories() { +std::vector scan_dead_directories(std::string *diag) { std::vector candidates; + size_t enumFailures = 0; static_api_ptr_t lm; metadb_handle_list all; lm->get_all_items(all); @@ -250,8 +253,10 @@ std::vector scan_dead_directories() { std::vector filenames; std::vector subdirs; - if (!list_dir_entries(dir, filenames, subdirs)) + if (!list_dir_entries(dir, filenames, subdirs)) { + ++enumFailures; continue; + } // Classify this directory. The shared ancestor itself is never // dead - it just wraps the tree being scanned. A dir with @@ -273,6 +278,18 @@ std::vector scan_dead_directories() { std::sort(candidates.begin(), candidates.end()); candidates.erase(std::unique(candidates.begin(), candidates.end()), candidates.end()); + if (diag) { + std::string rootsJoined; + for (const auto & r : roots) { + if (!rootsJoined.empty()) + rootsJoined += "; "; + rootsJoined += r; + } + *diag = "library items: " + std::to_string(all.get_count()) + + ", track dirs: " + std::to_string(dirOfTrack.size()) + ", roots: [" + rootsJoined + + "], dirs visited: " + std::to_string(visited.size()) + + ", unreadable dirs: " + std::to_string(enumFailures); + } return candidates; } diff --git a/src/scanner.h b/src/scanner.h index 4edc889..56e2e40 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -34,8 +34,9 @@ void goto_track_in_playlist(const std::string & playlist, const std::string & ke std::vector scan_invalid_tags(); // Directories under the media library that are empty or contain only ignorable files. -// Returns a list of directory paths that are candidates for deletion. -std::vector scan_dead_directories(); +// Returns a list of directory paths that are candidates for deletion. When diag is +// given, it receives a one-line scan summary (items seen, roots, dirs visited, errors). +std::vector scan_dead_directories(std::string *diag = nullptr); // Playlists this component manages. Excluded from every scan and from export: // otherwise collected tracks would re-flag themselves on the next run. diff --git a/src/version.h b/src/version.h index def9352..d7e63cd 100644 --- a/src/version.h +++ b/src/version.h @@ -2,4 +2,4 @@ // Single source of truth for the component version. // Automatically updated by GitHub Actions semantic release. -#define FIP_VERSION "1.8.2" +#define FIP_VERSION "1.8.3" diff --git a/tests/test_main.cpp b/tests/test_main.cpp index d44097e..7d918cf 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -239,6 +239,19 @@ static void test_record_track_playlist_match() { CHECK_STR_EQ(reports[1].lists[0], "Favorites"); } +static void test_extended_path() { + // Normal drive paths get the extended-length prefix + CHECK_STR_EQ(extended_path("G:\\My Drive\\Music"), "\\\\?\\G:\\My Drive\\Music"); + // Forward slashes become backslashes + CHECK_STR_EQ(extended_path("g:/music"), "\\\\?\\g:\\music"); + // Already extended paths pass through untouched + CHECK_STR_EQ(extended_path("\\\\?\\G:\\Music"), "\\\\?\\G:\\Music"); + // UNC shares use the UNC form + CHECK_STR_EQ(extended_path("\\\\server\\share\\dir"), "\\\\?\\UNC\\server\\share\\dir"); + // Relative paths pass through + CHECK_STR_EQ(extended_path("relative\\dir"), "relative\\dir"); +} + static void test_derive_duplicates() { scan_result result; result.tracks = { @@ -283,6 +296,7 @@ int main() { test_is_ignorable_file(); test_classify_directory(); test_common_scan_roots(); + test_extended_path(); test_derive_duplicates(); test_derive_orphans(); printf("%d checks, %d failures\n", g_checks, g_failures);