This commit is contained in:
Your Name
2025-05-03 11:15:12 +12:00
parent a658ba1de6
commit 3c5fc11065
8 changed files with 82 additions and 18 deletions

View File

@@ -22,9 +22,10 @@ uint64_t get_hash_from_tgz(const std::string &file_path)
std::ifstream file(file_path, std::ios::binary);
if (!file) return 0;
char buffer[2];
file.read(buffer, 2);
if (buffer[0] != 0x1F || buffer[1] != 0x8B) return 0;
int result = system("gunzip -t file.gz");
if (result != 0) { // not a gzip file.
return 0;
}
// gunzip the file to a new temporary directory
TempDirectory temp_dir_manager("tgz_unpack_"); // Creates dir and schedules cleanup
@@ -32,9 +33,8 @@ uint64_t get_hash_from_tgz(const std::string &file_path)
// unpack the file on disk
std::string command = "tar -zxzf " + file_path + " -C " + temp_dir;
int result = system(command.c_str()); // Basic tar extraction - requires 'tar' command
result = system(command.c_str()); // Basic tar extraction - requires 'tar' command
if (result != 0) {
std::cerr << "Error unpacking tgz file: " << file_path << std::endl;
return 0;
}