/*
* Dolda Connect - Modular multiuser Direct Connect-style client
- * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
+ * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com>
*
* 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
{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}
};
* job. */
static pid_t hashjob = -1;
struct sharecache *shareroot = NULL;
-static time_t lastscan = 0;
+static struct timer *scantimer = NULL;
unsigned long long sharesize = 0;
GCBCHAIN(sharechangecb, unsigned long long);
*/
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)
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;
}
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)
}
}
+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;
}
scanshares();
if(!hup)
+ {
while(doscan(100));
+ CBREG(confgetvar("cli", "rescandelay"), conf_update, rsdelayupdate, NULL, NULL);
+ }
return(0);
}