resolve symlinks...

SVN revision: 6556
This commit is contained in:
Carsten Haitzler 2003-01-10 02:05:37 +00:00
parent 6494104a2b
commit 8e3e8c5848
5 changed files with 53 additions and 13 deletions

View File

@ -1097,7 +1097,10 @@ evas_common_load_image_from_file(const char *file, const char *key)
} }
im->timestamp = mod_time; im->timestamp = mod_time;
if (file) if (file)
im->info.file = strdup(file); {
im->info.file = strdup(file);
im->info.real_file = evas_file_path_resolve(file);
}
if (key) if (key)
im->info.key = strdup(key); im->info.key = strdup(key);
evas_common_image_ref(im); evas_common_image_ref(im);

View File

@ -138,6 +138,7 @@ evas_common_image_free(RGBA_Image *im)
} }
if (im->mipmaps.levels) free(im->mipmaps.levels); if (im->mipmaps.levels) free(im->mipmaps.levels);
if (im->info.file) free(im->info.file); if (im->info.file) free(im->info.file);
if (im->info.real_file) free(im->info.real_file);
if (im->info.key) free(im->info.key); if (im->info.key) free(im->info.key);
if (im->info.comment) free(im->info.comment); if (im->info.comment) free(im->info.comment);
free(im); free(im);
@ -244,7 +245,8 @@ evas_common_image_store(RGBA_Image *im)
if (im->flags & RGBA_IMAGE_INDEXED) return; if (im->flags & RGBA_IMAGE_INDEXED) return;
if ((!im->info.file) && (!im->info.key)) return; if ((!im->info.file) && (!im->info.key)) return;
l1 = 0; l1 = 0;
if (im->info.file) l1 = strlen(im->info.file); if (im->info.real_file) l1 = strlen(im->info.real_file);
else if (im->info.file) l1 = strlen(im->info.file);
l2 = 0; l2 = 0;
if (im->info.key) l2 = strlen(im->info.key); if (im->info.key) l2 = strlen(im->info.key);
snprintf(buf, sizeof(buf), "%llx", im->timestamp); snprintf(buf, sizeof(buf), "%llx", im->timestamp);
@ -252,7 +254,8 @@ evas_common_image_store(RGBA_Image *im)
key = malloc(l1 + 3 + l2 + 3 + l3 +1); key = malloc(l1 + 3 + l2 + 3 + l3 +1);
if (!key) return; if (!key) return;
key[0] = 0; key[0] = 0;
if (im->info.file) strcpy(key, im->info.file); if (im->info.real_file) strcpy(key, im->info.real_file);
else if (im->info.file) strcpy(key, im->info.file);
strcat(key, "/:/"); strcat(key, "/:/");
if (im->info.key) strcat(key, im->info.key); if (im->info.key) strcat(key, im->info.key);
strcat(key, "/:/"); strcat(key, "/:/");
@ -272,7 +275,8 @@ evas_common_image_unstore(RGBA_Image *im)
if (!(im->flags & RGBA_IMAGE_INDEXED)) return; if (!(im->flags & RGBA_IMAGE_INDEXED)) return;
if ((!im->info.file) && (!im->info.key)) return; if ((!im->info.file) && (!im->info.key)) return;
l1 = 0; l1 = 0;
if (im->info.file) l1 = strlen(im->info.file); if (im->info.real_file) l1 = strlen(im->info.real_file);
else if (im->info.file) l1 = strlen(im->info.file);
l2 = 0; l2 = 0;
if (im->info.key) l2 = strlen(im->info.key); if (im->info.key) l2 = strlen(im->info.key);
snprintf(buf, sizeof(buf), "%llx", im->timestamp); snprintf(buf, sizeof(buf), "%llx", im->timestamp);
@ -280,7 +284,8 @@ evas_common_image_unstore(RGBA_Image *im)
key = malloc(l1 + 3 + l2 + 3 + l3 +1); key = malloc(l1 + 3 + l2 + 3 + l3 +1);
if (!key) return; if (!key) return;
key[0] = 0; key[0] = 0;
if (im->info.file) strcpy(key, im->info.file); if (im->info.real_file) strcpy(key, im->info.real_file);
else if (im->info.file) strcpy(key, im->info.file);
strcat(key, "/:/"); strcat(key, "/:/");
if (im->info.key) strcat(key, im->info.key); if (im->info.key) strcat(key, im->info.key);
strcat(key, "/:/"); strcat(key, "/:/");
@ -294,6 +299,7 @@ evas_common_image_unstore(RGBA_Image *im)
RGBA_Image * RGBA_Image *
evas_common_image_find(const char *filename, const char *key, DATA64 timestamp) evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
{ {
char *real_filename;
Evas_Object_List *l; Evas_Object_List *l;
RGBA_Image *im; RGBA_Image *im;
char *str; char *str;
@ -301,8 +307,10 @@ evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
char buf[256]; char buf[256];
if ((!filename) && (!key)) return NULL; if ((!filename) && (!key)) return NULL;
real_filename = evas_file_path_resolve(filename);
l1 = 0; l1 = 0;
if (filename) l1 = strlen(filename); if (real_filename) l1 = strlen(real_filename);
else if (filename) l1 = strlen(filename);
l2 = 0; l2 = 0;
if (key) l2 = strlen(key); if (key) l2 = strlen(key);
sprintf(buf, "%llx", timestamp); sprintf(buf, "%llx", timestamp);
@ -325,11 +333,20 @@ evas_common_image_find(const char *filename, const char *key, DATA64 timestamp)
im = (RGBA_Image *)l; im = (RGBA_Image *)l;
ok = 0; ok = 0;
if ((filename) && (im->info.file) && if (real_filename)
(!strcmp(filename, im->info.file))) {
ok++; if ((im->info.real_file) &&
if ((!filename) && (!im->info.file)) (!strcmp(real_filename, im->info.real_file)))
ok++; ok++;
}
else
{
if ((filename) && (im->info.file) &&
(!strcmp(filename, im->info.file)))
ok++;
if ((!filename) && (!im->info.file))
ok++;
}
if ((key) && (im->info.key) && if ((key) && (im->info.key) &&
(!strcmp(key, im->info.key))) (!strcmp(key, im->info.key)))
ok++; ok++;
@ -350,6 +367,7 @@ evas_common_image_ram_usage(RGBA_Image *im)
ram += sizeof(struct _RGBA_Image); ram += sizeof(struct _RGBA_Image);
if (im->info.file) ram += strlen(im->info.file); if (im->info.file) ram += strlen(im->info.file);
if (im->info.real_file) ram += strlen(im->info.real_file);
if (im->info.key) ram += strlen(im->info.key); if (im->info.key) ram += strlen(im->info.key);
if (im->info.comment) ram += strlen(im->info.comment); if (im->info.comment) ram += strlen(im->info.comment);
if ((im->image) && (im->image->data) && (!im->image->no_free)) if ((im->image) && (im->image->data) && (!im->image->no_free))

View File

@ -8,9 +8,12 @@
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
/* get the casefold feature! */ /* get the casefold feature! */
#define _GNU_SOURCE #define _GNU_SOURCE
#include <fnmatch.h> #include <fnmatch.h>
@ -120,6 +123,15 @@ evas_file_modified_time(const char *file)
return 0; return 0;
} }
char *
evas_file_path_resolve(const char *file)
{
char buf[PATH_MAX], *buf2;
if (!realpath(file, buf)) return NULL;
buf2 = strdup(buf);
return buf2;
}
#else #else
@ -327,7 +339,6 @@ evas_file_path_list(char *path, char *match, int match_case)
return files; return files;
} }
DATA64 DATA64
evas_file_modified_time(const char *file) evas_file_modified_time(const char *file)
{ {
@ -353,4 +364,10 @@ evas_file_modified_time(const char *file)
return modtime.QuadPart; return modtime.QuadPart;
} }
char *
evas_file_path_resolve(const char *file)
{
return strdup(file);
}
#endif #endif

View File

@ -265,6 +265,7 @@ struct _RGBA_Image
{ {
int format; int format;
char *file; char *file;
char *real_file;
char *key; char *key;
char *comment; char *comment;
} info; } info;

View File

@ -521,6 +521,7 @@ int evas_file_path_is_file(char *path);
int evas_file_path_is_dir(char *path); int evas_file_path_is_dir(char *path);
Evas_List *evas_file_path_list(char *path, char *match, int match_case); Evas_List *evas_file_path_list(char *path, char *match, int match_case);
DATA64 evas_file_modified_time(const char *file); DATA64 evas_file_modified_time(const char *file);
char *evas_file_path_resolve(const char *file);
int evas_mem_free(int mem_required); int evas_mem_free(int mem_required);
int evas_mem_degrade(int mem_required); int evas_mem_degrade(int mem_required);
void evas_debug_error(void); void evas_debug_error(void);