| 45 | } |
| 46 | |
| 47 | std::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 | |
| 82 | std::string cmFilePathChecksum::getPart(std::string const& filePath, |
| 83 | size_t length) const |
no test coverage detected