From 1c30bd1793b2ccd065091d6c53886e002f35c393 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:15:22 +1100 Subject: [PATCH] fix: strip file:// scheme from foobar paths before scanning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit foobar2000 reports local tracks as file://G:\... — root derivation discarded every one as a stream (roots: []), and track_is_live never checked the disk. Normalize once at the source for roots, existence checks, keys and reports. Prepares 1.8.4. --- CHANGELOG.md | 7 +++++++ src/logic.cpp | 22 ++++++++++++++++++++++ src/logic.h | 4 ++++ src/scanner.cpp | 22 +++++++++++----------- src/version.h | 2 +- tests/test_main.cpp | 12 ++++++++++++ 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e1430..0ad3f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ Versions match `FIP_VERSION` in `src/version.h`. ## [Unreleased] +## [1.8.4] - 2026-11-23 + +### Fixed + +- Dead/empty directory scan now works: foobar2000 reports local paths with a `file://` prefix, which root derivation discarded as a stream. Local paths are stripped to native form everywhere (scan roots, existence checks, dead-track detection, reports). +- Dead-track detection is no longer silently disabled for local files by the same `file://` prefix. + ## [1.8.3] - 2026-10-18 ### Fixed diff --git a/src/logic.cpp b/src/logic.cpp index 50da51c..d5eefd7 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -115,6 +115,28 @@ std::vector common_scan_roots(const std::unordered_set return roots; } +// foobar2000 prefixes local file paths with "file://" (e.g. file://G:\Music). +// Strip it so Win32 APIs and root derivation see the actual filesystem path. +std::string strip_file_scheme(const char *path) { + if (!path) + return {}; + static const char scheme[] = "file://"; + constexpr size_t n = sizeof(scheme) - 1; + const std::string s(path); + if (s.size() >= n) { + bool same = true; + for (size_t i = 0; i < n; ++i) { + if (static_cast(::tolower(static_cast(s[i]))) != scheme[i]) { + same = false; + break; + } + } + if (same) + return s.substr(n); + } + return s; +} + // 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) { diff --git a/src/logic.h b/src/logic.h index 836eb13..4ba4e75 100644 --- a/src/logic.h +++ b/src/logic.h @@ -96,6 +96,10 @@ dir_status classify_directory(const std::vector & filenames); // top folders to scan so empty sibling folders in the watched tree are found. std::vector common_scan_roots(const std::unordered_set & dirPaths); +// foobar2000 reports local files as "file://G:\\path\\track.mp3". Strip the +// scheme so filesystem checks and scan roots see a plain native path. +std::string strip_file_scheme(const char *path); + // 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/scanner.cpp b/src/scanner.cpp index b30c406..b5e33f0 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -4,18 +4,18 @@ #include std::string track_key(metadb_handle_ptr h) { - return track_key_for(h->get_path(), h->get_subsong_index()); + return track_key_for(strip_file_scheme(h->get_path()).c_str(), h->get_subsong_index()); } bool track_is_live(metadb_handle_ptr h, std::unordered_map *cache) { - const char *path = h->get_path(); - if (strstr(path, "://") != nullptr) - return true; + const std::string path = strip_file_scheme(h->get_path()); + if (path.find("://") != std::string::npos) + return true; // stream, not a local file if (cache != nullptr) { if (auto it = cache->find(path); it != cache->end()) return it->second; } - const bool live = (GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES); + const bool live = (GetFileAttributesA(path.c_str()) != INVALID_FILE_ATTRIBUTES); if (cache != nullptr) cache->emplace(path, live); return live; @@ -32,7 +32,7 @@ static std::string track_header(metadb_handle_ptr h) { if (h->format_title(nullptr, t, tf, nullptr) && !t.is_empty()) return t.c_str(); } - return h->get_path(); + return strip_file_scheme(h->get_path()); } scan_result scan_playlists() { @@ -125,7 +125,7 @@ std::vector scan_dead_tracks() { e.playlistName = plname.c_str(); e.item = t; e.header = track_header(items[t]); - e.path = items[t]->get_path(); + e.path = strip_file_scheme(items[t]->get_path()); out.push_back(std::move(e)); } } @@ -155,7 +155,7 @@ std::vector scan_invalid_tags() { e.playlistName = name; e.item = t; e.header = track_header(items[t]); - e.path = items[t]->get_path(); + e.path = strip_file_scheme(items[t]->get_path()); out.push_back(std::move(e)); } } @@ -221,10 +221,10 @@ std::vector scan_dead_directories(std::string *diag) { // Collect unique parent directories from all library tracks. std::unordered_set dirOfTrack; for (t_size t = 0; t < all.get_count(); ++t) { - const char *path = all[t]->get_path(); - if (!path) + const char *rawPath = all[t]->get_path(); + if (!rawPath) continue; - std::string dir(path); + std::string dir(strip_file_scheme(rawPath)); size_t lastSlash = dir.find_last_of("\\/"); if (lastSlash != std::string::npos) dir = dir.substr(0, lastSlash); diff --git a/src/version.h b/src/version.h index d7e63cd..bcca495 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.3" +#define FIP_VERSION "1.8.4" diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 7d918cf..6b4d8f0 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -239,6 +239,17 @@ static void test_record_track_playlist_match() { CHECK_STR_EQ(reports[1].lists[0], "Favorites"); } +static void test_strip_file_scheme() { + // foobar2000 local paths arrive as file:// + native path + CHECK_STR_EQ(strip_file_scheme("file://G:\\My Drive\\Music\\track.mp3"), "G:\\My Drive\\Music\\track.mp3"); + CHECK_STR_EQ(strip_file_scheme("FILE://G:/Music/track.flac"), "G:/Music/track.flac"); + // streams and plain paths pass through untouched + CHECK_STR_EQ(strip_file_scheme("http://server/stream.mp3"), "http://server/stream.mp3"); + CHECK_STR_EQ(strip_file_scheme("G:\\plain.mp3"), "G:\\plain.mp3"); + CHECK_STR_EQ(strip_file_scheme("file://"), ""); + CHECK_STR_EQ(strip_file_scheme(nullptr), ""); +} + 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"); @@ -297,6 +308,7 @@ int main() { test_classify_directory(); test_common_scan_roots(); test_extended_path(); + test_strip_file_scheme(); test_derive_duplicates(); test_derive_orphans(); printf("%d checks, %d failures\n", g_checks, g_failures);