diff options
| author | Lennart Poettering <lennart@poettering.net> | 2003-08-29 01:21:11 +0000 |
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2003-08-29 01:21:11 +0000 |
| commit | db3b96fc0014a5e860df1efc729b38d629662826 (patch) | |
| tree | 9076f5b7c6a14c6239b562d442cdf46d755c9ff0 /src/cleanup.c | |
| parent | 0d7460e9592c501b48fe9ab05d8e7fd52cb5bb4d (diff) | |
many fixes
--cleanup implemented
git-svn-id: file:///home/lennart/svn/public/syrep/trunk@13 07ea20a6-d2c5-0310-9e02-9ef735347d72
Diffstat (limited to 'src/cleanup.c')
| -rw-r--r-- | src/cleanup.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/cleanup.c b/src/cleanup.c new file mode 100644 index 0000000..6f096f9 --- /dev/null +++ b/src/cleanup.c @@ -0,0 +1,92 @@ +/* $Id$ */ + +/*** + This file is part of syrep. + + syrep is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + syrep is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with syrep; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +***/ + +#include <unistd.h> +#include <string.h> +#include <limits.h> +#include <errno.h> + +#include "syrep.h" +#include "util.h" + +int cleanup(const char *root) { + char p[PATH_MAX]; + + if (args.cleanup_level_arg >= 1) { + + if (args.verbose_flag) + fprintf(stderr, "Emptying trash ...\n"); + + snprintf(p, sizeof(p), "%s/.syrep/" SYREP_TRASHDIR, root); + + if (rm_rf(p, 0) < 0) + return -1; + + if (args.verbose_flag) + fprintf(stderr, "Removing temporary directories ...\n"); + + snprintf(p, sizeof(p), "%s/.syrep/" SYREP_TEMPDIR, root); + + if (rm_rf(p, 1) < 0) + return -1; + } + + if (args.cleanup_level_arg >= 2) { + + if (args.verbose_flag) + fprintf(stderr, "Removing digest cache ...\n"); + + snprintf(p, sizeof(p), "%s/.syrep/" SYREP_MDCACHEFILENAME, root); + + if (unlink(p) < 0) { + if (errno != ENOENT) { + fprintf(stderr, "unlink(\"%s\"): %s\n", p, strerror(errno)); + return -1; + } + } + } + + if (args.cleanup_level_arg >= 3) { + + if (args.verbose_flag) + fprintf(stderr, "Removing status data ...\n"); + + snprintf(p, sizeof(p), "%s/.syrep/" SYREP_SNAPSHOTFILENAME, root); + + if (unlink(p) < 0) { + if (errno != ENOENT) { + fprintf(stderr, "unlink(\"%s\"): %s\n", p, strerror(errno)); + return -1; + } + } + + snprintf(p, sizeof(p), "%s/.syrep", root); + + if (rmdir(p) < 0) { + if (errno != ENOENT) { + fprintf(stderr, "rmdir(\"%s\"): %s\n", p, strerror(errno)); + return -1; + } + } + } + + + return 0; +} |
