diff options
author | Denis Kenzior <denkenz@gmail.com> | 2010-10-13 02:55:04 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-10-13 05:04:47 -0500 |
commit | e828bc767c76e7297840ea138484c3eb432ecfce (patch) | |
tree | fcd516d743946e725e47fde6c80e7aecdabf500f /src/simfs.c | |
parent | 5524b1732417c539cf3f6cf75e0ef5cbad4e710a (diff) | |
download | ofono-e828bc767c76e7297840ea138484c3eb432ecfce.tar.bz2 |
simfs: Also clean out image files
When cleaning cache
Diffstat (limited to 'src/simfs.c')
-rw-r--r-- | src/simfs.c | 34 |
1 files changed, 33 insertions, 1 deletions
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); } |