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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Versions match `FIP_VERSION` in `src/version.h`.

## [Unreleased]

## [1.8.6] - 2026-11-23

### Fixed

- Dead-track removal failures are now reported per entry with a reason (stale playlist index, duplicate entry, or playlist API failure) in the report file and the foobar console, and the popup includes the report file path.

## [1.8.5] - 2026-11-23

### Changed
Expand Down
25 changes: 23 additions & 2 deletions src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,18 @@ void format_report(const std::vector<track_report> & reports, pfc::string_base &
}

void format_dead_report(const std::vector<dead_entry> & dead, bool removed, pfc::string_base & out) {
const std::vector<std::string> none;
const std::vector<removal_failure> none;
format_dead_report(dead, removed, none, out);
}

void format_dead_report(const std::vector<dead_entry> & dead, bool removed,
const std::vector<std::string> & failedPlaylists, pfc::string_base & out) {
std::vector<removal_failure> failures;
for (const auto & name : failedPlaylists)
failures.push_back({name, "", "playlist removal failed"});
format_dead_report(dead, removed, failures, out);
}

static void append_dead_entry_item(pfc::string_base & body, const dead_entry & entry) {
body << " - " << entry.header.c_str();
if (!entry.path.empty())
Expand All @@ -213,7 +221,7 @@ static void append_dead_summary_header(pfc::string_base & head, size_t deadCount
}

void format_dead_report(const std::vector<dead_entry> & dead, bool removed,
const std::vector<std::string> & failedPlaylists, pfc::string_base & out) {
const std::vector<removal_failure> & failures, pfc::string_base & out) {
if (dead.empty()) {
out << "No dead tracks found. Nothing to do.\n";
return;
Expand All @@ -230,6 +238,11 @@ void format_dead_report(const std::vector<dead_entry> & dead, bool removed,
i = j;
}

std::vector<std::string> failedPlaylists;
for (const auto & f : failures)
if (std::find(failedPlaylists.begin(), failedPlaylists.end(), f.playlist) == failedPlaylists.end())
failedPlaylists.push_back(f.playlist);

append_dead_summary_header(out, dead.size(), affected, removed);

// Pass 2: Stream group headers and items directly into out with O(1) group counts
Expand All @@ -246,6 +259,14 @@ void format_dead_report(const std::vector<dead_entry> & dead, bool removed,

i = j;
}

if (!failures.empty()) {
out << "\nFAILED REMOVALS (" << failures.size() << "):\n";
for (const auto & f : failures) {
out << " - [" << f.playlist.c_str() << "] " << f.entry.c_str() << "\n";
out << " Reason: " << f.reason.c_str() << "\n";
}
}
}

static bool is_forbidden_filename_char(char c) {
Expand Down
9 changes: 9 additions & 0 deletions src/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ std::vector<dup_info> derive_orphans(const scan_result & result, const std::unor

// Formatters ----------------------------------------------------------------

// One dead entry that could not be removed, with the reason it was skipped.
struct removal_failure {
std::string playlist;
std::string entry;
std::string reason;
};

void format_report(const std::vector<track_report> & reports, pfc::string_base & out);
void format_dead_report(const std::vector<dead_entry> & dead, bool removed, pfc::string_base & out);
void format_dead_report(const std::vector<dead_entry> & dead, bool removed,
const std::vector<std::string> & failedPlaylists, pfc::string_base & out);
void format_dead_report(const std::vector<dead_entry> & dead, bool removed,
const std::vector<removal_failure> & failures, pfc::string_base & out);
std::string safe_filename(const char *name);

// Writes body to %TEMP%\foo_findplaylists_report.txt. Returns the path.
Expand Down
24 changes: 18 additions & 6 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,29 @@ class main_find_playing : public mainmenu_commands {

static void run_remove_dead() {
auto dead = scan_dead_tracks();
std::vector<std::string> failed;
std::vector<removal_failure> failed;
const t_size removed = apply_dead_removal(dead, failed);
pfc::string_formatter msg;
format_dead_report(dead, true, failed, msg);
report("Find in Playlists: dead tracks", msg);
const std::string path = report_path("Find in Playlists: dead tracks", msg);

for (const auto & f : failed) {
pfc::string_formatter line;
line << "FAILED [" << f.playlist.c_str() << "] " << f.entry.c_str() << " - " << f.reason.c_str();
FB2K_console_formatter() << line;
}

pfc::string_formatter sum;
if (dead.empty())
if (dead.empty()) {
sum << "No dead tracks found. Nothing changed.";
else
sum << "Removed " << removed << " of " << dead.size() << " dead entries."
<< (failed.empty() ? "" : " Some removals FAILED, see report.") << "\nUndo with Ctrl+Z per playlist.";
} else {
sum << "Removed " << removed << " of " << dead.size() << " dead entries.";
if (!failed.empty())
sum << "\n" << failed.size() << " FAILED - details in console and report: " << path.c_str();
else
sum << "\nReport: " << path.c_str();
sum << "\nUndo with Ctrl+Z per playlist.";
}
confirm("Find in Playlists", sum);
}

Expand Down
28 changes: 21 additions & 7 deletions src/playlist_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ t_size collect_into(const char *plname, const std::vector<metadb_handle_ptr> & t
return add.get_count();
}

t_size apply_dead_removal(const std::vector<dead_entry> & dead, std::vector<std::string> & failedPlaylists) {
failedPlaylists.clear();
t_size apply_dead_removal(const std::vector<dead_entry> & dead, std::vector<removal_failure> & failures) {
failures.clear();
if (dead.empty())
return 0;
static_api_ptr_t<playlist_manager> pm;
Expand All @@ -68,8 +68,16 @@ t_size apply_dead_removal(const std::vector<dead_entry> & dead, std::vector<std:
size_t j = i;
while (j < dead.size() && dead[j].playlist == dead[i].playlist &&
dead[j].playlistName == dead[i].playlistName) {
if (dead[j].item < items.get_count() && !mask.m[dead[j].item]) {
mask.m[dead[j].item] = 1;
const dead_entry & entry = dead[j];
if (entry.item >= items.get_count()) {
failures.push_back({entry.playlistName, entry.header,
"entry index " + std::to_string(entry.item) + " no longer exists in playlist (" +
std::to_string(items.get_count()) + " items); playlist changed since scan"});
} else if (mask.m[entry.item]) {
failures.push_back(
{entry.playlistName, entry.header, "duplicate dead entry at index " + std::to_string(entry.item)});
} else {
mask.m[entry.item] = 1;
++marked;
}
++j;
Expand All @@ -78,10 +86,16 @@ t_size apply_dead_removal(const std::vector<dead_entry> & dead, std::vector<std:
i = j;
continue;
}
if (pm->playlist_remove_items(pl, mask))
if (pm->playlist_remove_items(pl, mask)) {
total += marked;
else
failedPlaylists.push_back(dead[i].playlistName);
} else {
for (size_t k = i; k < j; ++k) {
if (dead[k].item < items.get_count() && mask.m[dead[k].item]) {
failures.push_back({dead[k].playlistName, dead[k].header,
"playlist_remove_items failed (playlist unavailable or read-only)"});
}
}
}
i = j;
}
return total;
Expand Down
4 changes: 3 additions & 1 deletion src/playlist_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ t_size find_or_create_playlist(const char *name);
// them; anything added manually is wiped on the next run.
t_size collect_into(const char *plname, const std::vector<metadb_handle_ptr> & tracks);

t_size apply_dead_removal(const std::vector<dead_entry> & dead, std::vector<std::string> & failedPlaylists);
// Removes dead entries grouped by playlist. failures receives one record per
// entry that could not be removed, with the playlist, entry and reason.
t_size apply_dead_removal(const std::vector<dead_entry> & dead, std::vector<removal_failure> & failures);
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.5"
#define FIP_VERSION "1.8.6"
9 changes: 9 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ static void test_format_dead() {
"(Undo per playlist with Ctrl+Z if anything looks wrong.)\n"
"Mix A: 1\n - Artist - One\n Z:\\path\\one.mp3\n");
CHECK_STR_EQ(fmt_dead({}, false), "No dead tracks found. Nothing to do.\n");

// Failed removals are reported individually with a reason
pfc::string_formatter withFailure;
format_dead_report({a}, true, std::vector<removal_failure>{{"Mix A", "Artist - One", "playlist unavailable"}},
withFailure);
const std::string text(withFailure.c_str());
CHECK(text.find("FAILED REMOVALS (1)") != std::string::npos);
CHECK(text.find("Reason: playlist unavailable") != std::string::npos);
CHECK(text.find("(REMOVAL FAILED, untouched)") != std::string::npos);
}

static void test_write_report_file() {
Expand Down
Loading