Skip to content

Conversation

@silverweed
Copy link
Contributor

@silverweed silverweed commented Nov 26, 2025

Currently this doesn't work as expected:

auto dir1 = file->mkdir("a/b");
auto dir2 = file->mkdir("a/b", "", /* returnExisting = */ true); // should return the already-existing dir
EXPECT_EQ(dir1, dir2); // FAILS: dir2 is nullptr

because TDirectoryFile::mkdir doesn't propagate the value of returnExistingDirectory to recursive mkdir calls. This PR fixes it.

In addition, title was currently only applied to the topmost directory in case of hierarchies, which is counterintuitive as the returned TDirectory is actually the innermost. This PR changes the (previously undocumented) title logic to the opposite: every non-leaf directory gets created with a default title and only the innermost gets the user-defined one. In our codebase we have 0 cases of mkdir being called with a hierarchy and an explicit title, so this change shouldn't impact anything.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

@silverweed silverweed self-assigned this Nov 26, 2025
@silverweed silverweed requested a review from pcanal as a code owner November 26, 2025 10:38
@silverweed silverweed mentioned this pull request Nov 26, 2025
2 tasks
@github-actions
Copy link

Test Results

    22 files      22 suites   4d 2h 29m 4s ⏱️
 3 780 tests  3 780 ✅ 0 💤 0 ❌
81 234 runs  81 234 ✅ 0 💤 0 ❌

Results for commit bcfe688.

if (!tmpdir) {
tmpdir = (TDirectoryFile*)mkdir(workname.Data(),title);
// We give all intermediate directories a default title, as `title` is only given to the innermost dir.
tmpdir = (TDirectoryFile *)mkdir(workname.Data(), workname.Data());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we rather use the empty string for the title of intermediate directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps; the only reason I used the name as the title is because that's what the function does in the normal case when an empty title is passed (see line https://github.com/root-project/root/pull/20531/files#diff-56ce80e060312dead2b5c7965a71f7ddee4211abf448bee96240b3c908833e7eR1275).
But an empty title makes more sense to me as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but given the line linked above, even if I pass "" the effective title will be workname.Data(), so if we wanted actually empty titles we would have to change that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants