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

delfiles() now takes a 3rd argument: keep, which is a number of files to retain

(not delete) from the end of the sorted list of files (normally, 0).
parent ee3c2d99
......@@ -510,7 +510,7 @@ void msgs_cfg()
SAFEPRINTF(tmp, "%ssubs/", cfg.data_dir);
else
SAFECOPY(tmp, cfg.sub[j]->data_dir);
delfiles(tmp, str);
delfiles(tmp, str, /* keep: */0);
}
}
}
......
......@@ -310,7 +310,7 @@ void sub_cfg(uint grpnum)
if(j==-1)
continue;
if(j==0)
delfiles(data_dir,str);
delfiles(data_dir,str, /* keep: */0);
}
}
if(msk == MSK_CUT)
......@@ -1458,7 +1458,7 @@ void sub_cfg(uint grpnum)
,cfg.grp[cfg.sub[i]->grp]->code_prefix
,cfg.sub[i]->code_suffix);
strlwr(str2);
delfiles(str,str2);
delfiles(str,str2, /* keep: */0);
}
if(cfg.sub[i]->misc&SUB_HYPER)
......
......@@ -327,7 +327,7 @@ void xfer_cfg()
sprintf(tmp, "%sdirs/", cfg.data_dir);
else
strcpy(tmp, cfg.dir[j]->data_dir);
delfiles(tmp, str);
delfiles(tmp, str, /* keep: */0);
}
}
}
......@@ -1105,7 +1105,7 @@ void dir_cfg(uint libnum)
if (j == -1)
continue;
if (j == 0)
delfiles(data_dir, str);
delfiles(data_dir, str, /* keep: */0);
}
}
if(msk == MSK_CUT)
......
......@@ -2489,15 +2489,15 @@ int DLLCALL newuserdat(scfg_t* cfg, user_t* user)
return(err);
SAFEPRINTF2(str,"%sfile/%04u.in",cfg->data_dir,user->number); /* delete any files */
delfiles(str,ALLFILES); /* waiting for user */
delfiles(str, ALLFILES, /* keep: */0); /* waiting for user */
rmdir(str);
SAFEPRINTF(tmp,"%04u.*",user->number);
SAFEPRINTF(str,"%sfile",cfg->data_dir);
delfiles(str,tmp);
delfiles(str,tmp, /* keep: */0);
SAFEPRINTF(str,"%suser",cfg->data_dir);
delfiles(str,tmp);
delfiles(str,tmp, /* keep: */0);
SAFEPRINTF2(str,"%suser/%04u",cfg->data_dir,user->number);
delfiles(str,ALLFILES);
delfiles(str,ALLFILES, /* keep: */0);
rmdir(str);
SAFEPRINTF2(str,"%suser/ptrs/%04u.ixb",cfg->data_dir,user->number); /* msg ptrs */
......
......@@ -747,14 +747,15 @@ int removecase(const char *path)
/****************************************************************************/
/* Deletes all files in dir 'path' that match file spec 'spec' */
/* Optionally, keep the last so many files (sorted by name) */
/* Returns number of files deleted or negative on error */
/****************************************************************************/
long DLLCALL delfiles(const char *inpath, const char *spec)
long DLLCALL delfiles(const char *inpath, const char *spec, size_t keep)
{
char *path;
char lastch;
size_t i;
long files = 0;
ulong files = 0;
long errors = 0;
glob_t g;
size_t inpath_len=strlen(inpath);
......@@ -773,7 +774,9 @@ long DLLCALL delfiles(const char *inpath, const char *spec)
strcat(path,spec);
glob(path,0,NULL,&g);
free(path);
for(i=0;i<g.gl_pathc;i++) {
if(keep >= g.gl_pathc)
return 0;
for(i = 0; i < g.gl_pathc && files < g.gl_pathc - keep; i++) {
if(isdir(g.gl_pathv[i]))
continue;
CHMOD(g.gl_pathv[i],S_IWRITE); /* In case it's been marked RDONLY */
......
......@@ -233,7 +233,7 @@ DLLEXPORT char* DLLCALL getdirname(const char* path);
DLLEXPORT long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only);
DLLEXPORT ulong DLLCALL getdisksize(const char* path, ulong unit);
DLLEXPORT ulong DLLCALL getfreediskspace(const char* path, ulong unit);
DLLEXPORT long DLLCALL delfiles(const char *inpath, const char *spec);
DLLEXPORT long DLLCALL delfiles(const char *inpath, const char *spec, size_t keep);
DLLEXPORT char* DLLCALL backslash(char* path);
DLLEXPORT BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path);
DLLEXPORT BOOL DLLCALL wildmatchi(const char *fname, const char *spec, BOOL path);
......
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