mirror of git://git.sysmocom.de/ofono
simfs: Add cache flushing functions
This commit is contained in:
parent
5213119ac5
commit
2cec48fb1c
68
src/simfs.c
68
src/simfs.c
|
@ -907,9 +907,6 @@ 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 (imsi == NULL || phase == OFONO_SIM_PHASE_UNKNOWN)
|
||||
return;
|
||||
|
@ -918,10 +915,20 @@ void sim_fs_check_version(struct sim_fs *fs)
|
|||
if (version == SIM_FS_VERSION)
|
||||
return;
|
||||
|
||||
path = g_strdup_printf(SIM_CACHE_BASEPATH, imsi, phase);
|
||||
sim_fs_cache_flush(fs);
|
||||
|
||||
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)
|
||||
{
|
||||
const char *imsi = ofono_sim_get_imsi(fs->sim);
|
||||
enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
|
||||
char *path = g_strdup_printf(SIM_CACHE_BASEPATH, imsi, phase);
|
||||
struct dirent **entries;
|
||||
int len = scandir(path, &entries, NULL, alphasort);
|
||||
|
||||
ofono_info("Detected old simfs version in %s, removing", path);
|
||||
len = scandir(path, &entries, NULL, alphasort);
|
||||
g_free(path);
|
||||
|
||||
if (len > 0) {
|
||||
|
@ -934,20 +941,47 @@ 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);
|
||||
sim_fs_image_cache_flush(fs);
|
||||
}
|
||||
|
||||
void sim_fs_cache_flush_file(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);
|
||||
char *path = g_strdup_printf(SIM_CACHE_PATH, imsi, phase, id);
|
||||
|
||||
remove(path);
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
void sim_fs_image_cache_flush(struct sim_fs *fs)
|
||||
{
|
||||
const char *imsi = ofono_sim_get_imsi(fs->sim);
|
||||
enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
|
||||
char *path = g_strdup_printf(SIM_IMAGE_CACHE_BASEPATH, imsi, phase);
|
||||
struct dirent **entries;
|
||||
int 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]);
|
||||
}
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
g_free(entries);
|
||||
/* Remove everything */
|
||||
while (len--) {
|
||||
remove_imagefile(imsi, phase, entries[len]);
|
||||
g_free(entries[len]);
|
||||
}
|
||||
|
||||
version = SIM_FS_VERSION;
|
||||
write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION, imsi, phase);
|
||||
g_free(entries);
|
||||
}
|
||||
|
||||
void sim_fs_image_cache_flush_file(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);
|
||||
char *path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
|
||||
|
||||
remove(path);
|
||||
g_free(path);
|
||||
}
|
||||
|
|
|
@ -47,4 +47,9 @@ 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);
|
||||
void sim_fs_cache_flush_file(struct sim_fs *fs, int id);
|
||||
void sim_fs_image_cache_flush(struct sim_fs *fs);
|
||||
void sim_fs_image_cache_flush_file(struct sim_fs *fs, int id);
|
||||
|
||||
void sim_fs_free(struct sim_fs *fs);
|
||||
|
|
Loading…
Reference in New Issue