diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-07-04 20:21:45 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:58 +0200 |
commit | f1c219b6322427fd2d5d97df17fe684fbfe45afa (patch) | |
tree | 379da26a9a06144cbe054dd21a465a39f3f17e9c /src/GlobalLib.cpp | |
parent | 444b5725b125e5154a571a1542cbb5a7ca58e29b (diff) |
Return a string for a getFileData
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; } |