From fb2012925ecdde269976c87e214463bac172d605 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 11:09:04 +1100 Subject: [PATCH 1/7] ci: release tagging driven by version.h instead of a robot bump PR --- .github/workflows/auto-approve.yml | 4 +- .github/workflows/release.yml | 153 +++-------------------------- 2 files changed, 16 insertions(+), 141 deletions(-) diff --git a/.github/workflows/auto-approve.yml b/.github/workflows/auto-approve.yml index b0ebae3..035c8b6 100644 --- a/.github/workflows/auto-approve.yml +++ b/.github/workflows/auto-approve.yml @@ -10,9 +10,7 @@ permissions: jobs: auto-approve: runs-on: ubuntu-latest - if: >- - github.event.pull_request.user.login == 'ccombe' || - github.event.pull_request.user.login == 'github-actions[bot]' + if: github.event.pull_request.user.login == 'ccombe' steps: - name: Auto-approve env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a22b2c..db1eedb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,25 +4,13 @@ on: push: branches: [master, main] workflow_dispatch: - inputs: - bump_type: - description: "Manual bump type override (patch, minor, major, or auto)" - required: false - default: "auto" - type: choice - options: - - auto - - patch - - minor - - major permissions: contents: write - pull-requests: write jobs: release: - name: Semantic Release & Publish + name: Build & Publish Release runs-on: windows-latest steps: - name: Checkout code @@ -31,136 +19,25 @@ jobs: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - - name: Calculate Semantic Version + # Version lives in src/version.h (bumped in a normal PR). A release + # happens whenever that version has no matching tag yet. + - name: Decide whether to release id: semver shell: pwsh - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MANUAL_BUMP: ${{ github.event.inputs.bump_type }} run: | - git fetch --tags --force - $tags = git tag -l --sort=-v:refname "v*" - $latestTag = if ($tags) { ($tags -split "`r?`n")[0].Trim() } else { $null } - - if (-not $latestTag) { - Write-Host "No existing release tags found. Setting initial baseline version." - $content = Get-Content src/version.h -Raw - $m = [regex]::Match($content, 'FIP_VERSION\s+"([^"]+)"') - $base = if ($m.Success) { $m.Groups[1].Value } else { "1.4.0" } - $parts = $base.Split('.') - while ($parts.Count -lt 3) { $parts += '0' } - $newVersion = ($parts[0..2] -join '.') - $newTag = "v$newVersion" - $range = "HEAD" - } else { - Write-Host "Latest release tag found: $latestTag" - $range = "$latestTag..HEAD" - # Ignore automated "chore(release)" bump commits; they do not drive new releases - # (prevents an infinite patch-bump loop after a release lands). - $subjects = @(git log $range --pretty=format:"%s") - $meaningful = @($subjects | Where-Object { $_ -notmatch "^chore\(release\)" }) - if (-not $meaningful) { - Write-Host "No new meaningful commits since $latestTag. Skipping release." - Write-Output "should_release=false" >> $env:GITHUB_OUTPUT - exit 0 - } - $commitText = ($meaningful -join "`n").Trim() - - $raw = $latestTag.TrimStart('v') - $parts = $raw.Split('.') - while ($parts.Count -lt 3) { $parts += '0' } - [int]$major = $parts[0] - [int]$minor = $parts[1] - [int]$patch = $parts[2] - - $bump = if ($env:MANUAL_BUMP -and $env:MANUAL_BUMP -ne 'auto') { $env:MANUAL_BUMP } else { $null } - if (-not $bump) { - if ($commitText -match "(?m)^[a-zA-Z]+(\([^\)]+\))?!:" -or $commitText -match "BREAKING CHANGE") { - $bump = "major" - } elseif ($commitText -match "(?m)^feat(\([^\)]+\))?:") { - $bump = "minor" - } else { - $bump = "patch" - } - } - - Write-Host "Determined bump type: $bump" - if ($bump -eq "major") { - $major++ - $minor = 0 - $patch = 0 - } elseif ($bump -eq "minor") { - $minor++ - $patch = 0 - } else { - $patch++ - } - - $newVersion = "$major.$minor.$patch" - $newTag = "v$newVersion" - } - - Write-Output "should_release=true" >> $env:GITHUB_OUTPUT - Write-Output "version=$newVersion" >> $env:GITHUB_OUTPUT - Write-Output "tag=$newTag" >> $env:GITHUB_OUTPUT - Write-Output "range=$range" >> $env:GITHUB_OUTPUT - Write-Host "Calculated next release: $newVersion (tag: $newTag)" - - - name: Update version.h and CHANGELOG.md - if: steps.semver.outputs.should_release == 'true' - shell: pwsh - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - $ver = "${{ steps.semver.outputs.version }}" - $today = (Get-Date).ToString("yyyy-MM-dd") - - # 1. Update src/version.h $vh = Get-Content src/version.h -Raw - $vhUpdated = [regex]::Replace($vh, 'FIP_VERSION\s+"[^"]+"', "FIP_VERSION `"$ver`"") - $vhUpdated | Out-File src/version.h -Encoding utf8 - - # 2. Update CHANGELOG.md - $cl = Get-Content CHANGELOG.md -Raw - $shortVer = $ver -replace '\.0$', '' - $hasHeader = ($cl -match [regex]::Escape("## [$ver]")) -or ($cl -match [regex]::Escape("## [$shortVer]")) - if (-not $hasHeader) { - $range = "${{ steps.semver.outputs.range }}" - $commitLines = @(git log $range --pretty=format:"- %s (%h)") - $commitBody = if ($commitLines.Count -gt 0) { $commitLines -join "`n" } else { "- Maintenance and updates." } - - $newEntry = "## [Unreleased]`n`n## [$ver] - $today`n`n### Changes`n$commitBody" - if ($cl -match "(?ms)^## \[Unreleased\].*?(?=^## \[|\z)") { - $unreleasedContent = [regex]::Match($cl, "(?ms)^## \[Unreleased\]\s*(.*?)(?=^## \[|\z)").Groups[1].Value.Trim() - if ($unreleasedContent -ne "") { - $newEntry = "## [Unreleased]`n`n## [$ver] - $today`n`n$unreleasedContent" - } - $cl = [regex]::Replace($cl, "(?ms)^## \[Unreleased\].*?(?=^## \[|\z)", "$newEntry`n`n") - } else { - $cl = "## [Unreleased]`n`n## [$ver] - $today`n`n$commitBody`n`n" + $cl - } - $cl | Out-File CHANGELOG.md -Encoding utf8 - } - - # 3. Commit the bump on a release branch and open an auto-merge PR - - # master requires pull requests (branch protection), so a direct push is rejected. - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add src/version.h CHANGELOG.md - git diff-index --quiet HEAD - if ($LASTEXITCODE -ne 0) { - npx prettier --write CHANGELOG.md - git add src/version.h CHANGELOG.md - $branch = "release/bump-version$($ver -replace '\.', '-')" - git checkout -b $branch - git commit -m "chore(release): bump version to $ver" - # force: a previous attempt may have left the branch behind - git push origin $branch --force - $prUrl = gh pr create --title "chore(release): bump version to $ver" --body "Automated version bump for v$ver. Auto-merges once checks pass." - gh pr merge $prUrl --auto --squash - Write-Host "Opened auto-merge PR for version bump: $prUrl" + $m = [regex]::Match($vh, 'FIP_VERSION\s+"([^"]+)"') + $ver = if ($m.Success) { $m.Groups[1].Value } else { "0.0.0" } + git fetch --tags --force + $exists = git rev-parse -q --verify "refs/tags/v$ver" 2>$null + if ($LASTEXITCODE -eq 0 -and $exists) { + Write-Host "Tag v$ver already exists. Skipping release." + Write-Output "should_release=false" >> $env:GITHUB_OUTPUT } else { - Write-Host "No file changes needed for version bump." + Write-Host "Will release v$ver" + Write-Output "should_release=true" >> $env:GITHUB_OUTPUT + Write-Output "version=$ver" >> $env:GITHUB_OUTPUT + Write-Output "tag=v$ver" >> $env:GITHUB_OUTPUT } - name: Setup MSBuild From 54081062fbddd4a7be9c9db0f71701976b02a4e4 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 11:41:10 +1100 Subject: [PATCH 2/7] fix: dead-dir scan starts at watched-tree root; Properties group renders off main thread --- src/logic.cpp | 74 +++++++++++++++++++++++++++++++++++++-------- src/logic.h | 4 +++ src/properties.cpp | 12 +++++--- src/scanner.cpp | 26 ++++++++++------ src/stdafx.h | 1 + tests/test_main.cpp | 31 +++++++++++++++++++ 6 files changed, 122 insertions(+), 26 deletions(-) diff --git a/src/logic.cpp b/src/logic.cpp index 3a42ca7..c7772b5 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -3,6 +3,7 @@ #include "logic.h" #include +#include #include #include @@ -39,21 +40,70 @@ bool has_invalid_tag_chars(const char *field) { return false; } -bool record_track_playlist_match(const std::string & key, const std::string & playlistName, - const std::unordered_map & indexOf, - std::vector & reports) { - const auto it = indexOf.find(key); - if (it == indexOf.end()) - return false; - - auto & lists = reports[it->second].lists; - if (!lists.empty() && lists.back() == playlistName) - return false; +// Deepest shared ancestor (per drive volume) of the given directory paths: +// the top folder to scan so empty sibling folders in the watched tree are found. +// Returns one root per volume that actually holds library directories. +std::vector common_scan_roots(const std::unordered_set & dirPaths) { + auto toNorm = [](std::string s) { + for (auto & c : s) { + if (c == '/') + c = '\\'; + else + c = static_cast(::tolower(static_cast(c))); + } + return s; + }; + + // volume ("g:\") -> (component lists, one original-case dir to cut the root from) + struct vol { + std::vector> comps; + const std::string *sample = nullptr; + }; + std::unordered_map byVolume; + for (const auto & raw : dirPaths) { + const std::string norm = toNorm(raw); + const size_t colon = norm.find(":\\"); + if (colon == std::string::npos) // not a file path (network, stream...) + continue; + const std::string volume = norm.substr(0, colon + 2); + std::vector parts; + size_t i = volume.size(); + while (i < norm.size()) { + size_t next = norm.find('\\', i); + if (next == std::string::npos) + next = norm.size(); + if (i < next) // ignore empty segments (e.g. doubleslash) + parts.push_back(norm.substr(i, next - i)); + i = next + 1; + } + auto & v = byVolume[volume]; + v.comps.push_back(std::move(parts)); + v.sample = &raw; + } - lists.push_back(playlistName); - return true; + std::vector roots; + roots.reserve(byVolume.size()); + for (auto & [volume, v] : byVolume) { + size_t rootLen = volume.size(); // original-case root cut from the sample dir + for (size_t i = 0; i < v.comps[0].size(); ++i) { + const auto & part = v.comps[0][i]; + bool shared = true; + for (const auto & c : v.comps) + if (i >= c.size() || c[i] != part) + shared = false; + if (!shared) + break; + rootLen += part.size() + 1; // component + separator + } + roots.push_back(v.sample->substr(0, rootLen)); + } + return roots; } +bool record_track_playlist_match(const std::string & key, const std::string & playlistName, + +bool record_track_playlist_match(const std::string & key, const std::string & playlistName, + static void append_track_report_entry(pfc::string_base & f, const track_report & r) { f << r.header.c_str() << "\n"; if (r.lists.empty()) { diff --git a/src/logic.h b/src/logic.h index 380a1b1..05caf20 100644 --- a/src/logic.h +++ b/src/logic.h @@ -91,3 +91,7 @@ enum class dir_status { // Classifies a list of filenames (not full paths) in a directory. 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); diff --git a/src/properties.cpp b/src/properties.cpp index a4df9f8..fff6c52 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -8,17 +8,21 @@ class playlist_property_provider : public track_property_provider_v5 { public: + // v5 property properties are enumerated off the main thread in fb2k v2; + // playlist APIs are main-thread only, so hop there synchronously. void enumerate_properties_v5(trackListRef items, track_property_provider_v5_info_source &, - track_property_callback_v2 & cb, abort_callback &) override { - if (!core_api::is_main_thread()) - return; // playlist APIs are main-thread only + track_property_callback_v2 & cb, abort_callback & abort) override { if (!cb.is_group_wanted("Playlists")) return; metadb_handle_list sel; for (size_t i = 0; i < items.get_size(); ++i) sel.add_item(items[i]); std::vector reports; - find_playlists_for(sel, reports); + if (core_api::is_main_thread()) { + find_playlists_for(sel, reports); + } else { + fb2k::inMainThreadSynchronous([&] { find_playlists_for(sel, reports); }, abort); + } for (const auto & r : reports) { pfc::string_formatter count; count << r.lists.size(); diff --git a/src/scanner.cpp b/src/scanner.cpp index c2d89d2..22fa695 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -188,7 +188,7 @@ std::vector scan_dead_directories() { lm->get_all_items(all); // Collect unique parent directories from all library tracks. - std::unordered_set roots; + std::unordered_set dirOfTrack; for (t_size t = 0; t < all.get_count(); ++t) { const char *path = all[t]->get_path(); if (!path) @@ -197,16 +197,20 @@ std::vector scan_dead_directories() { size_t lastSlash = dir.find_last_of("\\/"); if (lastSlash != std::string::npos) dir = dir.substr(0, lastSlash); - roots.insert(dir); + dirOfTrack.insert(dir); } - // For each unique directory, enumerate all subdirectories recursively. + // Scan from the deepest common ancestor per volume, not from leaf dirs + // only - empty folders sitting beside album folders would else be missed. + const std::vector roots = common_scan_roots(dirOfTrack); + + // For each root, enumerate all subdirectories recursively. std::unordered_set visited; for (const auto & root : roots) { - std::vector stack; - stack.push_back(root); + std::vector> stack; + stack.emplace_back(root, true); while (!stack.empty()) { - std::string dir = stack.back(); + auto [dir, isTop] = stack.back(); stack.pop_back(); if (!dir.empty() && (dir.back() == '\\' || dir.back() == '/')) @@ -236,16 +240,18 @@ std::vector scan_dead_directories() { } while (FindNextFileA(hFind, &fd)); FindClose(hFind); - // Classify this directory. - dir_status st = classify_directory(filenames); - if (st == dir_status::empty_or_dead) { + // Classify this directory. The shared ancestor itself is never + // dead - it just wraps the tree being scanned. A dir with + // subfolders is skipped too: cleanup targets are true leaf + // folders, and RemoveDirectoryA would fail on them anyway. + if (!isTop && subdirs.empty() && classify_directory(filenames) == dir_status::empty_or_dead) { candidates.push_back(dir); } // Push subdirs for traversal. for (const auto & sd : subdirs) { if (!visited.count(sd)) - stack.push_back(sd); + stack.emplace_back(sd, false); } } } diff --git a/src/stdafx.h b/src/stdafx.h index eb33da1..17203e1 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/test_main.cpp b/tests/test_main.cpp index d945eae..d44097e 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -168,6 +168,36 @@ static void test_classify_directory() { CHECK(classify_directory({"song.flac", "readme.txt"}) == dir_status::has_music); } +static void test_common_scan_roots() { + // Deepest shared ancestor of sibling leaf dirs + std::vector r1 = common_scan_roots({"H:\\Music\\Rock\\Album A", "H:\\Music\\Pop\\Album B"}); + CHECK(r1.size() == 1); + CHECK(r1[0] == "H:\\Music\\"); + + // Mixed-case and forward slashes normalize to one volume + std::vector r2 = common_scan_roots({"h:/music/rock/album a", "H:\\MUSIC\\JAZZ\\"}); + CHECK(r2.size() == 1); + for (auto & c : r2[0]) { + if (c == '/') + c = '\\'; + c = static_cast(::tolower(static_cast(c))); + } + CHECK(r2[0] == "h:\\music\\"); + + // Two volumes -> one root per volume + std::vector r3 = common_scan_roots({"H:\\Music\\Rock", "I:\\Music\\Jazz"}); + CHECK(r3.size() == 2); + + // A dir directly in the volume -> root is the volume itself + std::vector r4 = common_scan_roots({"H:\\Music\\Rock", "H:\\Track.mp3"}); + CHECK(r4.size() == 1); + CHECK(r4[0] == "H:\\"); + + // Non-file paths are ignored + CHECK(common_scan_roots({"http://server/stream"}).empty()); + CHECK(common_scan_roots({}).empty()); +} + static void test_record_track_playlist_match() { std::unordered_map indexOf; std::vector reports; @@ -252,6 +282,7 @@ int main() { test_is_music_file(); test_is_ignorable_file(); test_classify_directory(); + test_common_scan_roots(); test_derive_duplicates(); test_derive_orphans(); printf("%d checks, %d failures\n", g_checks, g_failures); From 50f5c28b836442bd0a410fbedf88311ea724b1a2 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 11:41:54 +1100 Subject: [PATCH 3/7] chore(release): prepare 1.8.1 --- CHANGELOG.md | 7 +++++++ src/version.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bbdaf6..8a6f90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ Versions match `FIP_VERSION` in `src/version.h`. ## [Unreleased] +## [1.8.1] - 2026-10-18 + +### Fixed + +- Find Dead/Empty Directories now scans the whole watched tree: roots are the deepest shared folder per volume, so empty folders that sit beside album folders are found too. Folders containing subfolders are no longer misreported as dead. +- The Properties dialog now shows the "Playlists" group reliably: playlist lookups hop to the main thread when foobar enumerates properties on a worker thread. + ## [1.8.0] - 2026-10-17 ### Changes diff --git a/src/version.h b/src/version.h index c3a97e8..d88c627 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.0" +#define FIP_VERSION "1.8.1" From e480ae3e12482fbf34b17c180f1bf966104c4c14 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:23:45 +1100 Subject: [PATCH 4/7] fix: skip network paths in scan root derivation --- src/logic.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/logic.cpp b/src/logic.cpp index c7772b5..c6a30db 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -61,6 +61,8 @@ std::vector common_scan_roots(const std::unordered_set }; std::unordered_map byVolume; for (const auto & raw : dirPaths) { + if (raw.find("://") != std::string::npos) // network / stream path + continue; const std::string norm = toNorm(raw); const size_t colon = norm.find(":\\"); if (colon == std::string::npos) // not a file path (network, stream...) @@ -101,8 +103,19 @@ std::vector common_scan_roots(const std::unordered_set } bool record_track_playlist_match(const std::string & key, const std::string & playlistName, + const std::unordered_map & indexOf, + std::vector & reports) { + const auto it = indexOf.find(key); + if (it == indexOf.end()) + return false; -bool record_track_playlist_match(const std::string & key, const std::string & playlistName, + auto & lists = reports[it->second].lists; + if (!lists.empty() && lists.back() == playlistName) + return false; + + lists.push_back(playlistName); + return true; +} static void append_track_report_entry(pfc::string_base & f, const track_report & r) { f << r.header.c_str() << "\n"; From d5bc11fe1e2d23d5eaa59f0c6a1786a6d0e12e84 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:28:16 +1100 Subject: [PATCH 5/7] refactor: extract list_dir_entries --- src/scanner.cpp | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/scanner.cpp b/src/scanner.cpp index 22fa695..20c6932 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -181,6 +181,27 @@ bool tag_has_invalid_chars(metadb_handle_ptr h) { return false; } +// Enumerate one directory's direct files and subfolders. +static bool list_dir_entries(const std::string & dir, std::vector & filenames, + std::vector & subdirs) { + WIN32_FIND_DATAA fd; + HANDLE hFind = FindFirstFileA((dir + "\\*").c_str(), &fd); + if (hFind == INVALID_HANDLE_VALUE) + return false; + do { + const char *name = fd.cFileName; + if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) + continue; + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + subdirs.push_back(dir + "\\" + name); + } else { + filenames.push_back(name); + } + } while (FindNextFileA(hFind, &fd)); + FindClose(hFind); + return true; +} + std::vector scan_dead_directories() { std::vector candidates; static_api_ptr_t lm; @@ -220,25 +241,10 @@ std::vector scan_dead_directories() { continue; visited.insert(dir); - // Enumerate entries in this directory. - WIN32_FIND_DATAA fd; - HANDLE hFind = FindFirstFileA((dir + "\\*").c_str(), &fd); - if (hFind == INVALID_HANDLE_VALUE) - continue; - std::vector filenames; std::vector subdirs; - do { - const char *name = fd.cFileName; - if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) - continue; - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - subdirs.push_back(dir + "\\" + name); - } else { - filenames.push_back(name); - } - } while (FindNextFileA(hFind, &fd)); - FindClose(hFind); + if (!list_dir_entries(dir, filenames, subdirs)) + continue; // Classify this directory. The shared ancestor itself is never // dead - it just wraps the tree being scanned. A dir with From 3a8403e8cb92bf99781a969e350c2731195c0414 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:32:44 +1100 Subject: [PATCH 6/7] refactor: split common_scan_roots into file-scope helpers --- src/logic.cpp | 73 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/src/logic.cpp b/src/logic.cpp index c6a30db..a2a94c9 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -40,20 +40,47 @@ bool has_invalid_tag_chars(const char *field) { return false; } +namespace { + +// Lowercase everything so volume/prefix matching is case-insensitive. +std::string normalized_dir(std::string s) { + for (auto & c : s) { + if (c == '/') + c = '\\'; + else + c = static_cast(::tolower(static_cast(c))); + } + return s; +} + +// Append the \\-separated path components of s[start..] to out. +void split_components(std::vector & out, const std::string & s, size_t start) { + size_t i = start; + while (i < s.size()) { + size_t next = s.find('\\', i); + if (next == std::string::npos) + next = s.size(); + if (i < next) // ignore empty segments (e.g. doubleslash) + out.push_back(s.substr(i, next - i)); + i = next + 1; + } +} + +// True if every directory in the volume shares comps[i] == part. +bool all_share_component(const std::vector> & comps, size_t i, const std::string & part) { + for (const auto & c : comps) { + if (i >= c.size() || c[i] != part) + return false; + } + return true; +} + +} // namespace + // Deepest shared ancestor (per drive volume) of the given directory paths: // the top folder to scan so empty sibling folders in the watched tree are found. // Returns one root per volume that actually holds library directories. std::vector common_scan_roots(const std::unordered_set & dirPaths) { - auto toNorm = [](std::string s) { - for (auto & c : s) { - if (c == '/') - c = '\\'; - else - c = static_cast(::tolower(static_cast(c))); - } - return s; - }; - // volume ("g:\") -> (component lists, one original-case dir to cut the root from) struct vol { std::vector> comps; @@ -63,23 +90,14 @@ std::vector common_scan_roots(const std::unordered_set for (const auto & raw : dirPaths) { if (raw.find("://") != std::string::npos) // network / stream path continue; - const std::string norm = toNorm(raw); + const std::string norm = normalized_dir(raw); const size_t colon = norm.find(":\\"); - if (colon == std::string::npos) // not a file path (network, stream...) + if (colon == std::string::npos) // not a file path continue; const std::string volume = norm.substr(0, colon + 2); - std::vector parts; - size_t i = volume.size(); - while (i < norm.size()) { - size_t next = norm.find('\\', i); - if (next == std::string::npos) - next = norm.size(); - if (i < next) // ignore empty segments (e.g. doubleslash) - parts.push_back(norm.substr(i, next - i)); - i = next + 1; - } auto & v = byVolume[volume]; - v.comps.push_back(std::move(parts)); + v.comps.push_back({}); + split_components(v.comps.back(), norm, volume.size()); v.sample = &raw; } @@ -88,14 +106,9 @@ std::vector common_scan_roots(const std::unordered_set for (auto & [volume, v] : byVolume) { size_t rootLen = volume.size(); // original-case root cut from the sample dir for (size_t i = 0; i < v.comps[0].size(); ++i) { - const auto & part = v.comps[0][i]; - bool shared = true; - for (const auto & c : v.comps) - if (i >= c.size() || c[i] != part) - shared = false; - if (!shared) + if (!all_share_component(v.comps, i, v.comps[0][i])) break; - rootLen += part.size() + 1; // component + separator + rootLen += v.comps[0][i].size() + 1; // component + separator } roots.push_back(v.sample->substr(0, rootLen)); } From 059dd8ecf971ee346e2c7b02e4cfb5718ce03a66 Mon Sep 17 00:00:00 2001 From: el combo <24692334+ccombe@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:39:52 +1100 Subject: [PATCH 7/7] fix: check_quality brace desync from URLs inside string literals --- scripts/check_quality.py | 58 +++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/scripts/check_quality.py b/scripts/check_quality.py index ca57845..a4b289f 100644 --- a/scripts/check_quality.py +++ b/scripts/check_quality.py @@ -10,15 +10,55 @@ import argparse def strip_comments_and_strings(code: str) -> str: - # Remove single line comments - code = re.sub(r"//.*", "", code) - # Remove multi-line comments - code = re.sub(r"/\*.*?\*/", "", code, flags=re.DOTALL) - # Remove string literals - code = re.sub(r"\"(?:\\.|[^\"\\])*\"", "\"\"", code) - # Remove char literals - code = re.sub(r"\'(?:\\.|[^\'\\])*\'", "''", code) - return code + # Single-pass state machine: comment stripping must not run before string + # handling, or a "://" inside a string literal is mistaken for a comment + # start and desynchronizes quote/brace pairing for the whole file. + out = [] + i = 0 + n = len(code) + state = 0 # 0: code, 1: line comment, 2: block comment, 3: string, 4: char + while i < n: + c = code[i] + nxt = code[i + 1] if i + 1 < n else "" + if state == 0: + if c == "/" and nxt == "/": + state = 1 + i += 2 + elif c == "/" and nxt == "*": + state = 2 + i += 2 + elif c == '"': + state = 3 + out.append('"') + i += 1 + elif c == "'": + state = 4 + out.append("'") + i += 1 + else: + out.append(c) + i += 1 + elif state == 1: # line comment: keep the newline + if c == "\n": + state = 0 + out.append("\n") + i += 1 + elif state == 2: # block comment + if c == "*" and nxt == "/": + state = 0 + i += 2 + else: + i += 1 + else: # string (3) or char (4): keep quotes, drop escapes whole + if c == "\\": + i += 2 + elif (state == 3 and c == '"') or (state == 4 and c == "'"): + state = 0 + out.append(c) + i += 1 + else: + i += 1 + return "".join(out) def analyze_functions(filepath: str, is_unit_tested: bool = False): with open(filepath, "r", encoding="utf-8", errors="ignore") as f: