MCPcopy Create free account
hub / github.com/Kitware/CMake / get

Method get

Source/cmFilePathChecksum.cxx:47–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47std::string cmFilePathChecksum::get(std::string const& filePath) const
48{
49 std::string relPath;
50 std::string relSeed;
51 {
52 std::string const fileReal = cmSystemTools::GetRealPath(filePath);
53 std::string parentDir;
54 // Find closest project parent directory
55 for (auto const& pDir : this->parentDirs) {
56 if (!pDir.first.empty() &&
57 cmsys::SystemTools::IsSubDirectory(fileReal, pDir.first)) {
58 parentDir = pDir.first;
59 relSeed = pDir.second;
60 break;
61 }
62 }
63 // Use file system root as fallback parent directory
64 if (parentDir.empty()) {
65 relSeed = "FileSystemRoot";
66 cmsys::SystemTools::SplitPathRootComponent(fileReal, &parentDir);
67 }
68 // Calculate relative path from project parent directory
69 relPath = cmsys::SystemTools::RelativePath(
70 parentDir, cmsys::SystemTools::GetParentDirectory(fileReal));
71 }
72
73 // Calculate the file ( seed + relative path ) binary checksum
74 std::vector<unsigned char> hashBytes =
75 cmCryptoHash(cmCryptoHash::AlgoSHA256).ByteHashString(relSeed + relPath);
76
77 // Convert binary checksum to string
78 return cmBase32Encoder().encodeString(hashBytes.data(), hashBytes.size(),
79 false);
80}
81
82std::string cmFilePathChecksum::getPart(std::string const& filePath,
83 size_t length) const

Callers 1

getPartMethod · 0.95

Calls 8

GetRealPathFunction · 0.85
cmBase32EncoderClass · 0.85
ByteHashStringMethod · 0.80
encodeStringMethod · 0.80
cmCryptoHashClass · 0.70
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected