CMS 3D CMS Logo

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