Skip to content

Commit

Permalink
drop rmdirs() and use cli_rmdirs() instead
Browse files Browse the repository at this point in the history
git-svn: trunk@2842
  • Loading branch information
Tomasz Kojm committed Feb 22, 2007
1 parent c5107e7 commit 66ba178
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 95 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Thu Feb 22 17:16:54 CET 2007 (tk)
---------------------------------
* shared/misc.c: drop rmdirs() and use cli_rmdirs() instead

Thu Feb 22 16:51:33 CET 2007 (tk)
---------------------------------
* libclamav: new scan setting CL_SCAN_PDF
Expand Down
2 changes: 1 addition & 1 deletion clamscan/treewalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int clamav_rmdirs(const char *dir)
}
}
#endif
rmdirs(dir);
cli_rmdirs(dir);
exit(0);
break;
default:
Expand Down
12 changes: 6 additions & 6 deletions freshclam/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static int chdir_inc(const char *dbname)

if(cvd_unpack(dbfile, path) == -1) {
logg("!chdir_inc: Can't unpack %s into %s\n", dbfile, path);
rmdirs(path);
cli_rmdirs(path);
return -1;
}
}
Expand Down Expand Up @@ -822,7 +822,7 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
inc = 0;
if(stat(dbinc, &sb) != -1) {
logg("^Removing corrupted incremental directory %s\n", dbinc);
if(rmdirs(dbinc)) {
if(cli_rmdirs(dbinc)) {
logg("!Can't remove incremental directory\n");
return 53;
}
Expand Down Expand Up @@ -998,14 +998,14 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
if(ret) {
if(bacinc) {
logg("*Restoring incremental directory %s from backup\n", dbinc);
rmdirs(dbinc);
cli_rmdirs(dbinc);
rename(bacinc, dbinc);
free(bacinc);
}
return ret;
} else {
logg("*Removing incremental directory %s\n", dbinc);
rmdirs(dbinc);
cli_rmdirs(dbinc);
}

} else {
Expand All @@ -1014,7 +1014,7 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig

if(bacinc) {
logg("*Removing backup directory %s\n", bacinc);
rmdirs(bacinc);
cli_rmdirs(bacinc);
free(bacinc);
}
}
Expand All @@ -1026,7 +1026,7 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
}

if(nodb && inc)
rmdirs(dbinc);
cli_rmdirs(dbinc);

logg("%s updated (version: %d, sigs: %d, f-level: %d, builder: %s)\n", inc ? dbinc : dbfile, current->version, current->sigs, current->fl, current->builder);

Expand Down
62 changes: 1 addition & 61 deletions shared/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,66 +186,6 @@ int filecopy(const char *src, const char *dest)

}

int rmdirs(const char *dirname)
{
DIR *dd;
struct dirent *dent;
struct stat maind, statbuf;
char *fname;


if((dd = opendir(dirname)) != NULL) {
while(stat(dirname, &maind) != -1) {
if(!rmdir(dirname)) break;
if(errno != ENOTEMPTY && errno != EEXIST && errno != EBADF) {
closedir(dd);
return 0;
}

while((dent = readdir(dd))) {
#if (!defined(C_CYGWIN)) && (!defined(C_INTERIX)) && (!defined(C_WINDOWS))
if(dent->d_ino)
#endif
{
if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
fname = mcalloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
#ifdef C_WINDOWS
sprintf(fname, "%s\\%s", dirname, dent->d_name);
#else
sprintf(fname, "%s/%s", dirname, dent->d_name);
#endif

/* stat the file */
if(lstat(fname, &statbuf) != -1) {
if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) {
if(rmdir(fname) == -1) { /* can't be deleted */
if(errno == EACCES) {
closedir(dd);
free(fname);
return 1;
}
rmdirs(fname);
}
} else
unlink(fname);
}

free(fname);
}
}
}

rewinddir(dd);
}

} else {
return 1;
}

closedir(dd);
return 0;
}

int dircopy(const char *src, const char *dest)
{
DIR *dd;
Expand Down Expand Up @@ -279,7 +219,7 @@ int dircopy(const char *src, const char *dest)

if(filecopy(spath, dpath) == -1) {
/* mprintf("!dircopy: Can't copy %s to %s\n", spath, dpath); */
rmdirs(dest);
cli_rmdirs(dest);
closedir(dd);
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion shared/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ char *freshdbdir(void);
void print_version(void);
int filecopy(const char *src, const char *dest);
int isnumb(const char *str);
int rmdirs(const char *dirname);
int dircopy(const char *src, const char *dest);
int cvd_unpack(const char *cvd, const char *destdir);
void daemonize(void);
Expand Down
52 changes: 26 additions & 26 deletions sigtool/sigtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ static int build(struct optstruct *opt)
}
if(cvd_unpack(olddb, pt) == -1) {
mprintf("!build: Can't unpack CVD file %s\n", olddb);
rmdirs(pt);
cli_rmdirs(pt);
free(pt);
return -1;
}
Expand All @@ -879,15 +879,15 @@ static int build(struct optstruct *opt)
mprintf("!build: Can't create temporary directory %s\n", pt);
free(pt);
if(!inc)
rmdirs(olddb);
cli_rmdirs(olddb);
return -1;
}
if(cvd_unpack(opt_arg(opt, "build"), pt) == -1) {
mprintf("!build: Can't unpack CVD file %s\n", opt_arg(opt, "build"));
rmdirs(pt);
cli_rmdirs(pt);
free(pt);
if(!inc)
rmdirs(olddb);
cli_rmdirs(olddb);
return -1;
}

Expand All @@ -898,19 +898,19 @@ static int build(struct optstruct *opt)

ret = diffdirs(olddb, pt, patch);

rmdirs(pt);
cli_rmdirs(pt);
free(pt);

if(ret == -1) {
if(!inc)
rmdirs(olddb);
cli_rmdirs(olddb);
return -1;
}

ret = verifydiff(patch, NULL, olddb);

if(!inc)
rmdirs(olddb);
cli_rmdirs(olddb);

if(ret == -1) {
snprintf(broken, sizeof(broken), "%s.broken", patch);
Expand Down Expand Up @@ -1113,20 +1113,20 @@ static int listdb(const char *filename)

if(cvd_unpack(filename, dir) == -1) {
mprintf("!listdb: Can't unpack CVD file %s\n", filename);
rmdirs(dir);
cli_rmdirs(dir);
free(dir);
return -1;
}

/* list extracted directory */
if(listdir(dir) == -1) {
mprintf("!listdb: Can't list directory %s\n", filename);
rmdirs(dir);
cli_rmdirs(dir);
free(dir);
return -1;
}

rmdirs(dir);
cli_rmdirs(dir);
free(dir);

return 0;
Expand Down Expand Up @@ -1255,7 +1255,7 @@ static int vbadump(struct optstruct *opt)

close(fd);
sigtool_vba_scandir(dir, hex_output);
rmdirs(dir);
cli_rmdirs(dir);
free(dir);
return 0;
}
Expand Down Expand Up @@ -1423,22 +1423,22 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir)
if(cvd) {
if(cvd_unpack(cvd, tempdir) == -1) {
mprintf("!verifydiff: Can't unpack CVD file %s\n", cvd);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
return -1;
}
} else {
if(dircopy(incdir, tempdir) == -1) {
mprintf("!verifydiff: Can't copy dir %s to %s\n", incdir, tempdir);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
return -1;
}
}

if((fd = open(diff, O_RDONLY)) == -1) {
mprintf("!verifydiff: Can't open diff file %s\n", diff);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
return -1;
}
Expand All @@ -1447,7 +1447,7 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir)

if(chdir(tempdir) == -1) {
mprintf("!verifydiff: Can't chdir to %s\n", tempdir);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
close(fd);
return -1;
Expand All @@ -1456,7 +1456,7 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir)
if(cdiff_apply(fd, mode) == -1) {
mprintf("!verifydiff: Can't apply %s\n", diff);
chdir(cwd);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
close(fd);
return -1;
Expand All @@ -1473,7 +1473,7 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir)
if(!(fh = fopen(info, "r"))) {
mprintf("!verifydiff: Can't open %s\n", info);
chdir(cwd);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
return -1;
}
Expand All @@ -1483,7 +1483,7 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir)
if(strncmp(buff, "ClamAV-VDB", 10)) {
mprintf("!verifydiff: Incorrect info file %s\n", info);
chdir(cwd);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);
return -1;
}
Expand All @@ -1510,7 +1510,7 @@ static int verifydiff(const char *diff, const char *cvd, const char *incdir)

fclose(fh);
chdir(cwd);
rmdirs(tempdir);
cli_rmdirs(tempdir);
free(tempdir);

if(!ret) {
Expand Down Expand Up @@ -1623,31 +1623,31 @@ static int makediff(struct optstruct *opt)

if(cvd_unpack(opt_arg(opt, "diff"), odir) == -1) {
mprintf("!makediff: Can't unpack CVD file %s\n", opt_arg(opt, "diff"));
rmdirs(odir);
cli_rmdirs(odir);
free(odir);
return -1;
}

ndir = cli_gentemp(NULL);
if(!ndir) {
mprintf("!makediff: Can't generate temporary name for ndir\n");
rmdirs(odir);
cli_rmdirs(odir);
free(odir);
return -1;
}

if(mkdir(ndir, 0700) == -1) {
mprintf("!makediff: Can't create directory %s\n", ndir);
free(ndir);
rmdirs(odir);
cli_rmdirs(odir);
free(odir);
return -1;
}

if(cvd_unpack(opt->filename, ndir) == -1) {
mprintf("!makediff: Can't unpack CVD file %s\n", opt->filename);
rmdirs(odir);
rmdirs(ndir);
cli_rmdirs(odir);
cli_rmdirs(ndir);
free(odir);
free(ndir);
return -1;
Expand All @@ -1660,8 +1660,8 @@ static int makediff(struct optstruct *opt)

ret = diffdirs(odir, ndir, name);

rmdirs(odir);
rmdirs(ndir);
cli_rmdirs(odir);
cli_rmdirs(ndir);
free(odir);
free(ndir);

Expand Down

0 comments on commit 66ba178

Please sign in to comment.