fsck: Overwrite the backup index file if it exists.
[osl.git] / fsck.c
diff --git a/fsck.c b/fsck.c
index e623b3789f284910c6a9b7ad6fbea5231030ed57..bc77424e30db1f7939ec6b084d707b283b0693ed 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -14,7 +14,6 @@
 
 #include "log.h"
 #include "osl.h"
-#include "error.h"
 #include "util.h"
 #include "osl_core.h"
 #include "fsck.cmdline.h"
@@ -44,6 +43,7 @@ static struct fsck_args_info conf;
        FSCK_ERROR(CHDIR, "could not change directory"), \
        FSCK_ERROR(OPENDIR, "could not open directory"),
 
+#define FSCK_ERROR_BIT 29
 #define FSCK_ERROR(num, txt) E_FSCK_ ## num
 enum {
        FSCK_DUMMY = (1 << FSCK_ERROR_BIT) - 1,
@@ -121,8 +121,8 @@ static int _write_all(int fd, const char *buf, size_t len)
        return write_all(fd, buf, &len);
 }
 
-/**
- * Paraslash's version of malloc().
+/*
+ * Wrapper for malloc().
  *
  * \param size The desired new size.
  *
@@ -147,7 +147,7 @@ __must_check __malloc static void *fsck_malloc(size_t size)
 }
 
 /**
- * Paraslash's version of calloc().
+ * Allocate memory and fill with zeros.
  *
  * \param size The desired new size.
  *
@@ -167,7 +167,7 @@ __must_check __malloc static void *fsck_calloc(size_t size)
 }
 
 /**
- * Paraslash's version of strdup().
+ * Save version of strdup().
  *
  * \param s The string to be duplicated.
  *
@@ -577,7 +577,8 @@ static int prune_objects(struct osl_table *t, uint32_t *lost_bytes)
 
        NOTICE_LOG("removing unreferenced objects from data files\n");
        /* first make a copy of the index */
-       ret = osl_open(old_idx_filename, O_WRONLY | O_CREAT | O_EXCL, 0644);
+       DEBUG_LOG("opening %s\n", old_idx_filename);
+       ret = osl_open(old_idx_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if (ret < 0)
                goto out_free;
        fd = ret;
@@ -1169,7 +1170,8 @@ static int check_table(char *db_dir, char *table_name)
        ret = dump_table(conf.dump_dir_arg, &desc);
 out:
        if (ret < 0)
-               ERROR_LOG("failed to check table %s\n", table_name);
+               ERROR_LOG("failed to check table %s: %s\n", table_name,
+                       fsck_strerror(-ret));
        else
                NOTICE_LOG("successfully checked table %s\n", table_name);
        return ret;