Code

* make lock_timeout configurable
[fusedav.git] / src / statcache.c
index 3622a73a468f61c98abf5a0902c8c0636c13a0a2..d9e801f32b8b299ab78021e10bdb5ada292bf3ed 100644 (file)
@@ -1,3 +1,27 @@
+/* $Id$ */
+
+/***
+  This file is part of fusedav.
+
+  fusedav is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  fusedav is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+  License for more details.
+  
+  You should have received a copy of the GNU General Public License
+  along with fusedav; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdio.h>
 #include <inttypes.h>
 #include <time.h>
@@ -7,6 +31,7 @@
 #include <assert.h>
 
 #include "statcache.h"
+#include "filecache.h"
 #include "fusedav.h"
 
 #include <ne_uri.h>
@@ -16,7 +41,6 @@
 
 struct dir_entry {
     struct dir_entry *next;
-    int is_dir;
     char filename[];
 };
 
@@ -46,7 +70,7 @@ static uint32_t calc_hash(const char *s) {
     uint32_t h = 0;
 
     for (; *s; s++) {
-        h ^= * (uint8_t*) s;
+        h ^= * (const uint8_t*) s;
         h = (h << 8) | (h  >> 24);
     }
 
@@ -57,6 +81,7 @@ int stat_cache_get(const char *fn, struct stat *st) {
     uint32_t h;
     struct cache_entry *ce;
     int r = -1;
+    void *f;
 
     if (debug)
         fprintf(stderr, "CGET: %s\n", fn);
@@ -75,6 +100,12 @@ int stat_cache_get(const char *fn, struct stat *st) {
         time(NULL) <= ce->stat_info.dead) {
         
         *st = ce->stat_info.st;
+
+        if ((f = file_cache_get(fn))) {
+            st->st_size = file_cache_get_size(f);
+            file_cache_unref(f);
+        }
+
         r = 0;
     }
 
@@ -215,7 +246,7 @@ void dir_cache_finish(const char *fn, int success) {
     free_dir_entries(de);
 }
 
-void dir_cache_add(const char *fn, const char *subdir, int is_dir) {
+void dir_cache_add(const char *fn, const char *subdir) {
     uint32_t h;
     struct cache_entry *ce;
     assert(cache);
@@ -238,7 +269,6 @@ void dir_cache_add(const char *fn, const char *subdir, int is_dir) {
         assert(n);
 
         strcpy(n->filename, subdir);
-        n->is_dir = is_dir;
         
         n->next = ce->dir_info.entries2;
         ce->dir_info.entries2 = n;
@@ -247,12 +277,13 @@ void dir_cache_add(const char *fn, const char *subdir, int is_dir) {
     pthread_mutex_unlock(&dir_cache_mutex);
 }
 
-int dir_cache_enumerate(const char *fn, void (*f) (const char*fn, const char *subdir, int is_dir, void *user), void *user) {
+int dir_cache_enumerate(const char *fn, void (*f) (const char*fn, const char *subdir, void *user), void *user) {
     uint32_t h;
     struct cache_entry *ce;
     struct dir_entry *de = NULL;
-    assert(cache && f);
     int r = -1;
+
+    assert(cache && f);
     
     h = calc_hash(fn);
     ce = cache + (h % CACHE_SIZE);
@@ -269,7 +300,7 @@ int dir_cache_enumerate(const char *fn, void (*f) (const char*fn, const char *su
         pthread_mutex_unlock(&dir_cache_mutex);
 
         for (de = ce->dir_info.entries; de; de = de->next)
-            f(fn, de->filename, de->is_dir, user);
+            f(fn, de->filename, user);
 
         pthread_mutex_lock(&dir_cache_mutex);
         ce->dir_info.in_use = 0;
@@ -356,6 +387,7 @@ void cache_alloc(void) {
         return;
 
     cache = malloc(sizeof(struct cache_entry)*CACHE_SIZE);
+    assert(cache);
     memset(cache, 0, sizeof(struct cache_entry)*CACHE_SIZE);
 }