| 84 | } |
| 85 | |
| 86 | [[nodiscard]] inline Result downloadFileHash(StringView remoteURL, StringView localFile, Hashing::Type hashType, |
| 87 | StringView expectedHash) |
| 88 | { |
| 89 | FileSystem fs; |
| 90 | SC_TRY(fs.init(".")); |
| 91 | if (not fs.existsAndIsFile(localFile) or not checkFileHash(localFile, hashType, expectedHash)) |
| 92 | { |
| 93 | Process process; |
| 94 | String output; |
| 95 | Result res = process.exec({"curl", "-L", "-o", localFile, remoteURL}, output); |
| 96 | if (res) |
| 97 | { |
| 98 | SC_TRY_MSG(process.getExitStatus() == 0, "Cannot download file"); |
| 99 | } |
| 100 | Process process2; |
| 101 | if (not res) |
| 102 | { |
| 103 | res = process2.exec({"wget", "-O", localFile, remoteURL}, output); |
| 104 | if (res) |
| 105 | { |
| 106 | SC_TRY_MSG(process2.getExitStatus() == 0, "Cannot download file"); |
| 107 | } |
| 108 | } |
| 109 | if (not res) |
| 110 | { |
| 111 | return Result::Error("Cannot find neither curl nor wget"); |
| 112 | } |
| 113 | SC_TRY(checkFileHash(localFile, hashType, expectedHash)); |
| 114 | } |
| 115 | return Result(true); |
| 116 | } |
| 117 | |
| 118 | [[nodiscard]] inline Result readFileIntoString(StringSpan path, String& output) |
| 119 | { |
no test coverage detected