Skip to content

Commit

Permalink
[io] TFile::ls skips keys with slash in their name
Browse files Browse the repository at this point in the history
If one does:
TFile* aFile = new TFile("/tmp/tnamed.root", "RECREATE");
TNamed("TIME/CLK", "0x6").Write();
aFile->ls();

nothing is printed

Solution proposed by pcanal

Formatting

Co-authored-by: Philippe Canal <[email protected]>

apply pcanals suggestion

Co-authored-by: Philippe Canal <[email protected]>

check if reg is not null

missing check
  • Loading branch information
ferdymercury authored and pcanal committed Dec 20, 2023
1 parent 5560b67 commit 5815897
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions io/io/src/TDirectoryFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1179,17 +1179,20 @@ void TDirectoryFile::ls(Option_t *option) const
TString opt = opta.Strip(TString::kBoth);
Bool_t memobj = kTRUE;
Bool_t diskobj = kTRUE;
TString reg = "*";
TString reg;
if (opt.BeginsWith("-m")) {
diskobj = kFALSE;
if (opt.Length() > 2)
if (opt.Length() > 2) {
reg = opt(2,opt.Length());
}
} else if (opt.BeginsWith("-d")) {
memobj = kFALSE;
if (opt.Length() > 2)
if (opt.Length() > 2) {
reg = opt(2,opt.Length());
} else if (!opt.IsNull())
}
} else if (!opt.IsNull()) {
reg = opt;
}

TRegexp re(reg, kTRUE);

Expand All @@ -1198,7 +1201,8 @@ void TDirectoryFile::ls(Option_t *option) const
TIter nextobj(fList);
while ((obj = (TObject *) nextobj())) {
TString s = obj->GetName();
if (s.Index(re) == kNPOS) continue;
if (!reg.IsNull() && s.Index(re) == kNPOS)
continue;
obj->ls(option); //*-* Loop on all the objects in memory
}
}
Expand All @@ -1208,7 +1212,8 @@ void TDirectoryFile::ls(Option_t *option) const
for (TObjLink *lnk = fKeys->FirstLink(); lnk != nullptr; lnk = lnk->Next()) {
TKey *key = (TKey*)lnk->GetObject();
TString s = key->GetName();
if (s.Index(re) == kNPOS) continue;
if (!reg.IsNull() && s.Index(re) == kNPOS)
continue;
bool first = (lnk->Prev() == nullptr) || (s != lnk->Prev()->GetObject()->GetName());
bool hasbackup = (lnk->Next() != nullptr) && (s == lnk->Next()->GetObject()->GetName());
if (first)
Expand Down

0 comments on commit 5815897

Please sign in to comment.