/*
- $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>
return;
}
-void set_signal(void)
+static void set_signal(void)
{
struct sigaction sv;
}
}
-int get_lock(const char *dbpath)
+static int get_lock(const char *dbpath)
{
int lockfd;
char lockpath[PATH_MAX];
return lockfd;
}
-void free_lock(int lockfd)
+static void free_lock(int lockfd)
{
struct flock lock;
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"
" 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"
" -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"
);
}
/* 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) {
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.
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.");
}