Skip to content
Snippets Groups Projects
Commit 77e2d88e authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

create_archive() will skip directories in supplied file_list

The file_list[] parameter was expected to contain only files, but the directory() function (used to create that file_list[]) returns a list of all directory entries, including sub-directories. I could (and maybe will) add an option to directory() to only include files or dirs, but this seemed the more direct fix for the problem reported by DesotoFireflite (VALHALLA):

TickIT's nodelist_handler.js appears to be creating and leaving behind a sub-directory of the temp directory, triggering this error:
 1/23  11:36:56a  QNET libarchive error -1 (13 opening c:\SBBS\temp\event\nodelist_handler/) creating c:\SBBS\data\VERT.REP 

Why isn't the temp directory fully cleaned up after/between events? That's another thing to look into.
parent 2ac39df7
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2617 passed
...@@ -750,6 +750,7 @@ str_list_t directory(const char* path) ...@@ -750,6 +750,7 @@ str_list_t directory(const char* path)
} }
const char* supported_archive_formats[] = { "zip", "7z", "tgz", NULL }; const char* supported_archive_formats[] = { "zip", "7z", "tgz", NULL };
// Returns total number of successfully archived files
// Returns negative on error // Returns negative on error
long create_archive(const char* archive, const char* format long create_archive(const char* archive, const char* format
,bool with_path, str_list_t file_list, char* error, size_t maxerrlen) ,bool with_path, str_list_t file_list, char* error, size_t maxerrlen)
...@@ -785,10 +786,13 @@ long create_archive(const char* archive, const char* format ...@@ -785,10 +786,13 @@ long create_archive(const char* archive, const char* format
return result; return result;
} }
ulong file_count = 0; ulong file_count = 0;
ulong archived = 0;
for(;file_list[file_count] != NULL; file_count++) { for(;file_list[file_count] != NULL; file_count++) {
struct archive_entry* entry; struct archive_entry* entry;
struct stat st; struct stat st;
const char* filename = file_list[file_count]; const char* filename = file_list[file_count];
if(isdir(filename))
continue;
FILE* fp = fopen(filename, "rb"); FILE* fp = fopen(filename, "rb");
if(fp == NULL) { if(fp == NULL) {
safe_snprintf(error, maxerrlen, "%d opening %s", errno, filename); safe_snprintf(error, maxerrlen, "%d opening %s", errno, filename);
...@@ -827,12 +831,13 @@ long create_archive(const char* archive, const char* format ...@@ -827,12 +831,13 @@ long create_archive(const char* archive, const char* format
archive_entry_free(entry); archive_entry_free(entry);
if(result != ARCHIVE_OK) if(result != ARCHIVE_OK)
break; break;
archived++;
} }
archive_write_close(ar); archive_write_close(ar);
archive_write_free(ar); archive_write_free(ar);
if(file_list[file_count] != NULL) if(file_list[file_count] != NULL)
return result < 0 ? result : -1; return result < 0 ? result : -1;
return file_count; return archived;
} }
long extract_files_from_archive(const char* archive, const char* outdir, const char* allowed_filename_chars long extract_files_from_archive(const char* archive, const char* outdir, const char* allowed_filename_chars
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment