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

Add/use smb_removefile_by_name()

This fixes a filebase corruption issue that could be triggered by using
FileBase.update() to rename a file while also changing the file's auxdata or
extended description: you can't remove a file header that has the new filename
(in the file_t.name field), cause it doesn't exist yet. So we needed an SMBLIB
API function to pass the (original) filename instead. Much like the filedat.c
removefile() function, but without the SMB opening/closing feature.
parent 397d6ebe
No related branches found
No related tags found
No related merge requests found
Pipeline #6613 passed
......@@ -562,12 +562,7 @@ bool removefile(scfg_t* cfg, int dirnum, const char* filename)
if(smb_open_dir(cfg, &smb, dirnum) != SMB_SUCCESS)
return false;
int result;
file_t file;
if((result = smb_loadfile(&smb, filename, &file, file_detail_normal)) == SMB_SUCCESS) {
result = smb_removefile(&smb, &file);
smb_freefilemem(&file);
}
int result = smb_removefile_by_name(&smb, filename);
smb_close(&smb);
return result == SMB_SUCCESS;
}
......
......@@ -1335,7 +1335,7 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist)
if(p->smb_result != SMB_SUCCESS)
JS_ReportError(cx, "%d writing '%s'", p->smb_result, file.name);
else {
if((p->smb_result = smb_removefile(&p->smb, &file)) == SMB_SUCCESS) {
if((p->smb_result = smb_removefile_by_name(&p->smb, filename)) == SMB_SUCCESS) {
if(readd_always)
file.hdr.when_imported.time = 0; // we want the file to appear as "new"
p->smb_result = smb_addfile(&p->smb, &file, SMB_SELFPACK, extdesc, auxdata, newfname);
......
......@@ -472,6 +472,19 @@ int smb_removefile(smb_t* smb, smbfile_t* file)
return result;
}
/****************************************************************************/
/****************************************************************************/
int smb_removefile_by_name(smb_t* smb, const char* filename)
{
int result;
smbfile_t file;
if((result = smb_loadfile(smb, filename, &file, file_detail_normal)) != SMB_SUCCESS)
return result;
result = smb_removefile(smb, &file);
smb_freefilemem(&file);
return result;
}
uint64_t smb_getfilesize(idxrec_t* idx)
{
return ((uint64_t)idx->size) | (((uint64_t)idx->size_ext) << 32);
......
......@@ -295,6 +295,7 @@ SMBEXPORT int smb_findfile(smb_t*, const char* filename, smbfile_t*);
SMBEXPORT int smb_loadfile(smb_t*, const char* filename, smbfile_t*, enum file_detail);
SMBEXPORT void smb_freefilemem(smbfile_t*);
SMBEXPORT int smb_removefile(smb_t*, smbfile_t*);
SMBEXPORT int smb_removefile_by_name(smb_t*, const char* filename);
SMBEXPORT char* smb_fileidxname(const char* filename, char* buf, size_t);
SMBEXPORT uint64_t smb_getfilesize(idxrec_t*);
SMBEXPORT int smb_setfilesize(idxrec_t*, uint64_t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment