Skip to content

Commit 37bee09

Browse files
committed
[io] in TDirectoryFile::mkdir, only apply title to the innermost dir.
1 parent 4da088e commit 37bee09

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

io/io/src/TDirectoryFile.cxx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,9 @@ TFile *TDirectoryFile::OpenFile(const char *name, Option_t *option,const char *f
12581258
/// Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
12591259
///
12601260
/// @param name the name or hierarchy of the subdirectory ("a" or "a/b/c")
1261-
/// @param title the title
1261+
/// @param title the title of the directory. For hierarchies, this is only applied
1262+
/// to the innermost directory (so if `name == "a/b/c"` and `title == "my dir"`,
1263+
/// only `c` will have the title `"my dir"`).
12621264
/// @param returnExistingDirectory if key-name is already existing, the returned
12631265
/// value points to preexisting sub-directory if true and to `nullptr` if false.
12641266
/// @return a pointer to the created sub-directory, not to the top sub-directory
@@ -1284,10 +1286,11 @@ TDirectory *TDirectoryFile::mkdir(const char *name, const char *title, Bool_t re
12841286
TDirectoryFile *tmpdir = nullptr;
12851287
GetObject(workname.Data(), tmpdir);
12861288
if (!tmpdir) {
1287-
tmpdir = (TDirectoryFile*)mkdir(workname.Data(),title);
1289+
// We give all intermediate directories a default title, as `title` is only given to the innermost dir.
1290+
tmpdir = (TDirectoryFile *)mkdir(workname.Data(), workname.Data());
12881291
if (!tmpdir) return nullptr;
12891292
}
1290-
return tmpdir->mkdir(slash + 1, "", returnExistingDirectory);
1293+
return tmpdir->mkdir(slash + 1, title, returnExistingDirectory);
12911294
}
12921295

12931296
TDirectory::TContext ctxt(this);

io/io/test/TFileTests.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,23 @@ TEST(TDirectoryFile, SeekParent)
285285
TEST(TDirectoryFile, RecursiveMkdir)
286286
{
287287
TMemFile f("mkdirtest.root", "RECREATE");
288-
auto dir1 = f.mkdir("a/b/c");
288+
auto dir1 = f.mkdir("a/b/c", "my dir");
289289
EXPECT_NE(dir1, nullptr);
290290
{
291291
ROOT::TestSupport::CheckDiagsRAII diags;
292292
diags.requiredDiag(kError, "TDirectoryFile::mkdir","An object with name c exists already");
293293
auto dir2 = f.mkdir("a/b/c", "", /* returnExisting = */ false);
294294
EXPECT_EQ(dir2, nullptr);
295295
}
296-
auto dir3 = f.mkdir("a/b/c", "", /* returnExisting = */ true);
296+
auto dir3 = f.mkdir("a/b/c", "foobar", /* returnExisting = */ true);
297297
EXPECT_EQ(dir3, dir1);
298+
EXPECT_STREQ(dir3->GetTitle(), "my dir");
299+
auto dirB = dir3->GetMotherDir();
300+
ASSERT_NE(dirB, nullptr);
301+
EXPECT_STREQ(dirB->GetTitle(), "b");
302+
auto dirA = dirB->GetMotherDir();
303+
ASSERT_NE(dirA, nullptr);
304+
EXPECT_STREQ(dirA->GetTitle(), "a");
298305
}
299306

300307
// https://its.cern.ch/jira/browse/ROOT-10581

0 commit comments

Comments
 (0)