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
22 changes: 18 additions & 4 deletions main/src/hadd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,20 @@ static Int_t ParseFilterFile(const std::optional<std::string> &filterFileName,
return 0;
}

static bool FilesAreEquivalent(std::string_view source, std::string_view target)
{
const bool sourceIsLocal = source.find_first_of("://") == std::string_view::npos;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const bool sourceIsLocal = source.find_first_of("://") == std::string_view::npos;
const bool sourceHasProtocol = source.find_first_of("://") == std::string_view::npos;

See https://github.com/root-project/root/pull/20878/changes#r2694519784

const bool targetIsLocal = target.find_first_of("://") == std::string_view::npos;
if (sourceIsLocal != targetIsLocal)
return false;

// We cannot use std::filesystem functions for remote files.
Copy link
Member

@pcanal pcanal Jan 15, 2026

Choose a reason for hiding this comment

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

Suggested change
// We cannot use std::filesystem functions for remote files.
// We cannot use std::filesystem functions for remote files nor local files
// expressed with a protocol.

eg auto f = TFile::Open("file://t1.root", "RECREATE") creates a local file.

if (!sourceIsLocal)
return source == target;

return std::filesystem::exists(target) && std::filesystem::equivalent(source, target);
}

int main(int argc, char **argv)
{
InitLog("hadd", kDefaultHaddVerbosity);
Expand Down Expand Up @@ -718,7 +732,7 @@ int main(int argc, char **argv)
<< (argv[a] + 1) << std::endl;
if (!args.fSkipErrors)
return 1;
} else if (std::filesystem::exists(targetname) && std::filesystem::equivalent(line, targetname)) {
} else if (FilesAreEquivalent(line, targetname)) {
Err() << "file " << line << " cannot be both the target and an input!\n";
if (!args.fSkipErrors)
return 1;
Expand All @@ -729,12 +743,12 @@ int main(int argc, char **argv)
}
}
} else {
const std::string line = argv[a];
if (gSystem->AccessPathName(line.c_str(), kReadPermission) == kTRUE) {
const char *line = argv[a];
if (gSystem->AccessPathName(line, kReadPermission) == kTRUE) {
Err() << "could not validate argument \"" << line << "\" as input file " << std::endl;
if (!args.fSkipErrors)
return 1;
} else if (std::filesystem::exists(targetname) && std::filesystem::equivalent(line, targetname)) {
} else if (FilesAreEquivalent(line, targetname)) {
Err() << "file " << line << " cannot be both the target and an input!\n";
if (!args.fSkipErrors)
return 1;
Expand Down
14 changes: 14 additions & 0 deletions roottest/root/io/hadd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,22 @@ ROOTTEST_ADD_TEST(test_hadd_args_quieter
################################################################
configure_file(file1_20706.root . COPYONLY)
configure_file(file2_20706.root . COPYONLY)
configure_file(filelist_20872.txt . COPYONLY)

ROOTTEST_ADD_TEST(test_hadd_regr_20706
PRECMD ${CMAKE_COMMAND} -E rm -f merged_20706.root
COMMAND ${ROOT_hadd_CMD} -f merged_20706.root file1_20706.root file2_20706.root
)

if(davix AND NOT MSVC)
ROOTTEST_ADD_TEST(test_hadd_regr_20872
PRECMD ${CMAKE_COMMAND} -E rm -f merged_20872.root
COMMAND ${ROOT_hadd_CMD} -f merged_20872.root root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root
)

ROOTTEST_ADD_TEST(test_hadd_regr_20872_2
PRECMD ${CMAKE_COMMAND} -E rm -f merged_20872_2.root
COMMAND ${ROOT_hadd_CMD} -f root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root @filelist_20872.txt
PASSREGEX "root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root cannot be both the target and an input!"
)
endif()
2 changes: 2 additions & 0 deletions roottest/root/io/hadd/filelist_20872.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root
root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root
Loading