diff options
Diffstat (limited to 'src/GlobalLib.cpp')
-rw-r--r-- | src/GlobalLib.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index df66727..8346a83 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -60,7 +60,22 @@ namespace sibs FileString libArchivedFilePath = libPathResult.unwrap(); libArchivedFilePath += TINYDIR_STRING("/.cache/sibs/archive/"); libArchivedFilePath += toFileString(name); - if(getFileType(libArchivedFilePath.c_str()) != FileType::FILE_NOT_FOUND) + FileType archive_path_file_type = getFileType(libArchivedFilePath.c_str()); + + if(archive_path_file_type == FileType::FILE_NOT_FOUND) + return Result<bool>::Ok(true); + + if(archive_path_file_type != FileType::DIRECTORY) + return Result<bool>::Err("A previous download of package is corrupt, attempting to redownload..."); + + bool isEmpty = true; + walkDir(libArchivedFilePath.c_str(), [&isEmpty](tinydir_file *file) + { + isEmpty = false; + return false; + }); + + if(!isEmpty) return Result<bool>::Err("A previous download of package is corrupt, attempting to redownload..."); return Result<bool>::Ok(true); @@ -314,6 +329,7 @@ namespace sibs if(!createArchiveDirResult) return createArchiveDirResult; + FileString libArchivedDir = libArchivedFilePath; libArchivedFilePath += TINYDIR_STRING("/"); libArchivedFilePath += toFileString(package.version.toString()); Result<bool> downloadResult = curl::downloadFile(package.urls[0].c_str(), libArchivedFilePath.c_str()); @@ -329,8 +345,10 @@ namespace sibs // We have extracted the archive, we dont need to cache it. If remove fails, it doesn't really matter, user can remove it himself #if OS_FAMILY == OS_FAMILY_POSIX remove(libArchivedFilePath.c_str()); + remove(libArchivedDir.c_str()); #else _wremove(libArchivedFilePath.c_str()); + _wremove(libArchivedDir.c_str()); #endif return archiveExtractResult; } |