Add:Core:Added support for checking a files version
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 20 Oct 2008 19:21:09 +0000 (19:21 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 20 Oct 2008 19:21:09 +0000 (19:21 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1520 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/file.c
navit/file.h

index ffe79f7..a17ed4c 100644 (file)
@@ -43,8 +43,6 @@
 #define O_BINARY 0
 #endif
 
-static struct file *file_list;
-
 static GHashTable *file_name_hash;
 static int file_name_id;
 static struct cache *file_cache;
@@ -73,8 +71,6 @@ file_create(char *name)
        file->size=stat.st_size;
        file->name = g_strdup(name);
        dbg_assert(file != NULL);
-       file->next=file_list;
-       file_list=file;
        return file;
 }
 
@@ -250,18 +246,6 @@ file_remap_readonly(struct file *f)
 }
 
 void
-file_remap_readonly_all(void)
-{
-       struct file *f=file_list;
-       int limit=1000;
-
-       while (f && limit-- > 0) {
-               file_remap_readonly(f);
-               f=f->next;
-       }
-}
-
-void
 file_unmap(struct file *f)
 {
 #if defined(_WIN32) || defined(__CEGCC__)
@@ -271,20 +255,6 @@ file_unmap(struct file *f)
 #endif
 }
 
-void
-file_unmap_all(void)
-{
-       struct file *f=file_list;
-       int limit=1000;
-
-       while (f && limit-- > 0) {
-               file_unmap(f);
-               f=f->next;
-       }
-}
-
-
-
 void *
 file_opendir(char *dir)
 {
@@ -405,6 +375,28 @@ file_get_param(struct file *file, struct param_list *param, int count)
        return i-count;
 }
 
+int
+file_version(struct file *file, int byname)
+{
+#ifndef __CEGCC__
+       struct stat st;
+       int error;
+       if (byname)
+               error=stat(file->name, &st);
+       else
+               error=fstat(file->fd, &st);
+       if (error || !file->version || file->mtime != st.st_mtime || file->ctime != st.st_ctime) {
+               file->mtime=st.st_mtime;
+               file->ctime=st.st_ctime;
+               file->version++;
+               dbg(0,"%s now version %d\n", file->name, file->version);
+       }
+       return file->version;
+#else
+       return 0;
+#endif
+}
+
 void
 file_init(void)
 {
index 971e32d..bf05b6c 100644 (file)
@@ -20,6 +20,9 @@
 #ifndef NAVIT_FILE_H
 #define NAVIT_FILE_H
 
+#ifndef __CEGCC__
+#include <time.h>
+#endif
 #include "param.h"
 
 struct file {
@@ -29,9 +32,14 @@ struct file {
        char *name;
        int name_id;
        int fd;
+#ifndef __CEGCC__
+       time_t mtime;
+       time_t ctime;
+       int version;                    
+#endif
 #if defined(_WIN32) || defined(__CEGCC__)
-    long map_handle;
-    long map_file;
+       long map_handle;
+       long map_file;
 #endif
        struct file *next;
 };
@@ -49,9 +57,7 @@ unsigned char *file_data_read_compressed(struct file *file, long long offset, in
 void file_data_free(struct file *file, unsigned char *data);
 int file_exists(char *name);
 void file_remap_readonly(struct file *f);
-void file_remap_readonly_all(void);
 void file_unmap(struct file *f);
-void file_unmap_all(void);
 void *file_opendir(char *dir);
 char *file_readdir(void *hnd);
 void file_closedir(void *hnd);
@@ -62,6 +68,7 @@ int file_wordexp_get_count(struct file_wordexp *wexp);
 char **file_wordexp_get_array(struct file_wordexp *wexp);
 void file_wordexp_destroy(struct file_wordexp *wexp);
 int file_get_param(struct file *file, struct param_list *param, int count);
+int file_version(struct file *file, int byname);
 /* end of prototypes */
 
 #endif