]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/cmd_dbd.c
Scan mode wasn't called
[netatalk.git] / etc / cnid_dbd / cmd_dbd.c
index 34c6e43a5dd1d93a9a403ae4627db981d193a577..a932ee772c1b74740b016e5169b40f9cfcd30fa0 100644 (file)
@@ -1,5 +1,5 @@
 /* 
-   $Id: cmd_dbd.c,v 1.9 2009-10-12 11:38:01 franklahm Exp $
+   $Id: cmd_dbd.c,v 1.17 2009-11-30 15:51:30 franklahm Exp $
 
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
    
@@ -131,7 +131,7 @@ static void sig_handler(int signo)
     return;
 }
 
-void set_signal(void)
+static void set_signal(void)
 {
     struct sigaction sv;
 
@@ -165,7 +165,7 @@ void set_signal(void)
     }        
 }
 
-int get_lock(const char *dbpath)
+static int get_lock(const char *dbpath)
 {
     int lockfd;
     char lockpath[PATH_MAX];
@@ -215,7 +215,7 @@ int get_lock(const char *dbpath)
     return lockfd;
 }
 
-void free_lock(int lockfd)
+static void free_lock(int lockfd)
 {
     struct flock lock;
 
@@ -227,7 +227,7 @@ void free_lock(int lockfd)
     close(lockfd);
 }
 
-static void usage ()
+static void usage (void)
 {
     printf("Usage: dbd [-e|-v|-x] -d [-i] | -s [-n]| -r [-f] | -u <path to netatalk volume>\n"
            "dbd can dump, scan, reindex and rebuild Netatalk dbd CNID databases.\n"
@@ -255,7 +255,7 @@ static void usage ()
            "      7. Check for orphaned CNIDs in database (requires -e)\n"
            "      8. Open and close adouble files\n"
            "      Option: -f wipe database and rebuild from IDs stored in AppleDouble files,\n"
-           "                 only available for volumes with 'cachecnid' option. Implies -e.\n"
+           "                 only available for volumes without 'nocnidcache' option. Implies -e.\n"
            "   -u Prepare upgrade:\n"
            "      Before installing an upgraded version of Netatalk that is linked against\n"
            "      a newer BerkeleyDB lib, run `dbd -u ...` from the OLD Netatalk pior to\n"
@@ -266,9 +266,8 @@ static void usage ()
            "   -x rebuild indexes (just for completeness, mostly useless!)\n"
            "   -v verbose\n\n"
            "WARNING:\n"
-           "If you want/need to run an -r -f rebuild after adding 'cachecnid' to a volume configuration,\n"
-           "you must run a rebuild with -r alone at first in order to sync all existing CNIDs from the db\n"
-           "to the AppleDouble files!\n"
+           "For -r -f restore of the CNID database from the adouble files, the CNID must of course\n"
+           "be synched to them files first with a plain -r rebuild !\n"
         );
 }
 
@@ -352,13 +351,13 @@ int main(int argc, char **argv)
 
     /* Setup logging. Should be portable among *NIXes */
     if (!verbose)
-        setuplog("default log_info /dev/tty");
+        setuplog("console log_info /dev/tty");
     else
-        setuplog("default log_debug /dev/tty");
+        setuplog("console log_debug /dev/tty");
 
     /* Load .volinfo file */
     if (loadvolinfo(volpath, &volinfo) == -1) {
-        dbd_log( LOGSTD, "Unkown volume options!");
+        dbd_log( LOGSTD, "Not a Netatalk volume at '%s', no .volinfo file at '%s/.AppleDesktop/.volinfo' or unknown volume options", volpath, volpath);
         exit(EXIT_FAILURE);
     }
     if (vol_load_charsets(&volinfo) == -1) {
@@ -374,6 +373,22 @@ int main(int argc, char **argv)
     strncpy(dbpath, volinfo.v_dbpath, PATH_MAX - 9 - 1);
     strcat(dbpath, "/.AppleDB");
 
+    /* Check or create dbpath */
+    int dbdirfd = open(dbpath, O_RDONLY);
+    if (dbdirfd == -1 && errno == ENOENT) {
+        if (errno == ENOENT) {
+            if ((mkdir(dbpath, 0755)) != 0) {
+                dbd_log( LOGSTD, "Can't create .AppleDB for \"%s\": %s", dbpath, strerror(errno));
+                exit(EXIT_FAILURE);
+            }
+        } else {
+            dbd_log( LOGSTD, "Somethings wrong with .AppleDB for \"%s\", giving up: %s", dbpath, strerror(errno));
+            exit(EXIT_FAILURE);
+        }
+    } else {
+        close(dbdirfd);
+    }
+
     /* 
        Before we do anything else, check if there is an instance of cnid_dbd
        running already and silently exit if yes.
@@ -427,7 +442,7 @@ int main(int argc, char **argv)
         if (dbif_dump(dbd, dumpindexes) < 0) {
             dbd_log( LOGSTD, "Error dumping database");
         }
-    } else if ((rebuild && ! nocniddb) || (scan && nocniddb)) {
+    } else if ((rebuild && ! nocniddb) || scan) {
         if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) {
             dbd_log( LOGSTD, "Error repairing database.");
         }