From e828bc767c76e7297840ea138484c3eb432ecfce Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Wed, 13 Oct 2010 02:55:04 -0500 Subject: [PATCH] simfs: Also clean out image files When cleaning cache --- src/simfs.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/simfs.c b/src/simfs.c index 4a5570c0..fd768eff 100644 --- a/src/simfs.c +++ b/src/simfs.c @@ -47,7 +47,8 @@ #define SIM_CACHE_PATH SIM_CACHE_BASEPATH "/%04x" #define SIM_CACHE_HEADER_SIZE 38 #define SIM_FILE_INFO_SIZE 6 -#define SIM_IMAGE_CACHE_PATH STORAGEDIR "/%s-%i/images/%d.xpm" +#define SIM_IMAGE_CACHE_BASEPATH STORAGEDIR "/%s-%i/images" +#define SIM_IMAGE_CACHE_PATH SIM_IMAGE_CACHE_BASEPATH "/%d.xpm" #define SIM_FS_VERSION 1 @@ -810,6 +811,23 @@ static void remove_cachefile(const char *imsi, enum ofono_sim_phase phase, g_free(path); } +static void remove_imagefile(const char *imsi, enum ofono_sim_phase phase, + const struct dirent *file) +{ + int id; + char *path; + + if (file->d_type != DT_REG) + return; + + if (sscanf(file->d_name, "%d", &id) != 1) + return; + + path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id); + remove(path); + g_free(path); +} + void sim_fs_check_version(struct sim_fs *fs) { const char *imsi = ofono_sim_get_imsi(fs->sim); @@ -839,6 +857,20 @@ void sim_fs_check_version(struct sim_fs *fs) g_free(entries); } + path = g_strdup_printf(SIM_IMAGE_CACHE_BASEPATH, imsi, phase); + len = scandir(path, &entries, NULL, alphasort); + g_free(path); + + if (len > 0) { + /* Remove everything */ + while (len--) { + remove_imagefile(imsi, phase, entries[len]); + g_free(entries[len]); + } + + g_free(entries); + } + version = SIM_FS_VERSION; write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION, imsi, phase); }