FWCore
Utilities
src
resolveSymbolicLinks.cc
Go to the documentation of this file.
1
#include "
FWCore/Utilities/interface/resolveSymbolicLinks.h
"
2
#include "
FWCore/Utilities/interface/Parse.h
"
3
4
#include <filesystem>
5
#include <vector>
6
7
namespace
edm
{
8
9
namespace
{
10
namespace
bf = std::filesystem;
11
bool
resolveOneSymbolicLink(
std::string
&
fullPath
) {
12
if
(
fullPath
.empty())
13
return
false
;
14
if
(
fullPath
[0] !=
'/'
)
15
return
false
;
16
std::string
pathToResolve;
17
std::vector<std::string> pathElements =
edm::tokenize
(
fullPath
,
"/"
);
18
for
(
auto
const
&
path
: pathElements) {
19
if
(!
path
.empty()) {
20
pathToResolve +=
"/"
;
21
pathToResolve +=
path
;
22
bf::path
symLinkPath(pathToResolve);
23
if
(bf::is_symlink(bf::symlink_status(symLinkPath))) {
24
bf::path
resolved = bf::read_symlink(symLinkPath);
25
// This check is needed because in weird filesystems
26
// (e.g. AFS), the resolved link may not be accessible.
27
if
(!bf::exists(resolved)) {
28
continue
;
29
}
30
std::string
resolvedPath = resolved.string();
31
auto
begin =
fullPath
.begin();
32
auto
end
= begin + pathToResolve.size();
33
// resolvedPath may or may not contain the leading "/".
34
if
(resolvedPath[0] ==
'/'
) {
35
fullPath
.replace(begin,
end
, resolvedPath);
36
}
else
{
37
fullPath
.replace(begin + 1,
end
, resolvedPath);
38
}
39
return
true
;
40
}
41
}
42
}
43
return
false
;
44
}
45
}
// namespace
46
47
// Resolves symlinks recursively from anywhere in fullPath.
48
void
resolveSymbolicLinks
(
std::string
&
fullPath
) {
49
bool
found
= resolveOneSymbolicLink(
fullPath
);
50
if
(
found
) {
51
resolveSymbolicLinks
(
fullPath
);
52
}
53
}
54
}
// namespace edm
contentValuesFiles.fullPath
fullPath
Definition:
contentValuesFiles.py:64
resolveSymbolicLinks.h
edm
HLT enums.
Definition:
AlignableModifier.h:19
newFWLiteAna.found
found
Definition:
newFWLiteAna.py:118
edm::tokenize
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition:
Parse.cc:52
Parse.h
mps_fire.end
end
Definition:
mps_fire.py:242
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::resolveSymbolicLinks
void resolveSymbolicLinks(std::string &fullPath)
Definition:
resolveSymbolicLinks.cc:48
castor_dqm_sourceclient_file_cfg.path
path
Definition:
castor_dqm_sourceclient_file_cfg.py:37
Generated for CMSSW Reference Manual by
1.8.16