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 02312f94 authored by rswindell's avatar rswindell

backup() now renames/copies filename.ext to filename.#.ext rather than

filename.ext.# (making the backup files easier to sort, copy, etc).
backup() now returns BOOL instead of void.
Now exporting fcopy() (for use in js_global.c).
parent de5227b3
......@@ -821,8 +821,10 @@ extern "C" {
DLLEXPORT BOOL DLLCALL write_file_cfg(scfg_t* cfg, int backup_level);
DLLEXPORT BOOL DLLCALL write_chat_cfg(scfg_t* cfg, int backup_level);
DLLEXPORT BOOL DLLCALL write_xtrn_cfg(scfg_t* cfg, int backup_level);
DLLEXPORT void DLLCALL backup(char *org, int backup_level, BOOL ren);
DLLEXPORT BOOL DLLCALL fcopy(char* src, char* dest);
DLLEXPORT BOOL DLLCALL backup(char *org, int backup_level, BOOL ren);
DLLEXPORT void DLLCALL refresh_cfg(scfg_t* cfg);
/* scfglib1.c */
DLLEXPORT char * DLLCALL prep_dir(char* base, char* dir, size_t buflen);
......
......@@ -78,7 +78,7 @@ BOOL DLLCALL save_cfg(scfg_t* cfg, int backup_level)
return(TRUE);
}
static BOOL fcopy(char* src, char* dest)
BOOL DLLCALL fcopy(char* src, char* dest)
{
int ch;
ulong count=0;
......@@ -109,26 +109,39 @@ static BOOL fcopy(char* src, char* dest)
/****************************************************************************/
/****************************************************************************/
void DLLCALL backup(char *fname, int backup_level, BOOL ren)
BOOL DLLCALL backup(char *fname, int backup_level, BOOL ren)
{
char oldname[MAX_PATH+1];
char newname[MAX_PATH+1];
int i;
char oldname[MAX_PATH+1];
char newname[MAX_PATH+1];
char* ext;
int i;
int len;
if((ext=strrchr(fname,'.'))==NULL)
ext="";
len=strlen(fname)-strlen(ext);
for(i=backup_level;i;i--) {
sprintf(newname,"%s.%d",fname,i-1);
sprintf(newname,"%.*s.%d%s",len,fname,i-1,ext);
if(i==backup_level)
remove(newname);
if(remove(newname)!=0)
return(FALSE);
if(i==1) {
if(ren == TRUE)
rename(fname,newname);
if(rename(fname,newname)!=0)
return(FALSE);
else
fcopy(fname,newname);
if(!fcopy(fname,newname)
return(FALSE);
continue;
}
sprintf(oldname,"%s.%d",fname,i-2);
rename(oldname,newname);
sprintf(oldname,"%.*s.%d%s",len,fname,i-2,ext);
if(rename(oldname,newname)!=0)
return(FALSE);
}
return(TRUE);
}
/****************************************************************************/
......
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