---
 src/simfs.c |   35 +++++++++++++++++++++++++++--------
 src/simfs.h |    2 ++
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/simfs.c b/src/simfs.c
index 8e52f7b..2f58d9b 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -903,17 +903,39 @@ void sim_fs_check_version(struct sim_fs *fs)
        const char *imsi = ofono_sim_get_imsi(fs->sim);
        enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
        unsigned char version;
-       struct dirent **entries;
-       int len;
-       char *path;
 
        if (read_file(&version, 1, SIM_CACHE_VERSION, imsi, phase) == 1)
                if (version == SIM_FS_VERSION)
                        return;
 
-       path = g_strdup_printf(SIM_CACHE_BASEPATH, imsi, phase);
+       sim_fs_cache_flush(fs,  0);
+
+       version = SIM_FS_VERSION;
+       write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION, imsi, phase);
+}
+
+void sim_fs_cache_flush(struct sim_fs *fs, int id)
+{
+       const char *imsi = ofono_sim_get_imsi(fs->sim);
+       enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
+       int len;
+       char *path;
+       struct dirent **entries;
+
+       /* Id of 0 flushes all cache content */
+       if (id > 0) {
+               path = g_strdup_printf(SIM_CACHE_PATH, imsi, phase, id);
+               remove(path);
+               g_free(path);
+
+               path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
+               remove(path);
+               g_free(path);
+
+               return;
+       }
 
-       ofono_info("Detected old simfs version in %s, removing", path);
+       path = g_strdup_printf(SIM_CACHE_BASEPATH, imsi, phase);
        len = scandir(path, &entries, NULL, alphasort);
        g_free(path);
 
@@ -940,7 +962,4 @@ void sim_fs_check_version(struct sim_fs *fs)
 
                g_free(entries);
        }
-
-       version = SIM_FS_VERSION;
-       write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION, imsi, phase);
 }
diff --git a/src/simfs.h b/src/simfs.h
index ef962db..ace25bf 100644
--- a/src/simfs.h
+++ b/src/simfs.h
@@ -47,4 +47,6 @@ char *sim_fs_get_cached_image(struct sim_fs *fs, int id);
 
 void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id);
 
+void sim_fs_cache_flush(struct sim_fs *fs, int id);
+
 void sim_fs_free(struct sim_fs *fs);
-- 
1.7.1.86.g0e460.dirty

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to