MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / downloadFileHash

Function downloadFileHash

Tools/SC-package.h:86–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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{

Callers 1

packageInstallFunction · 0.85

Calls 5

checkFileHashFunction · 0.85
existsAndIsFileMethod · 0.80
ErrorEnum · 0.50
ResultClass · 0.50
initMethod · 0.45

Tested by

no test coverage detected