From ab067f4fc55b644a7c098b959818a0e54c4f3347 Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Sun, 12 Aug 2001 13:41:11 +0000 Subject: [PATCH] This is what I meant. I have tested: feh test:image.jpg WORKS imlib2_view e/data/icons/image/png.db:/icon/clicked WORKS I have tested saving with geist too and that works. The patch is bigger than it would have been because I had to revert some of raster's attempt. There is more debris left over (unused functions and params etc) but I won't clean all that out until people have checked out this and are happy. I might make something like imlib_get_real_filename available in the public API. So that apps (like feh) that use stat() that do their own error checking can also do the right thing, but this is a separate issue and not totally necessary. SVN revision: 5122 --- loaders/loader_db.c | 12 +++++++++--- src/file.c | 19 +++++++++++++------ src/file.h | 1 + src/image.c | 14 +++++++++++--- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/loaders/loader_db.c b/loaders/loader_db.c index d06722d..ba54172 100644 --- a/loaders/loader_db.c +++ b/loaders/loader_db.c @@ -258,7 +258,7 @@ save (ImlibImage *im, ImlibProgressFunction progress, char progress_granularity) { int alpha = 0; - char file[4096], key[4096], *cp; + char file[4096], key[4096], *cp, *tmp; DATA32 *header; DATA32 *buf; E_DB_File *db; @@ -271,10 +271,16 @@ save (ImlibImage *im, ImlibProgressFunction progress, return 0; if (im->flags & F_HAS_ALPHA) alpha = 1; - if ((!im->file) || (!im->real_file) || (!im->key)) + if ((!im->file) || (!im->real_file)) return 0; strcpy(file, im->real_file); - strcpy(key, im->key); + + tmp = strrchr(file, ':'); + if(!tmp) + return 0; + *tmp = '\0'; + strcpy(key, tmp + 1); + if (exists(file)) { if (!can_write(file)) return 0; diff --git a/src/file.c b/src/file.c index cca5689..eebe2e0 100644 --- a/src/file.c +++ b/src/file.c @@ -119,7 +119,7 @@ __imlib_FileExists(const char *s, int raw) char *fl; if ((!s) || (!*s)) return 0; - if (raw) fl = strdup(s); + if (__imlib_IsRealFile(s)) fl = strdup(s); else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) @@ -138,7 +138,7 @@ __imlib_FileIsFile(const char *s, int raw) char *fl; if ((!s) || (!*s)) return 0; - if (raw) fl = strdup(s); + if (__imlib_IsRealFile(s)) fl = strdup(s); else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) @@ -162,7 +162,7 @@ __imlib_FileIsDir(const char *s, int raw) char *fl; if ((!s) || (!*s)) return 0; - if (raw) fl = strdup(s); + if (__imlib_IsRealFile(s)) fl = strdup(s); else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) @@ -186,7 +186,7 @@ __imlib_FilePermissions(const char *s, int raw) char *fl; if ((!s) || (!*s)) return 0; - if (raw) fl = strdup(s); + if (__imlib_IsRealFile(s)) fl = strdup(s); else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) @@ -204,7 +204,7 @@ __imlib_FileCanRead(const char *s, int raw) char *fl; int val; - if (raw) fl = strdup(s); + if (__imlib_IsRealFile(s)) fl = strdup(s); else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (!(__imlib_FilePermissions(fl, 1) & (S_IRUSR | S_IRGRP | S_IROTH))) @@ -306,6 +306,13 @@ __imlib_FileDel(char *s) return; } +int +__imlib_IsRealFile(const char *s) +{ + struct stat st; + return ((stat(s, &st) != -1) && (!S_ISREG(st.st_mode))); +} + time_t __imlib_FileModDate(const char *s, int raw) { @@ -313,7 +320,7 @@ __imlib_FileModDate(const char *s, int raw) char *fl; if ((!s) || (!*s)) return 0; - if (raw) fl = strdup(s); + if (__imlib_IsRealFile(s)) fl = strdup(s); else fl = __imlib_FileRealFile(s); if (!fl) return 0; if (stat(fl, &st) < 0) diff --git a/src/file.h b/src/file.h index 275b0be..4fc787d 100644 --- a/src/file.h +++ b/src/file.h @@ -14,6 +14,7 @@ char *__imlib_FileHomeDir(int uid); char *__imlib_FileField(char *s, int field); int __imlib_FilePermissions(const char *s, int raw); int __imlib_FileCanRead(const char *s, int raw); +int __imlib_IsRealFile(const char *s); #endif diff --git a/src/image.c b/src/image.c index b447c40..231132d 100644 --- a/src/image.c +++ b/src/image.c @@ -1024,6 +1024,7 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress, ImlibImage *im; ImlibLoader *best_loader; char loader_ret = 0; + struct stat st; if (!file) return NULL; if (file[0] == 0) return NULL; @@ -1063,13 +1064,16 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress, /* so produce a new one and load an image into that */ im = __imlib_ProduceImage(); im->file = strdup(file); - if (raw_file_mode) + printf("file is %s\n", file); + if(__imlib_IsRealFile(file)) { + printf("file %s exists\n", file); im->real_file = strdup(im->file); im->key = NULL; } else { + printf("file %s does not exist\n", file); im->real_file = __imlib_FileRealFile(file); im->key = __imlib_FileKey(file); } @@ -1315,7 +1319,9 @@ __imlib_SaveImage(ImlibImage * im, const char *file, /* set the filename to the saved one */ pfile = im->file; im->file = strdup(file); - if (raw_file_mode) + im->real_file = strdup(im->file); + +/* if (raw_file_mode) { if (im->real_file) free(im->real_file); if (im->key) free(im->key); @@ -1328,7 +1334,9 @@ __imlib_SaveImage(ImlibImage * im, const char *file, im->real_file = __imlib_FileRealFile(file); if (im->key) free(im->key); im->key = __imlib_FileKey(file); - } + } + */ + /* find the laoder for the format - if its null use the extension */ l = __imlib_FindBestLoaderForFileFormat(im->real_file, im->format); /* no loader - abort */