Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 3cb82926 authored by Rob Swindell's avatar Rob Swindell 💬

Sort stored file (archive) contents, for later comparison purposes

Some archives contain exactly the same files as others, but in a different order. Believe it or not.
parent 0d9111a5
Pipeline #2110 passed with stage
in 7 minutes and 52 seconds
...@@ -639,7 +639,7 @@ bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, client_t* ...@@ -639,7 +639,7 @@ bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, client_t*
if(f->from_ip == NULL) if(f->from_ip == NULL)
file_client_hfields(f, client); file_client_hfields(f, client);
str_list_t list = list_archive_contents(fpath, /* pattern: */NULL str_list_t list = list_archive_contents(fpath, /* pattern: */NULL
,(cfg->dir[dirnum]->misc & DIR_NOHASH) == 0, /* error: */NULL, /* size: */0); ,(cfg->dir[dirnum]->misc & DIR_NOHASH) == 0, /* sort: */TRUE, /* error: */NULL, /* size: */0);
int result = smb_addfile_withlist(&smb, f, SMB_SELFPACK, extdesc, list, fpath); int result = smb_addfile_withlist(&smb, f, SMB_SELFPACK, extdesc, list, fpath);
smb_close(&smb); smb_close(&smb);
strListFree(&list); strListFree(&list);
...@@ -703,7 +703,7 @@ int archive_type(const char* archive, char* str, size_t size) ...@@ -703,7 +703,7 @@ int archive_type(const char* archive, char* str, size_t size)
return result; return result;
} }
str_list_t list_archive_contents(const char* filename, const char* pattern, bool hash, char* error, size_t maxerrlen) str_list_t list_archive_contents(const char* filename, const char* pattern, bool hash, bool sort, char* error, size_t maxerrlen)
{ {
int result; int result;
struct archive *ar; struct archive *ar;
...@@ -802,6 +802,8 @@ str_list_t list_archive_contents(const char* filename, const char* pattern, bool ...@@ -802,6 +802,8 @@ str_list_t list_archive_contents(const char* filename, const char* pattern, bool
} }
} }
archive_read_free(ar); archive_read_free(ar);
if(sort)
iniSortSections(&list, /* sort_keys: */TRUE);
return list; return list;
} }
......
...@@ -67,7 +67,7 @@ DLLEXPORT int file_sauce_hfields(file_t*, struct sauce_charinfo*); ...@@ -67,7 +67,7 @@ DLLEXPORT int file_sauce_hfields(file_t*, struct sauce_charinfo*);
DLLEXPORT str_list_t directory(const char* path); DLLEXPORT str_list_t directory(const char* path);
DLLEXPORT long create_archive(const char* archive, const char* format DLLEXPORT 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);
DLLEXPORT str_list_t list_archive_contents(const char* archive, const char* pattern, bool hash, char* error, size_t maxerrlen); DLLEXPORT str_list_t list_archive_contents(const char* archive, const char* pattern, bool hash, bool sort, char* error, size_t maxerrlen);
DLLEXPORT char* cmdstr(scfg_t*, user_t*, const char* instr, const char* fpath, const char* fspec, char* cmd, size_t); DLLEXPORT char* cmdstr(scfg_t*, user_t*, const char* instr, const char* fpath, const char* fspec, char* cmd, size_t);
DLLEXPORT long extract_files_from_archive(const char* archive, const char* outdir, const char* allowed_filename_chars DLLEXPORT long extract_files_from_archive(const char* archive, const char* outdir, const char* allowed_filename_chars
,bool with_path, long max_files, str_list_t file_list, char* error, size_t); ,bool with_path, long max_files, str_list_t file_list, char* error, size_t);
......
...@@ -1237,7 +1237,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1237,7 +1237,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
if(file.from_ip == NULL) if(file.from_ip == NULL)
file_client_hfields(&file, client); file_client_hfields(&file, client);
str_list_t list = list_archive_contents(fpath, /* pattern: */NULL str_list_t list = list_archive_contents(fpath, /* pattern: */NULL
,(scfg->dir[file.dir]->misc & DIR_NOHASH) == 0, /* error: */NULL, /* size: */0); ,(scfg->dir[file.dir]->misc & DIR_NOHASH) == 0, /* sort: */TRUE, /* error: */NULL, /* size: */0);
p->smb_result = smb_addfile_withlist(&p->smb, &file, SMB_SELFPACK, extdesc, list, fpath); p->smb_result = smb_addfile_withlist(&p->smb, &file, SMB_SELFPACK, extdesc, list, fpath);
strListFree(&list); strListFree(&list);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(p->smb_result == SMB_SUCCESS)); JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(p->smb_result == SMB_SUCCESS));
...@@ -1329,7 +1329,7 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1329,7 +1329,7 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist)
if((p->smb_result = smb_removefile(&p->smb, &file)) == SMB_SUCCESS) { if((p->smb_result = smb_removefile(&p->smb, &file)) == SMB_SUCCESS) {
str_list_t list = list_archive_contents(newfname, /* pattern: */NULL str_list_t list = list_archive_contents(newfname, /* pattern: */NULL
,file.dir < scfg->total_dirs && (scfg->dir[file.dir]->misc & DIR_NOHASH) == 0 ,file.dir < scfg->total_dirs && (scfg->dir[file.dir]->misc & DIR_NOHASH) == 0
,/* error: */NULL, /* size: */0); ,/* sort: */TRUE, /* error: */NULL, /* size: */0);
p->smb_result = smb_addfile_withlist(&p->smb, &file, SMB_SELFPACK, extdesc, list, newfname); p->smb_result = smb_addfile_withlist(&p->smb, &file, SMB_SELFPACK, extdesc, list, newfname);
strListFree(&list); strListFree(&list);
} }
......
...@@ -661,7 +661,7 @@ bool upgrade_file_bases(bool hash) ...@@ -661,7 +661,7 @@ bool upgrade_file_bases(bool hash)
body = extdesc; body = extdesc;
} }
str_list_t list = list_archive_contents(fpath, /* pattern: */NULL str_list_t list = list_archive_contents(fpath, /* pattern: */NULL
,(scfg.dir[i]->misc & DIR_NOHASH) == 0, /* error: */NULL, /* size: */0); ,(scfg.dir[i]->misc & DIR_NOHASH) == 0, /* sort: */TRUE, /* error: */NULL, /* size: */0);
result = smb_addfile_withlist(&smb, &file, SMB_FASTALLOC, body, list, fpath); result = smb_addfile_withlist(&smb, &file, SMB_FASTALLOC, body, list, fpath);
strListFree(&list); strListFree(&list);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment