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
1 change: 1 addition & 0 deletions io/io/inc/ROOT/RFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public:
/// `basePath` (defaulting to include the content of all subdirectories).
/// By default, keys referring to directories are not returned: only those referring to leaf objects are.
/// If `basePath` is the path of a leaf object, only `basePath` itself will be returned.
/// If `basePath` is the path of a directory, it won't appear in the listing.
/// `flags` is a bitmask specifying the listing mode.
/// If `(flags & kListObjects) != 0`, the listing will include keys of non-directory objects (default);
/// If `(flags & kListDirs) != 0`, the listing will include keys of directory objects;
Expand Down
4 changes: 4 additions & 0 deletions io/io/src/RFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ void ROOT::Experimental::RFileKeyIterable::RIterator::Advance()
assert(!fIterStack.empty());
const std::size_t nesting = fIterStack.size() - 1;

// Skip key if it's the root dir itself
if (isDir && fullPath == fPattern)
continue;

// Skip key if it's not a child of root dir
if (!ROOT::StartsWith(fullPath, fPattern))
continue;
Expand Down
12 changes: 6 additions & 6 deletions io/io/test/rfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ TEST(RFile, IterateKeysOnlyDirs)
{
auto file = RFile::Open(fileGuard.GetPath());
EXPECT_EQ(JoinKeyNames(file->ListKeys("", RFile::kListDirs | RFile::kListRecursive)), "a, a/b, e, e/c");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a", RFile::kListDirs | RFile::kListRecursive)), "a, a/b");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a/b", RFile::kListDirs | RFile::kListRecursive)), "a/b");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a", RFile::kListDirs | RFile::kListRecursive)), "a/b");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a/b", RFile::kListDirs | RFile::kListRecursive)), "");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a/b/c", RFile::kListDirs | RFile::kListRecursive)), "");
EXPECT_EQ(JoinKeyNames(file->ListKeys("e", RFile::kListDirs | RFile::kListRecursive)), "e, e/c");
EXPECT_EQ(JoinKeyNames(file->ListKeys("e", RFile::kListDirs | RFile::kListRecursive)), "e/c");
}
}

Expand All @@ -506,10 +506,10 @@ TEST(RFile, IterateKeysOnlyDirsNonRecursive)
{
auto file = RFile::Open(fileGuard.GetPath());
EXPECT_EQ(JoinKeyNames(file->ListKeys("", RFile::kListDirs)), "a, e");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a", RFile::kListDirs)), "a, a/b");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a/b", RFile::kListDirs)), "a/b");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a", RFile::kListDirs)), "a/b");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a/b", RFile::kListDirs)), "");
EXPECT_EQ(JoinKeyNames(file->ListKeys("a/b/c", RFile::kListDirs)), "");
EXPECT_EQ(JoinKeyNames(file->ListKeys("e", RFile::kListDirs)), "e, e/c");
EXPECT_EQ(JoinKeyNames(file->ListKeys("e", RFile::kListDirs)), "e/c");
}
}

Expand Down
4 changes: 4 additions & 0 deletions io/io/test/rfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
[key.GetPath() for key in rfile.ListKeys("", listDirs=True, listObjects=False, listRecursive=False)],
["foo"],
)
self.assertEqual(
[key.GetPath() for key in rfile.ListKeys("foo", listDirs=True, listObjects=False, listRecursive=False)],
["foo/bar"],
)
self.assertEqual(
[key.GetPath() for key in rfile.ListKeys("", listDirs=True, listRecursive=False)], ["hist", "foo"]
)
Expand Down Expand Up @@ -149,7 +153,7 @@

fileName = "test_rfile_gettree_py.root"
try:
with ROOT.TFile.Open(fileName, "RECREATE") as file:

Check failure on line 156 in io/io/test/rfile.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F841)

io/io/test/rfile.py:156:59: F841 Local variable `file` is assigned to but never used help: Remove assignment to unused variable `file`
tree = ROOT.TTree("tree", "tree")
x = array("i", [0])
tree.Branch("myColumn", x, "myColumn/I")
Expand Down
Loading