X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Fclient.c;h=e493a884ce47f449b80ea86ad3e1901dffce9c54;hb=c662029bed19d3b706cee02ac093758e4cc99649;hp=c07745385339c24bcd59feafa56f6c6eb588958f;hpb=ddb3658e4a9d9efb7a8628fee483e5371c426d12;p=doldaconnect.git diff --git a/daemon/client.c b/daemon/client.c index c077453..e493a88 100644 --- a/daemon/client.c +++ b/daemon/client.c @@ -1,6 +1,6 @@ /* * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) + * Copyright (C) 2004 Fredrik Tolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,7 +81,9 @@ static struct configvar myvars[] = {CONF_VAR_INT, "hashwritedelay", {.num = 300}}, /** The amount of time, in seconds, to wait before automatically * rescanning the shared directories for changes. Set to zero (the - * default) to disable automatic rescanning. */ + * default) to disable automatic rescanning. (Broken shares are + * always rescanned upon detection, regardless of this + * setting.) */ {CONF_VAR_INT, "rescandelay", {.num = 0}}, {CONF_VAR_END} }; @@ -103,7 +105,8 @@ static struct timer *hashwritetimer = NULL; * job. */ static pid_t hashjob = -1; struct sharecache *shareroot = NULL; -static time_t lastscan = 0; +static struct timer *scantimer = NULL; +int sharedfiles = 0; unsigned long long sharesize = 0; GCBCHAIN(sharechangecb, unsigned long long); @@ -291,8 +294,10 @@ static void readhashcache(void) if((stream = fopen(hcname, "r")) == NULL) { flog(LOG_WARNING, "could not open hash cache %s: %s", hcname, strerror(errno)); + free(hcname); return; } + free(hcname); while(hashcache != NULL) freehashcache(hashcache); line = 0; @@ -366,8 +371,10 @@ static void writehashcache(int now) if((stream = fopen(hcname, "w")) == NULL) { flog(LOG_WARNING, "could not write hash cache %s: %s", hcname, strerror(errno)); + free(hcname); return; } + free(hcname); fprintf(stream, "# Dolda Connect hash cache file\n"); fprintf(stream, "# Generated automatically, do not edit\n"); fprintf(stream, "# Format: DEVICE INODE MTIME [HASH...]\n"); @@ -526,13 +533,14 @@ static int hashfile(char *path) */ static void checkhashes(void) { - struct sharecache *node; + struct sharecache *node, *next; struct hashcache *hc; char *path; node = shareroot->child; - for(node = shareroot->child; node != NULL; node = nextscnode(node)) + for(node = shareroot->child; node != NULL; node = next) { + next = nextscnode(node); if(node->f.b.type != FILE_REG) continue; if(!node->f.b.hastth) @@ -645,6 +653,8 @@ static void freecache(struct sharecache *node) CBCHAINDOCB(node, share_delete, node); CBCHAINFREE(node, share_delete); sharesize -= node->size; + if(node->f.b.type == FILE_REG) + sharedfiles--; if(node->path != NULL) free(node->path); if(node->name != NULL) @@ -935,6 +945,7 @@ int doscan(int quantum) if(S_ISREG(sb.st_mode)) { sharesize += (n->size = sb.st_size); + sharedfiles++; } else { n->size = 0; } @@ -973,6 +984,18 @@ int doscan(int quantum) return(1); } +static void rescancb(int cancelled, void *uudata) +{ + scantimer = NULL; + if(!cancelled) + { + if(scanqueue == NULL) + scanshares(); + else if(confgetint("cli", "rescandelay") > 0) + scantimer = timercallback(ntime() + confgetint("cli", "rescandelay"), (void (*)(int, void *))rescancb, NULL); + } +} + void scanshares(void) { struct sharepoint *cur; @@ -1003,6 +1026,10 @@ void scanshares(void) } queuescan(node); } + if(scantimer != NULL) + canceltimer(scantimer); + if(confgetint("cli", "rescandelay") > 0) + scantimer = timercallback(ntime() + confgetint("cli", "rescandelay"), (void (*)(int, void *))rescancb, NULL); } static void preinit(int hup) @@ -1020,6 +1047,15 @@ static void preinit(int hup) } } +static int rsdelayupdate(struct configvar *var, void *uudata) +{ + if(scantimer != NULL) + canceltimer(scantimer); + if(confgetint("cli", "rescandelay") > 0) + scantimer = timercallback(ntime() + var->val.num, (void (*)(int, void *))rescancb, NULL); + return(0); +} + static int init(int hup) { struct sharepoint *cur, *next; @@ -1033,7 +1069,10 @@ static int init(int hup) } scanshares(); if(!hup) + { while(doscan(100)); + CBREG(confgetvar("cli", "rescandelay"), conf_update, rsdelayupdate, NULL, NULL); + } return(0); } @@ -1051,6 +1090,8 @@ static void terminate(void) { if(hashjob != 0) kill(hashjob, SIGHUP); + if(hashwritetimer != NULL) + writehashcache(1); while(shares != NULL) freesharepoint(shares); freecache(shareroot);