mirror of https://gitlab.com/nakst/essence
More robust SHA256 checksum check (ignore asterisk in front of file name on Windows)
This commit is contained in:
parent
e09790dae7
commit
5864273e29
|
@ -2,6 +2,17 @@ str url #option;
|
|||
str directoryName #option;
|
||||
str checksum #option;
|
||||
|
||||
// Returns true if file matches given SHA 256 checksum
|
||||
// Note: using StringStartsWith and StringEndsWith to avoid mismatch due to asterisk in front of file name on MSYS2/Windows
|
||||
bool FileMatchesSHA256Checksum(str filename, str checksum) {
|
||||
str shasum = SystemShellEvaluate("shasum -a 256 %filename%");
|
||||
if StringStartsWith(shasum, checksum) && StringEndsWith(shasum, filename) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Get(str url, str directoryName, str checksum) {
|
||||
assert url != "";
|
||||
assert directoryName != "";
|
||||
|
@ -42,8 +53,10 @@ void Get(str url, str directoryName, str checksum) {
|
|||
}
|
||||
|
||||
if checksum != "" {
|
||||
if SystemShellEvaluate("shasum -a 256 %cachePath%") != "%checksum% %cachePath%\n" {
|
||||
if FileMatchesSHA256Checksum(cachePath, checksum) {
|
||||
LogError("Checksum mismatch for file '%cachePath%'.\n");
|
||||
SystemShellExecute("shasum -a 256 %cachePath%");
|
||||
Log("%checksum% is the expected checksum");
|
||||
PathDelete(cachePath);
|
||||
assert false;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,17 @@ str compilerPath #persist;
|
|||
int compilerIndex #persist;
|
||||
bool runningMakefiles #persist;
|
||||
|
||||
// Returns true if file matches given SHA 256 checksum
|
||||
// Note: using StringStartsWith and StringEndsWith to avoid mismatch due to asterisk in front of file name on MSYS2/Windows
|
||||
bool FileMatchesSHA256Checksum(str filename, str checksum) {
|
||||
str shasum = SystemShellEvaluate("shasum -a 256 %filename%");
|
||||
if StringStartsWith(shasum, checksum) && StringEndsWith(shasum, filename) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Environment setup
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
@ -45,8 +56,7 @@ void Setup(bool forAutomation) {
|
|||
assert false;
|
||||
}
|
||||
|
||||
if SystemShellEvaluate("shasum -a 256 util/test.txt")
|
||||
!= "2c5622dbbf2552e0e66424a302bde0918e09379afce47eef1a21ef0198990fed util/test.txt\n" {
|
||||
if FileMatchesSHA256Checksum("util/test.txt", "2c5622dbbf2552e0e66424a302bde0918e09379afce47eef1a21ef0198990fed") {
|
||||
Log(TextColorError() + "--------------------------------------------------------------------");
|
||||
Log(TextColorError() + " The source has been corrupted!! ");
|
||||
Log(TextColorError() + " Please check that you have disabled any automatic line-ending or ");
|
||||
|
|
Loading…
Reference in New Issue