fix cache filenames

move cache to XDG_CACHE_HOME and add hostname for shared homedirs

SVN revision: 55263
This commit is contained in:
Sebastian Dransfeld 2010-12-04 16:02:20 +00:00
parent 649aa06958
commit 9da725d028
6 changed files with 47 additions and 25 deletions

View File

@ -269,11 +269,11 @@ main(int argc, char **argv)
efreet_cache_update = 0;
/* create homedir */
snprintf(file, sizeof(file), "%s/.efreet", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
if (!ecore_file_mkpath(file)) goto efreet_error;
/* lock process, so that we only run one copy of this program */
snprintf(file, sizeof(file), "%s/.efreet/desktop_data.lock", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet/desktop_data.lock", efreet_cache_home_get());
lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (lockfd < 0) goto efreet_error;
memset(&fl, 0, sizeof(struct flock));
@ -442,7 +442,7 @@ main(int argc, char **argv)
}
/* touch update file */
snprintf(file, sizeof(file), "%s/.efreet/desktop_data.update", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet/desktop_data.update", efreet_cache_home_get());
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (tmpfd >= 0)
{

View File

@ -312,7 +312,7 @@ cache_lock_file(void)
struct flock fl;
int lockfd;
snprintf(file, sizeof(file), "%s/.efreet/icon_data.lock", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet/icon_data.lock", efreet_cache_home_get());
lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (lockfd < 0) return -1;
@ -377,7 +377,7 @@ main(int argc, char **argv)
/* FIXME: should be in cache dir maybe */
/* create homedir */
snprintf(file, sizeof(file), "%s/.efreet", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
if (!ecore_file_mkpath(file)) return -1;
/* lock process, so that we only run one copy of this program */
@ -505,7 +505,7 @@ main(int argc, char **argv)
eet_close(ef);
/* touch update file */
snprintf(file, sizeof(file), "%s/.efreet/icon_data.update", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet/icon_data.update", efreet_cache_home_get());
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (tmpfd >= 0)
{

View File

@ -23,6 +23,7 @@ void *alloca (size_t);
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include "Efreet.h"
#include "efreet_private.h"
@ -42,6 +43,7 @@ static const char *xdg_config_home = NULL;
static const char *xdg_cache_home = NULL;
static Eina_List *xdg_data_dirs = NULL;
static Eina_List *xdg_config_dirs = NULL;
static const char *hostname = NULL;
/* define macros and variable for using the eina logging system */
#ifdef EFREET_MODULE_LOG_DOM
@ -90,6 +92,8 @@ efreet_base_shutdown(void)
IF_FREE_LIST(xdg_data_dirs, eina_stringshare_del);
IF_FREE_LIST(xdg_config_dirs, eina_stringshare_del);
IF_RELEASE(hostname);
eina_log_domain_unregister(_efreet_base_log_dom);
}
@ -199,6 +203,23 @@ efreet_cache_home_get(void)
return xdg_cache_home;
}
/**
* @return Returns the current hostname
* @brief Returns the current hostname or empty string if not found
*/
EAPI const char *
efreet_hostname_get(void)
{
char buf[256];
if (hostname) return hostname;
if (gethostname(buf, sizeof(buf)) < 0)
hostname = eina_stringshare_add("");
else
hostname = eina_stringshare_add(buf);
return hostname;
}
/**
* @internal
* @param key: The environemnt key to lookup

View File

@ -17,6 +17,7 @@ EAPI const char *efreet_config_home_get(void);
EAPI Eina_List *efreet_config_dirs_get(void);
EAPI const char *efreet_cache_home_get(void);
EAPI const char *efreet_hostname_get(void);
/**
* Efreet_Event_Cache_Update

View File

@ -101,7 +101,7 @@ efreet_cache_init(void)
#endif
EFREET_EVENT_DESKTOP_CACHE_UPDATE = ecore_event_type_new();
snprintf(buf, sizeof(buf), "%s/.efreet", efreet_home_dir_get());
snprintf(buf, sizeof(buf), "%s/efreet", efreet_cache_home_get());
if (!ecore_file_mkpath(buf)) goto error;
if (efreet_cache_update)
@ -194,11 +194,11 @@ EAPI const char *
efreet_icon_cache_file(void)
{
static char cache_file[PATH_MAX] = { '\0' };
const char *home;
const char *cache;
home = efreet_home_dir_get();
cache = efreet_cache_home_get();
snprintf(cache_file, sizeof(cache_file), "%s/.efreet/icons.eet", home);
snprintf(cache_file, sizeof(cache_file), "%s/efreet/icons_%s.eet", cache, efreet_hostname_get());
return cache_file;
}
@ -233,23 +233,23 @@ EAPI const char *
efreet_desktop_cache_file(void)
{
char tmp[PATH_MAX] = { '\0' };
const char *home, *lang, *country, *modifier;
const char *cache, *lang, *country, *modifier;
if (desktop_cache_file) return desktop_cache_file;
home = efreet_home_dir_get();
cache = efreet_cache_home_get();
lang = efreet_lang_get();
country = efreet_lang_country_get();
modifier = efreet_lang_modifier_get();
if (lang && country && modifier)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_%s_%s@%s.eet", home, lang, country, modifier);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_%s_%s_%s@%s.eet", cache, efreet_hostname_get(), lang, country, modifier);
else if (lang && country)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_%s_%s.eet", home, lang, country);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_%s_%s_%s.eet", cache, efreet_hostname_get(), lang, country);
else if (lang)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_%s.eet", home, lang);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_%s_%s.eet", cache, efreet_hostname_get(), lang);
else
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop.eet", home);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_%s.eet", cache, efreet_hostname_get());
desktop_cache_file = eina_stringshare_add(tmp);
return desktop_cache_file;
@ -265,7 +265,7 @@ efreet_desktop_cache_dirs(void)
if (desktop_cache_dirs) return desktop_cache_dirs;
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_dirs.cache", efreet_home_dir_get());
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_dirs.cache", efreet_cache_home_get());
desktop_cache_dirs = eina_stringshare_add(tmp);
return desktop_cache_dirs;
@ -768,7 +768,7 @@ desktop_cache_update_cache_job(void *data __UNUSED__)
if (!efreet_desktop_write_cache_dirs_file()) return;
snprintf(file, sizeof(file), "%s/.efreet/desktop_exec.lock", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet/desktop_exec.lock", efreet_cache_home_get());
desktop_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (desktop_cache_exe_lock < 0) return;
@ -805,7 +805,7 @@ icon_cache_update_cache_job(void *data __UNUSED__)
/* TODO: Retry update cache later */
if (icon_cache_exe_lock > 0) return;
snprintf(file, sizeof(file), "%s/.efreet/icon_exec.lock", efreet_home_dir_get());
snprintf(file, sizeof(file), "%s/efreet/icon_exec.lock", efreet_cache_home_get());
icon_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (icon_cache_exe_lock < 0) return;

View File

@ -96,23 +96,23 @@ EAPI const char *
efreet_desktop_util_cache_file(void)
{
char tmp[PATH_MAX] = { '\0' };
const char *home, *lang, *country, *modifier;
const char *cache_dir, *lang, *country, *modifier;
if (cache_file) return cache_file;
home = efreet_home_dir_get();
cache_dir = efreet_cache_home_get();
lang = efreet_lang_get();
country = efreet_lang_country_get();
modifier = efreet_lang_modifier_get();
if (lang && country && modifier)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_util_%s_%s@%s.eet", home, lang, country, modifier);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s@%s.eet", cache_dir, efreet_hostname_get(), lang, country, modifier);
else if (lang && country)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_util_%s_%s.eet", home, lang, country);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s.eet", cache_dir, efreet_hostname_get(), lang, country);
else if (lang)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_util_%s.eet", home, lang);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s.eet", cache_dir, efreet_hostname_get(), lang);
else
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_util.eet", home);
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s.eet", cache_dir, efreet_hostname_get());
cache_file = eina_stringshare_add(tmp);
return cache_file;