1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 19:03:04 +00:00

fix: 5053 old torrent files keep appearing (#5117)

This commit is contained in:
Charles Kerr 2023-03-01 20:12:19 -06:00 committed by GitHub
parent d21a3b622a
commit d3273504bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 34 deletions

View file

@ -621,22 +621,14 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor)
// --- // ---
auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load, bool* did_migrate_filename) auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load)
{ {
auto fields_loaded = tr_resume::fields_t{}; auto fields_loaded = tr_resume::fields_t{};
TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isTorrent(tor));
auto const was_dirty = tor->isDirty; auto const was_dirty = tor->isDirty;
auto const migrated = tr_torrent_metainfo::migrateFile( tr_torrent_metainfo::migrateFile(tor->session->resumeDir(), tor->name(), tor->infoHashString(), ".resume"sv);
tor->session->resumeDir(),
tor->name(),
tor->infoHashString(),
".resume"sv);
if (did_migrate_filename != nullptr)
{
*did_migrate_filename = migrated;
}
auto const filename = tor->resumeFile(); auto const filename = tor->resumeFile();
if (!tr_sys_path_exists(filename)) if (!tr_sys_path_exists(filename))
@ -865,7 +857,7 @@ auto useFallbackFields(tr_torrent* tor, tr_resume::fields_t fields, tr_ctor cons
} }
} // namespace } // namespace
fields_t load(tr_torrent* tor, fields_t fields_to_load, tr_ctor const* ctor, bool* did_rename_to_hash_only_name) fields_t load(tr_torrent* tor, fields_t fields_to_load, tr_ctor const* ctor)
{ {
TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isTorrent(tor));
@ -873,7 +865,7 @@ fields_t load(tr_torrent* tor, fields_t fields_to_load, tr_ctor const* ctor, boo
ret |= useMandatoryFields(tor, fields_to_load, ctor); ret |= useMandatoryFields(tor, fields_to_load, ctor);
fields_to_load &= ~ret; fields_to_load &= ~ret;
ret |= loadFromFile(tor, fields_to_load, did_rename_to_hash_only_name); ret |= loadFromFile(tor, fields_to_load);
fields_to_load &= ~ret; fields_to_load &= ~ret;
ret |= useFallbackFields(tor, fields_to_load, ctor); ret |= useFallbackFields(tor, fields_to_load, ctor);

View file

@ -46,7 +46,7 @@ auto inline constexpr Group = fields_t{ 1 << 23 };
auto inline constexpr All = ~fields_t{ 0 }; auto inline constexpr All = ~fields_t{ 0 };
fields_t load(tr_torrent* tor, fields_t fields_to_load, tr_ctor const* ctor, bool* did_rename_to_hash_only_name); fields_t load(tr_torrent* tor, fields_t fields_to_load, tr_ctor const* ctor);
void save(tr_torrent* tor); void save(tr_torrent* tor);

View file

@ -679,22 +679,20 @@ bool tr_torrent_metainfo::migrateFile(
std::string_view suffix) std::string_view suffix)
{ {
auto const old_filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix); auto const old_filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix);
auto const old_filename_exists = tr_sys_path_exists(old_filename); if (!tr_sys_path_exists(old_filename))
auto const new_filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix); {
auto const new_filename_exists = tr_sys_path_exists(new_filename); return false;
}
if (old_filename_exists && new_filename_exists) auto const new_filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix);
if (tr_sys_path_exists(new_filename))
{ {
tr_sys_path_remove(old_filename); tr_sys_path_remove(old_filename);
return false; return false;
} }
if (new_filename_exists) auto const renamed = tr_sys_path_rename(old_filename, new_filename);
{ if (!renamed)
return false;
}
if (old_filename_exists && tr_sys_path_rename(old_filename, new_filename))
{ {
tr_logAddError( tr_logAddError(
fmt::format( fmt::format(
@ -705,7 +703,7 @@ bool tr_torrent_metainfo::migrateFile(
return true; return true;
} }
return false; // neither file exists return renamed;
} }
void tr_torrent_metainfo::removeFile( void tr_torrent_metainfo::removeFile(

View file

@ -1105,15 +1105,9 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
// the same ones that would be saved back again, so don't let them // the same ones that would be saved back again, so don't let them
// affect the 'is dirty' flag. // affect the 'is dirty' flag.
auto const was_dirty = tor->isDirty; auto const was_dirty = tor->isDirty;
loaded = tr_resume::load(tor, tr_resume::All, ctor);
bool resume_file_was_migrated = false;
loaded = tr_resume::load(tor, tr_resume::All, ctor, &resume_file_was_migrated);
tor->isDirty = was_dirty; tor->isDirty = was_dirty;
tr_torrent_metainfo::migrateFile(session->torrentDir(), tor->name(), tor->infoHashString(), ".torrent"sv);
if (resume_file_was_migrated)
{
tr_torrent_metainfo::migrateFile(session->torrentDir(), tor->name(), tor->infoHashString(), ".torrent"sv);
}
} }
tor->completeness = tor->completion.status(); tor->completeness = tor->completion.status();

View file

@ -192,7 +192,7 @@ TEST_F(RenameTest, singleFilenameTorrent)
// (while it's renamed: confirm that the .resume file remembers the changes) // (while it's renamed: confirm that the .resume file remembers the changes)
tr_resume::save(tor); tr_resume::save(tor);
sync(); sync();
auto const loaded = tr_resume::load(tor, tr_resume::All, ctor, nullptr); auto const loaded = tr_resume::load(tor, tr_resume::All, ctor);
EXPECT_STREQ("foobar", tr_torrentName(tor)); EXPECT_STREQ("foobar", tr_torrentName(tor));
EXPECT_NE(decltype(loaded){ 0 }, (loaded & tr_resume::Name)); EXPECT_NE(decltype(loaded){ 0 }, (loaded & tr_resume::Name));
@ -303,7 +303,7 @@ TEST_F(RenameTest, multifileTorrent)
tr_resume::save(tor); tr_resume::save(tor);
// this is a bit dodgy code-wise, but let's make sure the .resume file got the name // this is a bit dodgy code-wise, but let's make sure the .resume file got the name
tor->setFileSubpath(1, "gabba gabba hey"sv); tor->setFileSubpath(1, "gabba gabba hey"sv);
auto const loaded = tr_resume::load(tor, tr_resume::All, ctor, nullptr); auto const loaded = tr_resume::load(tor, tr_resume::All, ctor);
EXPECT_NE(decltype(loaded){ 0 }, (loaded & tr_resume::Filenames)); EXPECT_NE(decltype(loaded){ 0 }, (loaded & tr_resume::Filenames));
EXPECT_EQ(ExpectedFiles[0], tr_torrentFile(tor, 0).name); EXPECT_EQ(ExpectedFiles[0], tr_torrentFile(tor, 0).name);
EXPECT_STREQ("Felidae/Felinae/Felis/placeholder/Kyphi", tr_torrentFile(tor, 1).name); EXPECT_STREQ("Felidae/Felinae/Felis/placeholder/Kyphi", tr_torrentFile(tor, 1).name);