Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ std::vector<std::string> common_scan_roots(const std::unordered_set<std::string>
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<std::string, size_t> & indexOf,
std::vector<track_report> & reports) {
Expand Down
4 changes: 4 additions & 0 deletions src/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ dir_status classify_directory(const std::vector<std::string> & 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<std::string> common_scan_roots(const std::unordered_set<std::string> & 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);
20 changes: 14 additions & 6 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -375,15 +381,17 @@ 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 {
name = it->path().filename().string();
} 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;
Expand All @@ -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;
Expand Down
25 changes: 21 additions & 4 deletions src/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ static bool list_dir_entries(const std::string & dir, std::vector<std::string> &
std::vector<std::string> & 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;
Expand All @@ -209,8 +211,9 @@ static bool list_dir_entries(const std::string & dir, std::vector<std::string> &
return !ec;
}

std::vector<std::string> scan_dead_directories() {
std::vector<std::string> scan_dead_directories(std::string *diag) {
std::vector<std::string> candidates;
size_t enumFailures = 0;
static_api_ptr_t<library_manager> lm;
metadb_handle_list all;
lm->get_all_items(all);
Expand Down Expand Up @@ -250,8 +253,10 @@ std::vector<std::string> scan_dead_directories() {

std::vector<std::string> filenames;
std::vector<std::string> 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
Expand All @@ -273,6 +278,18 @@ std::vector<std::string> 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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ void goto_track_in_playlist(const std::string & playlist, const std::string & ke
std::vector<dead_entry> 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<std::string> 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<std::string> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 14 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
Expand Down
Loading