2010-03-01 13:43:59 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2010-03-01 10:16:32 -08:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2010-03-10 13:33:43 -08:00
|
|
|
#include <sys/mman.h>
|
2010-03-01 10:16:32 -08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2010-03-02 03:26:31 -08:00
|
|
|
#include <errno.h>
|
2010-03-01 10:16:32 -08:00
|
|
|
|
|
|
|
#include <Eina.h>
|
2010-11-26 12:48:50 -08:00
|
|
|
#include <Eet.h>
|
2010-06-11 14:43:07 -07:00
|
|
|
#include <Ecore.h>
|
2010-03-01 10:16:32 -08:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
|
2011-02-05 11:56:44 -08:00
|
|
|
#define EFREET_MODULE_LOG_DOM /* no logging in this file */
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
#include "Efreet.h"
|
|
|
|
#include "efreet_private.h"
|
2010-11-27 12:15:00 -08:00
|
|
|
#include "efreet_cache_private.h"
|
2010-03-01 10:16:32 -08:00
|
|
|
|
|
|
|
static Eet_Data_Descriptor *edd = NULL;
|
|
|
|
static Eet_File *ef = NULL;
|
|
|
|
static Eet_File *util_ef = NULL;
|
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
static Eina_Hash *desktops = NULL;
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
static Eina_Hash *file_ids = NULL;
|
2010-03-01 13:43:37 -08:00
|
|
|
static Eina_Hash *paths = NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
static Eina_Hash *mime_types = NULL;
|
|
|
|
static Eina_Hash *categories = NULL;
|
|
|
|
static Eina_Hash *startup_wm_class = NULL;
|
|
|
|
static Eina_Hash *name = NULL;
|
|
|
|
static Eina_Hash *generic_name = NULL;
|
|
|
|
static Eina_Hash *comment = NULL;
|
|
|
|
static Eina_Hash *exec = NULL;
|
|
|
|
|
2010-11-16 02:31:49 -08:00
|
|
|
static int verbose = 0;
|
2010-06-01 17:19:38 -07:00
|
|
|
|
2010-03-10 13:33:43 -08:00
|
|
|
static int
|
|
|
|
strcmplen(const void *data1, const void *data2)
|
|
|
|
{
|
2010-03-29 13:14:43 -07:00
|
|
|
return strncmp(data1, data2, eina_stringshare_strlen(data2));
|
2010-03-10 13:33:43 -08:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
static int
|
2010-03-28 13:46:27 -07:00
|
|
|
cache_add(const char *path, const char *file_id, int priority __UNUSED__, int *changed)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
|
|
|
Efreet_Desktop *desk;
|
|
|
|
char *ext;
|
|
|
|
|
2010-06-01 17:19:38 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
2010-11-27 12:36:27 -08:00
|
|
|
printf("FOUND: %s\n", path);
|
|
|
|
if (file_id) printf(" (id): %s\n", file_id);
|
2010-06-01 17:19:38 -07:00
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
ext = strrchr(path, '.');
|
2010-03-13 12:58:17 -08:00
|
|
|
if (!ext || (strcmp(ext, ".desktop") && strcmp(ext, ".directory"))) return 1;
|
2010-03-29 13:11:12 -07:00
|
|
|
desk = efreet_desktop_new(path);
|
2010-06-01 17:19:38 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (desk) printf(" OK\n");
|
|
|
|
else printf(" FAIL\n");
|
|
|
|
}
|
2010-04-06 11:36:04 -07:00
|
|
|
if (!desk) return 1;
|
2010-03-30 03:51:35 -07:00
|
|
|
if (!desk->eet)
|
|
|
|
{
|
|
|
|
/* This file isn't in cache */
|
|
|
|
*changed = 1;
|
2010-06-01 17:19:38 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
printf(" NEW\n");
|
|
|
|
}
|
2010-03-30 03:51:35 -07:00
|
|
|
}
|
|
|
|
else if (ecore_file_mod_time(desk->orig_path) != desk->load_time)
|
2010-03-28 13:46:27 -07:00
|
|
|
{
|
|
|
|
efreet_desktop_free(desk);
|
|
|
|
*changed = 1;
|
|
|
|
desk = efreet_desktop_uncached_new(path);
|
2010-06-01 17:19:38 -07:00
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (desk) printf(" CHANGED\n");
|
|
|
|
else printf(" NO UNCACHED\n");
|
|
|
|
}
|
2010-03-28 13:46:27 -07:00
|
|
|
}
|
|
|
|
if (!desk) return 1;
|
2010-03-01 13:43:37 -08:00
|
|
|
if (!eina_hash_find(paths, desk->orig_path))
|
|
|
|
{
|
|
|
|
if (!eet_data_write(ef, edd, desk->orig_path, desk, 0))
|
|
|
|
return 0;
|
|
|
|
eina_hash_add(paths, desk->orig_path, (void *)1);
|
|
|
|
}
|
2010-03-01 13:43:59 -08:00
|
|
|
/* TODO: We should check priority, and not just hope we search in right order */
|
2010-11-09 13:31:46 -08:00
|
|
|
/* TODO: We need to find out if prioritized file id has changed because of
|
|
|
|
* changed search order. */
|
2010-12-09 04:19:00 -08:00
|
|
|
if (!desk->hidden && desk->type == EFREET_DESKTOP_TYPE_APPLICATION &&
|
2010-03-13 12:58:17 -08:00
|
|
|
file_id && !eina_hash_find(file_ids, file_id))
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
2011-01-31 03:32:34 -08:00
|
|
|
char *data;
|
|
|
|
Efreet_Cache_Array_String *array;
|
|
|
|
|
|
|
|
#define ADD_LIST(list, hash) \
|
|
|
|
EINA_LIST_FOREACH((list), l, data) \
|
|
|
|
{ \
|
|
|
|
array = eina_hash_find((hash), data); \
|
|
|
|
if (!array) \
|
|
|
|
array = NEW(Efreet_Cache_Array_String, 1); \
|
|
|
|
array->array = realloc(array->array, sizeof (char *) * (array->array_count + 1)); \
|
|
|
|
array->array[array->array_count++] = desk->orig_path; \
|
|
|
|
eina_hash_set((hash), data, array); \
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
#define ADD_ELEM(elem, hash) \
|
|
|
|
if ((elem)) \
|
|
|
|
{ \
|
|
|
|
data = (elem); \
|
|
|
|
array = eina_hash_find((hash), data); \
|
|
|
|
if (!array) \
|
|
|
|
array = NEW(Efreet_Cache_Array_String, 1); \
|
|
|
|
array->array = realloc(array->array, sizeof (char *) * (array->array_count + 1)); \
|
|
|
|
array->array[array->array_count++] = desk->orig_path; \
|
|
|
|
eina_hash_set((hash), data, array); \
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
ADD_LIST(desk->mime_types, mime_types);
|
|
|
|
ADD_LIST(desk->categories, categories);
|
|
|
|
ADD_ELEM(desk->startup_wm_class, startup_wm_class);
|
|
|
|
ADD_ELEM(desk->name, name);
|
|
|
|
ADD_ELEM(desk->generic_name, generic_name);
|
|
|
|
ADD_ELEM(desk->comment, comment);
|
|
|
|
ADD_ELEM(desk->exec, exec);
|
|
|
|
eina_hash_add(file_ids, file_id, desk->orig_path);
|
|
|
|
eina_hash_add(desktops, desk->orig_path, desk);
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
else
|
|
|
|
efreet_desktop_free(desk);
|
2010-03-01 10:16:32 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-03-28 13:46:27 -07:00
|
|
|
cache_scan(const char *path, const char *base_id, int priority, int recurse, int *changed)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
2010-03-10 13:34:52 -08:00
|
|
|
char *file_id = NULL;
|
|
|
|
char id[PATH_MAX];
|
2010-03-01 10:16:32 -08:00
|
|
|
char buf[PATH_MAX];
|
|
|
|
DIR *files;
|
2010-11-23 08:49:46 -08:00
|
|
|
struct dirent *ent;
|
2010-03-01 10:16:32 -08:00
|
|
|
|
|
|
|
if (!ecore_file_is_dir(path)) return 1;
|
|
|
|
|
|
|
|
files = opendir(path);
|
2010-04-17 11:39:13 -07:00
|
|
|
if (!files) return 1;
|
2010-03-10 13:34:52 -08:00
|
|
|
id[0] = '\0';
|
2010-11-23 08:49:46 -08:00
|
|
|
while ((ent = readdir(files)))
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
2010-11-23 08:49:46 -08:00
|
|
|
if (!ent) break;
|
|
|
|
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue;
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2010-03-10 13:34:52 -08:00
|
|
|
if (base_id)
|
|
|
|
{
|
|
|
|
if (*base_id)
|
2010-11-23 08:49:46 -08:00
|
|
|
snprintf(id, sizeof(id), "%s-%s", base_id, ent->d_name);
|
2010-03-10 13:34:52 -08:00
|
|
|
else
|
2010-11-23 08:49:46 -08:00
|
|
|
strcpy(id, ent->d_name);
|
2010-03-10 13:34:52 -08:00
|
|
|
file_id = id;
|
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2010-11-23 08:49:46 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", path, ent->d_name);
|
2010-03-01 10:16:32 -08:00
|
|
|
if (ecore_file_is_dir(buf))
|
|
|
|
{
|
2010-03-10 13:34:52 -08:00
|
|
|
if (recurse)
|
2010-03-28 13:46:27 -07:00
|
|
|
cache_scan(buf, file_id, priority, recurse, changed);
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-28 08:11:20 -07:00
|
|
|
if (!cache_add(buf, file_id, priority, changed))
|
|
|
|
{
|
|
|
|
closedir(files);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(files);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-06-01 17:19:38 -07:00
|
|
|
main(int argc, char **argv)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
|
|
|
/* TODO:
|
|
|
|
* - Add file monitor on files, so that we catch changes on files
|
|
|
|
* during whilst this program runs.
|
2010-04-01 12:40:53 -07:00
|
|
|
* - Maybe linger for a while to reduce number of cache re-creates.
|
2010-03-01 10:16:32 -08:00
|
|
|
*/
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash hash;
|
2010-12-02 00:34:07 -08:00
|
|
|
Efreet_Cache_Version version;
|
2010-03-10 13:33:43 -08:00
|
|
|
Eina_List *dirs = NULL, *user_dirs = NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
int priority = 0;
|
|
|
|
char *dir = NULL;
|
2010-03-29 13:14:43 -07:00
|
|
|
char *path;
|
2010-11-23 05:30:17 -08:00
|
|
|
int lockfd = -1, tmpfd, dirsfd = -1;
|
2010-03-10 13:33:43 -08:00
|
|
|
struct stat st;
|
2010-03-28 13:46:27 -07:00
|
|
|
int changed = 0;
|
2010-06-01 17:19:38 -07:00
|
|
|
int i;
|
2010-06-11 14:43:07 -07:00
|
|
|
struct flock fl;
|
2010-12-08 13:39:23 -08:00
|
|
|
char file[PATH_MAX] = { '\0' };
|
|
|
|
char util_file[PATH_MAX] = { '\0' };
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2010-06-01 17:19:38 -07:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(argv[i], "-v")) verbose = 1;
|
|
|
|
else if ((!strcmp(argv[i], "-h")) ||
|
|
|
|
(!strcmp(argv[i], "-help")) ||
|
|
|
|
(!strcmp(argv[i], "--h")) ||
|
|
|
|
(!strcmp(argv[i], "--help")))
|
|
|
|
{
|
|
|
|
printf("Options:\n");
|
|
|
|
printf(" -v Verbose mode\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
/* init external subsystems */
|
|
|
|
if (!eina_init()) goto eina_error;
|
2010-03-03 17:00:06 -08:00
|
|
|
if (!eet_init()) goto eet_error;
|
2010-11-23 08:49:46 -08:00
|
|
|
if (!ecore_init()) goto ecore_error;
|
|
|
|
|
2010-03-28 11:54:25 -07:00
|
|
|
efreet_cache_update = 0;
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
/* create homedir */
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!ecore_file_mkpath(file)) goto efreet_error;
|
|
|
|
|
2010-03-02 03:26:31 -08:00
|
|
|
/* lock process, so that we only run one copy of this program */
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(file, sizeof(file), "%s/efreet/desktop_data.lock", efreet_cache_home_get());
|
2010-11-23 05:30:17 -08:00
|
|
|
lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
|
|
|
if (lockfd < 0) goto efreet_error;
|
2010-06-11 14:43:07 -07:00
|
|
|
memset(&fl, 0, sizeof(struct flock));
|
|
|
|
fl.l_type = F_WRLCK;
|
|
|
|
fl.l_whence = SEEK_SET;
|
2010-11-23 05:30:17 -08:00
|
|
|
if (fcntl(lockfd, F_SETLK, &fl) < 0)
|
2010-06-01 17:19:38 -07:00
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
printf("LOCKED! You may want to delete %s if this persists\n", file);
|
|
|
|
}
|
|
|
|
goto efreet_error;
|
|
|
|
}
|
2010-03-02 03:26:31 -08:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
/* finish efreet init */
|
|
|
|
if (!efreet_init()) goto efreet_error;
|
2010-12-02 00:32:22 -08:00
|
|
|
edd = efreet_desktop_edd();
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!edd) goto edd_error;
|
|
|
|
|
|
|
|
/* create cache */
|
2010-03-01 11:05:49 -08:00
|
|
|
snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file());
|
|
|
|
tmpfd = mkstemp(file);
|
|
|
|
if (tmpfd < 0) goto error;
|
|
|
|
close(tmpfd);
|
2010-12-03 06:53:11 -08:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!ef) goto error;
|
2010-03-01 11:05:49 -08:00
|
|
|
|
2010-03-03 04:28:40 -08:00
|
|
|
snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file());
|
2010-03-01 11:05:49 -08:00
|
|
|
tmpfd = mkstemp(util_file);
|
|
|
|
if (tmpfd < 0) goto error;
|
|
|
|
close(tmpfd);
|
2010-12-03 06:53:11 -08:00
|
|
|
util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!util_ef) goto error;
|
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
/* write cache version */
|
|
|
|
version.major = EFREET_DESKTOP_UTILS_CACHE_MAJOR;
|
|
|
|
version.minor = EFREET_DESKTOP_UTILS_CACHE_MINOR;
|
|
|
|
eet_data_write(util_ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1);
|
|
|
|
version.major = EFREET_DESKTOP_CACHE_MAJOR;
|
|
|
|
version.minor = EFREET_DESKTOP_CACHE_MINOR;
|
|
|
|
eet_data_write(ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1);
|
|
|
|
|
|
|
|
desktops = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_desktop_free));
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
file_ids = eina_hash_string_superfast_new(NULL);
|
2010-03-01 13:43:37 -08:00
|
|
|
paths = eina_hash_string_superfast_new(NULL);
|
2011-01-31 03:32:34 -08:00
|
|
|
|
|
|
|
mime_types = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
|
|
|
categories = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
|
|
|
startup_wm_class = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
|
|
|
name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
|
|
|
generic_name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
|
|
|
comment = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
|
|
|
exec = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
|
2010-03-01 10:16:32 -08:00
|
|
|
|
|
|
|
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
|
|
|
|
"applications");
|
|
|
|
if (!dirs) goto error;
|
2010-03-10 13:33:43 -08:00
|
|
|
|
|
|
|
dirsfd = open(efreet_desktop_cache_dirs(), O_APPEND | O_RDWR, S_IRUSR | S_IWUSR);
|
2010-08-29 01:47:37 -07:00
|
|
|
if (dirsfd >= 0)
|
2010-03-10 13:33:43 -08:00
|
|
|
{
|
2010-08-29 01:47:37 -07:00
|
|
|
if ((fstat(dirsfd, &st) == 0) && (st.st_size > 0))
|
2010-03-10 13:33:43 -08:00
|
|
|
{
|
2010-08-29 01:47:37 -07:00
|
|
|
char *p;
|
|
|
|
char *map;
|
|
|
|
|
|
|
|
map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, dirsfd, 0);
|
|
|
|
if (map == MAP_FAILED) goto error;
|
|
|
|
p = map;
|
|
|
|
while (p < map + st.st_size)
|
|
|
|
{
|
|
|
|
unsigned int size = *(unsigned int *)p;
|
|
|
|
p += sizeof(unsigned int);
|
|
|
|
user_dirs = eina_list_append(user_dirs, eina_stringshare_add(p));
|
|
|
|
p += size;
|
|
|
|
}
|
|
|
|
munmap(map, st.st_size);
|
2010-03-10 13:33:43 -08:00
|
|
|
}
|
2010-04-06 11:35:35 -07:00
|
|
|
close(dirsfd);
|
|
|
|
dirsfd = -1;
|
|
|
|
unlink(efreet_desktop_cache_dirs());
|
2010-03-10 13:33:43 -08:00
|
|
|
}
|
|
|
|
|
2010-03-29 13:14:43 -07:00
|
|
|
EINA_LIST_FREE(dirs, path)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
|
|
|
char file_id[PATH_MAX] = { '\0' };
|
2010-03-10 13:33:43 -08:00
|
|
|
Eina_List *l;
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2010-03-29 13:14:43 -07:00
|
|
|
if (!cache_scan(path, file_id, priority++, 1, &changed)) goto error;
|
|
|
|
l = eina_list_search_unsorted_list(user_dirs, strcmplen, path);
|
|
|
|
if (l)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
2010-03-29 13:14:43 -07:00
|
|
|
eina_stringshare_del(eina_list_data_get(l));
|
|
|
|
user_dirs = eina_list_remove_list(user_dirs, l);
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2010-03-29 13:14:43 -07:00
|
|
|
eina_stringshare_del(path);
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2010-04-06 11:35:35 -07:00
|
|
|
if (user_dirs)
|
2010-03-10 13:33:43 -08:00
|
|
|
{
|
2010-04-06 11:35:35 -07:00
|
|
|
dirsfd = open(efreet_desktop_cache_dirs(), O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
|
|
|
|
if (dirsfd < 0) goto error;
|
|
|
|
EINA_LIST_FREE(user_dirs, dir)
|
2010-03-10 13:33:43 -08:00
|
|
|
{
|
|
|
|
unsigned int size = strlen(dir) + 1;
|
2010-06-24 12:34:15 -07:00
|
|
|
size_t count;
|
2010-06-24 09:17:45 -07:00
|
|
|
|
|
|
|
count = write(dirsfd, &size, sizeof(int));
|
|
|
|
count += write(dirsfd, dir, size);
|
|
|
|
|
2010-06-24 12:34:15 -07:00
|
|
|
if (count != sizeof (int) + size)
|
|
|
|
printf("Didn't write all data on dirsfd");
|
2010-04-06 11:35:35 -07:00
|
|
|
|
|
|
|
if (!cache_scan(dir, NULL, priority, 0, &changed)) goto error;
|
|
|
|
eina_stringshare_del(dir);
|
2010-03-10 13:33:43 -08:00
|
|
|
}
|
2010-04-06 11:35:35 -07:00
|
|
|
close(dirsfd);
|
|
|
|
dirsfd = -1;
|
2010-03-10 13:33:43 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
|
|
|
|
/* store util */
|
|
|
|
#define STORE_HASH_ARRAY(_hash) \
|
|
|
|
if (eina_hash_population((_hash)) > 0) \
|
|
|
|
{ \
|
|
|
|
Eina_Iterator *it; \
|
|
|
|
Efreet_Cache_Array_String array; \
|
|
|
|
const char *str; \
|
|
|
|
\
|
|
|
|
hash.hash = (_hash); \
|
|
|
|
eet_data_write(util_ef, efreet_hash_array_string_edd(), #_hash "_hash", &hash, 1); \
|
|
|
|
printf("key: %s = %d\n", #_hash, eina_hash_population(hash.hash)); \
|
|
|
|
array.array_count = 0; \
|
|
|
|
array.array = malloc(eina_hash_population(hash.hash) * sizeof(char *)); \
|
|
|
|
it = eina_hash_iterator_key_new(hash.hash); \
|
|
|
|
EINA_ITERATOR_FOREACH(it, str) \
|
|
|
|
array.array[array.array_count++] = str; \
|
|
|
|
eina_iterator_free(it); \
|
|
|
|
eet_data_write(util_ef, efreet_array_string_edd(), #_hash "_list", &array, 1); \
|
|
|
|
}
|
|
|
|
STORE_HASH_ARRAY(mime_types);
|
|
|
|
STORE_HASH_ARRAY(categories);
|
|
|
|
STORE_HASH_ARRAY(startup_wm_class);
|
|
|
|
STORE_HASH_ARRAY(name);
|
|
|
|
STORE_HASH_ARRAY(generic_name);
|
|
|
|
STORE_HASH_ARRAY(comment);
|
|
|
|
STORE_HASH_ARRAY(exec);
|
|
|
|
if (eina_hash_population(file_ids) > 0)
|
|
|
|
{
|
|
|
|
hash.hash = file_ids;
|
|
|
|
eet_data_write(util_ef, efreet_hash_string_edd(), "file_id", &hash, 1);
|
|
|
|
printf("key: file_id = %d\n", eina_hash_population(file_ids));
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_hash_free(mime_types);
|
|
|
|
eina_hash_free(categories);
|
|
|
|
eina_hash_free(startup_wm_class);
|
|
|
|
eina_hash_free(name);
|
|
|
|
eina_hash_free(generic_name);
|
|
|
|
eina_hash_free(comment);
|
|
|
|
eina_hash_free(exec);
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
eina_hash_free(file_ids);
|
2010-03-01 13:43:37 -08:00
|
|
|
eina_hash_free(paths);
|
2010-03-30 03:51:45 -07:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
eina_hash_free(desktops);
|
2011-01-27 12:21:16 -08:00
|
|
|
|
2010-03-30 03:51:45 -07:00
|
|
|
/* check if old and new caches contain the same number of entries */
|
|
|
|
if (!changed)
|
|
|
|
{
|
|
|
|
Eet_File *old;
|
|
|
|
|
|
|
|
old = eet_open(efreet_desktop_cache_file(), EET_FILE_MODE_READ);
|
|
|
|
if (!old || eet_num_entries(old) != eet_num_entries(ef)) changed = 1;
|
|
|
|
if (old) eet_close(old);
|
|
|
|
old = eet_open(efreet_desktop_util_cache_file(), EET_FILE_MODE_READ);
|
|
|
|
if (!old || eet_num_entries(old) != eet_num_entries(util_ef)) changed = 1;
|
|
|
|
if (old) eet_close(old);
|
|
|
|
}
|
2010-08-29 01:47:37 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
/* cleanup */
|
|
|
|
eet_close(util_ef);
|
|
|
|
eet_close(ef);
|
|
|
|
|
2010-03-28 12:31:26 -07:00
|
|
|
/* unlink old cache files */
|
2010-03-28 13:46:27 -07:00
|
|
|
if (changed)
|
2010-03-28 12:31:26 -07:00
|
|
|
{
|
2010-03-28 13:46:27 -07:00
|
|
|
if (unlink(efreet_desktop_cache_file()) < 0)
|
|
|
|
{
|
|
|
|
if (errno != ENOENT) goto error;
|
|
|
|
}
|
|
|
|
if (unlink(efreet_desktop_util_cache_file()) < 0)
|
|
|
|
{
|
|
|
|
if (errno != ENOENT) goto error;
|
|
|
|
}
|
|
|
|
/* rename tmp files to real files */
|
|
|
|
if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error;
|
|
|
|
if (rename(file, efreet_desktop_cache_file()) < 0) goto error;
|
2010-03-28 12:31:26 -07:00
|
|
|
}
|
2010-03-28 13:46:27 -07:00
|
|
|
else
|
2010-03-28 12:31:26 -07:00
|
|
|
{
|
2010-03-28 13:46:27 -07:00
|
|
|
unlink(util_file);
|
|
|
|
unlink(file);
|
2010-03-28 12:31:26 -07:00
|
|
|
}
|
2010-03-01 11:05:49 -08:00
|
|
|
|
2010-11-23 08:49:46 -08:00
|
|
|
/* touch update file */
|
2011-01-27 12:21:16 -08:00
|
|
|
/* TODO: We need to signal whether the cache was updated or not */
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(file, sizeof(file), "%s/efreet/desktop_data.update", efreet_cache_home_get());
|
2010-11-24 01:37:35 -08:00
|
|
|
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
|
2010-11-23 08:49:46 -08:00
|
|
|
if (tmpfd >= 0)
|
|
|
|
{
|
2011-01-16 00:12:51 -08:00
|
|
|
if (write(tmpfd, "a", 1) != 1) perror("write");
|
2010-11-23 08:49:46 -08:00
|
|
|
close(tmpfd);
|
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
efreet_shutdown();
|
2010-06-01 17:19:38 -07:00
|
|
|
ecore_shutdown();
|
2010-03-01 10:16:32 -08:00
|
|
|
eet_shutdown();
|
|
|
|
eina_shutdown();
|
2010-11-23 05:30:17 -08:00
|
|
|
close(lockfd);
|
2010-03-01 10:16:32 -08:00
|
|
|
return 0;
|
|
|
|
error:
|
2010-08-29 01:47:37 -07:00
|
|
|
if (dirsfd >= 0) close(dirsfd);
|
2010-03-01 10:16:32 -08:00
|
|
|
IF_FREE(dir);
|
|
|
|
edd_error:
|
|
|
|
efreet_shutdown();
|
|
|
|
efreet_error:
|
2010-11-23 08:49:46 -08:00
|
|
|
ecore_shutdown();
|
|
|
|
ecore_error:
|
2010-03-01 10:16:32 -08:00
|
|
|
eet_shutdown();
|
|
|
|
eet_error:
|
2010-03-03 17:00:06 -08:00
|
|
|
eina_shutdown();
|
|
|
|
eina_error:
|
2010-11-23 05:30:17 -08:00
|
|
|
if (lockfd >= 0) close(lockfd);
|
2010-03-01 10:16:32 -08:00
|
|
|
return 1;
|
|
|
|
}
|