| 2393 | } |
| 2394 | |
| 2395 | int cmcmd::HashSumFile(std::vector<std::string> const& args, |
| 2396 | cmCryptoHash::Algo algo) |
| 2397 | { |
| 2398 | if (args.size() < 3) { |
| 2399 | return -1; |
| 2400 | } |
| 2401 | int retval = 0; |
| 2402 | |
| 2403 | for (auto const& filename : cmMakeRange(args).advance(2)) { |
| 2404 | if (filename == "-") { |
| 2405 | #ifdef _WIN32 |
| 2406 | _setmode(fileno(stdin), _O_BINARY); |
| 2407 | #endif |
| 2408 | cmCryptoHash hasher(algo); |
| 2409 | std::string value = hasher.HashStream(std::cin); |
| 2410 | if (value.empty()) { |
| 2411 | // To mimic "md5sum/shasum" behavior in a shell: |
| 2412 | std::cerr << filename << ": No such file or directory\n"; |
| 2413 | retval++; |
| 2414 | } else { |
| 2415 | std::cout << value << " " << filename << '\n'; |
| 2416 | } |
| 2417 | } else if (cmSystemTools::FileIsDirectory(filename)) { |
| 2418 | // Cannot compute sum of a directory |
| 2419 | std::cerr << "Error: " << filename << " is a directory\n"; |
| 2420 | retval++; |
| 2421 | } else { |
| 2422 | cmCryptoHash hasher(algo); |
| 2423 | std::string value = hasher.HashFile(filename); |
| 2424 | if (value.empty()) { |
| 2425 | // To mimic "md5sum/shasum" behavior in a shell: |
| 2426 | std::cerr << filename << ": No such file or directory\n"; |
| 2427 | retval++; |
| 2428 | } else { |
| 2429 | std::cout << value << " " << filename << '\n'; |
| 2430 | } |
| 2431 | } |
| 2432 | } |
| 2433 | return retval; |
| 2434 | } |
| 2435 | |
| 2436 | int cmcmd::SymlinkLibrary(std::vector<std::string> const& args) |
| 2437 | { |
nothing calls this directly
no test coverage detected