refactor: remove tr_pathbuf::popdir() (#8221)

This commit is contained in:
Charles Kerr
2026-01-25 20:02:59 -06:00
committed by GitHub
parent daf15c01c3
commit a7b2a72cca
7 changed files with 11 additions and 47 deletions

View File

@@ -845,10 +845,6 @@ TEST_F(FileTest, pathDirname)
{
EXPECT_EQ(expected, tr_sys_path_dirname(input))
<< "input[" << input << "] expected [" << expected << "] actual [" << tr_sys_path_dirname(input) << "]\n";
auto path = tr_pathbuf{ input };
path.popdir();
EXPECT_EQ(expected, path) << "input[" << input << "] expected [" << expected << "] actual [" << path << "]\n";
}
/* TODO: is_same(dirname(x) + '/' + basename(x), x) */

View File

@@ -178,13 +178,14 @@ protected:
for (tr_file_index_t i = 0, n = files.file_count(); i < n; ++i)
{
auto walk = tr_pathbuf{ parent, '/', files.path(i) };
createFileWithContents(walk, std::data(Content), std::size(Content));
paths.emplace(walk);
auto const filename = tr_pathbuf{ parent, '/', files.path(i) };
createFileWithContents(filename, std::data(Content), std::size(Content));
paths.emplace(filename);
auto walk = filename.sv();
while (!tr_sys_path_is_same(parent, walk))
{
walk.popdir();
walk = tr_sys_path_dirname(walk);
paths.emplace(walk);
}
}

View File

@@ -212,9 +212,7 @@ protected:
{
auto const tmperr = errno;
auto dir = tr_pathbuf{ path };
dir.popdir();
if (auto const info = tr_sys_path_get_info(path); !info)
if (auto const dir = tr_sys_path_dirname(path); !tr_sys_path_exists(dir))
{
auto error = tr_error{};
tr_sys_dir_create(dir, TR_SYS_DIR_CREATE_PARENTS, 0700, &error);
@@ -433,9 +431,7 @@ protected:
auto const suffix = std::string_view{ partial ? ".part" : "" };
auto const filename = tr_pathbuf{ base, '/', subpath, suffix };
auto dirname = tr_pathbuf{ filename.sv() };
dirname.popdir();
tr_sys_dir_create(dirname, TR_SYS_DIR_CREATE_PARENTS, 0700);
tr_sys_dir_create(tr_sys_path_dirname(filename), TR_SYS_DIR_CREATE_PARENTS, 0700);
auto fd = tr_sys_file_open(filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, 0600);
auto const file_size = metainfo->file_size(i);