Icon cache: open correctly and create when needed
This commit is contained in:
@@ -52,6 +52,8 @@ void load_cache(Cache *cache, const gchar *cache_path)
|
|||||||
{
|
{
|
||||||
init_cache(cache);
|
init_cache(cache);
|
||||||
|
|
||||||
|
cache->loaded = TRUE;
|
||||||
|
|
||||||
int fd = open(cache_path, O_RDONLY);
|
int fd = open(cache_path, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return;
|
return;
|
||||||
@@ -89,8 +91,6 @@ void load_cache(Cache *cache, const gchar *cache_path)
|
|||||||
free(line);
|
free(line);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
cache->loaded = TRUE;
|
|
||||||
|
|
||||||
unlock:
|
unlock:
|
||||||
flock(fd, LOCK_UN);
|
flock(fd, LOCK_UN);
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -107,21 +107,23 @@ void write_cache_line(gpointer key, gpointer value, gpointer user_data)
|
|||||||
|
|
||||||
void save_cache(Cache *cache, const gchar *cache_path)
|
void save_cache(Cache *cache, const gchar *cache_path)
|
||||||
{
|
{
|
||||||
int fd = open(cache_path, O_RDONLY | O_CREAT);
|
int fd = open(cache_path, O_RDONLY | O_CREAT, 0600);
|
||||||
if (fd == -1)
|
if (fd == -1) {
|
||||||
|
gchar *dir_path = g_path_get_dirname(cache_path);
|
||||||
|
g_mkdir_with_parents(dir_path, 0700);
|
||||||
|
g_free(dir_path);
|
||||||
|
fd = open(cache_path, O_RDONLY | O_CREAT, 0600);
|
||||||
|
}
|
||||||
|
if (fd == -1) {
|
||||||
|
fprintf(stderr, RED "Could not save icon theme cache!" RESET "\n");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
flock(fd, LOCK_EX);
|
flock(fd, LOCK_EX);
|
||||||
|
|
||||||
FILE *f = fopen(cache_path, "w");
|
FILE *f = fopen(cache_path, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
gchar *dir_path = g_path_get_dirname(cache_path);
|
fprintf(stderr, RED "Could not save icon theme cache!" RESET "\n");
|
||||||
g_mkdir_with_parents(dir_path, 0700);
|
goto unlock;
|
||||||
g_free(dir_path);
|
|
||||||
f = fopen(cache_path, "w");
|
|
||||||
if (!f) {
|
|
||||||
fprintf(stderr, RED "Could not save icon theme cache!" RESET "\n");
|
|
||||||
goto unlock;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
g_hash_table_foreach(cache->_table, write_cache_line, f);
|
g_hash_table_foreach(cache->_table, write_cache_line, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|||||||
Reference in New Issue
Block a user