X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Fclient.c;h=6aa1887b91817382badd43ad0a23c6503bb5ec71;hb=533161b119ddbec3692368d134a250e14cf837c0;hp=47ac9de974961dbc009f0dd0d805a00596f9fb25;hpb=d9f89ef5daa6375fc4ff257826fa39562fbe3ac3;p=doldaconnect.git diff --git a/daemon/client.c b/daemon/client.c index 47ac9de..6aa1887 100644 --- a/daemon/client.c +++ b/daemon/client.c @@ -18,7 +18,6 @@ */ #include #include -#include #include #include #include @@ -255,52 +254,6 @@ static void freehashcache(struct hashcache *hc) free(hc); } -static char *findhashcachefile(int filldef) -{ - static char ret[128]; - char *hcname; - - if(getenv("HOME") != NULL) - { - snprintf(ret, sizeof(ret), "%s/.dc-hashcache", getenv("HOME")); - if(!access(ret, R_OK)) - return(ret); - } - if((hcname = icswcstombs(confgetstr("cli", "hashcache"), NULL, NULL)) == NULL) - { - flog(LOG_WARNING, "could not convert hash cache name into local charset: %s", strerror(errno)); - return(NULL); - } - if(strchr(hcname, '/') != NULL) - { - if(!access(hcname, R_OK)) - { - strcpy(ret, hcname); - return(ret); - } - } else { - snprintf(ret, sizeof(ret), "/etc/%s", hcname); - if(!access(ret, R_OK)) - return(ret); - snprintf(ret, sizeof(ret), "/usr/etc/%s", hcname); - if(!access(ret, R_OK)) - return(ret); - snprintf(ret, sizeof(ret), "/usr/local/etc/%s", hcname); - if(!access(ret, R_OK)) - return(ret); - } - if(filldef) - { - if(getenv("HOME") != NULL) - snprintf(ret, sizeof(ret), "%s/.dc-hashcache", getenv("HOME")); - else - snprintf(ret, sizeof(ret), "/etc/%s", hcname); - return(ret); - } else { - return(NULL); - } -} - static struct hashcache *findhashcache(dev_t dev, ino_t inode) { struct hashcache *hc; @@ -323,7 +276,7 @@ static void readhashcache(void) struct hashcache *hc; size_t len; - if((hcname = findhashcachefile(0)) == NULL) + if((hcname = findfile(icswcstombs(confgetstr("cli", "hashcache"), NULL, NULL), NULL, 0)) == NULL) return; if((stream = fopen(hcname, "r")) == NULL) { @@ -399,7 +352,7 @@ static void writehashcache(int now) } if(hashwritetimer != NULL) canceltimer(hashwritetimer); - hcname = findhashcachefile(1); + hcname = findfile(icswcstombs(confgetstr("cli", "hashcache"), NULL, NULL), NULL, 1); if((stream = fopen(hcname, "w")) == NULL) { flog(LOG_WARNING, "could not write hash cache %s: %s", hcname, strerror(errno)); @@ -413,7 +366,7 @@ static void writehashcache(int now) for(hc = hashcache; hc != NULL; hc = hc->next) { buf = base64encode(hc->tth, 24); - fprintf(stream, "%lli %lli %li tth %s\n", hc->dev, (long long)hc->inode, hc->mtime, buf); + fprintf(stream, "%lli %lli %li tth %s\n", (long long)hc->dev, (long long)hc->inode, hc->mtime, buf); free(buf); } fclose(stream); @@ -546,7 +499,7 @@ static int hashfile(char *path) } synctigertree(&tth); restigertree(&tth, digest); - ret = snprintf(buf, sizeof(buf), "%lli %lli %li %s\n", sb.st_dev, (long long)sb.st_ino, sb.st_mtime, base64encode(digest, 24)); + ret = snprintf(buf, sizeof(buf), "%lli %lli %li %s\n", (long long)sb.st_dev, (long long)sb.st_ino, sb.st_mtime, base64encode(digest, 24)); write(1, buf, ret); exit(0); }