From db3b96fc0014a5e860df1efc729b38d629662826 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Aug 2003 01:21:11 +0000 Subject: many fixes --cleanup implemented git-svn-id: file:///home/lennart/svn/public/syrep/trunk@13 07ea20a6-d2c5-0310-9e02-9ef735347d72 --- src/cleanup.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/cleanup.c (limited to 'src/cleanup.c') 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 +#include +#include +#include + +#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; +} -- cgit