From bca6bb2d6e00188c516c91d38ff8a67d0544cf22 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 4 Jul 2020 18:50:50 +0200 Subject: Add check that the package in cache is not corrupt from a previous download+extract that might have stopped mid-action --- src/GlobalLib.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index 586ec2d..df66727 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -40,13 +40,30 @@ namespace sibs } case FileType::DIRECTORY: { - return Result::Ok(true); + break; } default: { return Result::Err("Unexpected error!"); } } + + // We also need to verify that the archive was removed after extracting it, otherwise the extracted + // package could be corrupted. The archive is only removed after extracting is done. + // TODO: Find a way to verify that the git repo was cloned fully without interruption, or add .finished files + // for every download + + Result libPathResult = getHomeDir(); + if (!libPathResult) + return Result::Err(libPathResult); + + FileString libArchivedFilePath = libPathResult.unwrap(); + libArchivedFilePath += TINYDIR_STRING("/.cache/sibs/archive/"); + libArchivedFilePath += toFileString(name); + if(getFileType(libArchivedFilePath.c_str()) != FileType::FILE_NOT_FOUND) + return Result::Err("A previous download of package is corrupt, attempting to redownload..."); + + return Result::Ok(true); } Result GlobalLib::getLibs(const std::vector &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback) -- cgit v1.2.3