Loading src/thumbnail.c +45 −22 Original line number Diff line number Diff line Loading @@ -582,20 +582,38 @@ int feh_thumbnail_get_thumbnail(Imlib_Image * image, feh_file * file, return status; } char *feh_thumbnail_get_name(char *uri) static char *feh_thumbnail_get_prefix() { char *home = NULL, *thumb_file = NULL, *md5_name = NULL; /* FIXME: make sure original file isn't under ~/.thumbnails */ char *dir = NULL, *home, *xdg_cache_home; md5_name = feh_thumbnail_get_name_md5(uri); // TODO: perhaps make sure that either of those paths aren't /-terminated xdg_cache_home = getenv("XDG_CACHE_HOME"); if (xdg_cache_home && xdg_cache_home[0] == '/') { dir = estrjoin("/", xdg_cache_home, "thumbnails", td.cache_dir, NULL); } else { home = getenv("HOME"); if (home) { thumb_file = estrjoin("/", home, ".thumbnails", td.cache_dir, md5_name, NULL); if (home && home[0] == '/') { dir = estrjoin("/", home, ".cache/thumbnails", td.cache_dir, NULL); } } return dir; } char *feh_thumbnail_get_name(char *uri) { char *prefix, *thumb_file = NULL, *md5_name; /* FIXME: make sure original file isn't under ~/.thumbnails */ prefix = feh_thumbnail_get_prefix(); if (prefix) { md5_name = feh_thumbnail_get_name_md5(uri); thumb_file = estrjoin("/", prefix, md5_name, NULL); free(md5_name); free(prefix); } return thumb_file; } Loading Loading @@ -847,31 +865,36 @@ int feh_thumbnail_setup_thumbnail_dir(void) { int status = 0; struct stat sb; char *dir, *dir_thumbnails, *home; char *dir, *p; home = getenv("HOME"); if (home != NULL) { dir = estrjoin("/", home, ".thumbnails", td.cache_dir, NULL); dir = feh_thumbnail_get_prefix(); if (dir) { if (!stat(dir, &sb)) { if (S_ISDIR(sb.st_mode)) status = 1; else weprintf("%s should be a directory", dir); } else { dir_thumbnails = estrjoin("/", home, ".thumbnails", NULL); if (stat(dir_thumbnails, &sb) != 0) { if (mkdir(dir_thumbnails, 0700) == -1) weprintf("unable to create directory %s", dir_thumbnails); for (p = dir + 1; *p; p++) { if (*p != '/') { continue; } free(dir_thumbnails); *p = 0; if (stat(dir, &sb) != 0) { if (mkdir(dir, 0700) == -1) { weprintf("unable to create directory %s", dir); } } *p = '/'; } if (mkdir(dir, 0700) == -1) if (stat(dir, &sb) != 0) { if (mkdir(dir, 0700) == -1) { weprintf("unable to create directory %s", dir); else status = 1; } } } free(dir); } Loading Loading
src/thumbnail.c +45 −22 Original line number Diff line number Diff line Loading @@ -582,20 +582,38 @@ int feh_thumbnail_get_thumbnail(Imlib_Image * image, feh_file * file, return status; } char *feh_thumbnail_get_name(char *uri) static char *feh_thumbnail_get_prefix() { char *home = NULL, *thumb_file = NULL, *md5_name = NULL; /* FIXME: make sure original file isn't under ~/.thumbnails */ char *dir = NULL, *home, *xdg_cache_home; md5_name = feh_thumbnail_get_name_md5(uri); // TODO: perhaps make sure that either of those paths aren't /-terminated xdg_cache_home = getenv("XDG_CACHE_HOME"); if (xdg_cache_home && xdg_cache_home[0] == '/') { dir = estrjoin("/", xdg_cache_home, "thumbnails", td.cache_dir, NULL); } else { home = getenv("HOME"); if (home) { thumb_file = estrjoin("/", home, ".thumbnails", td.cache_dir, md5_name, NULL); if (home && home[0] == '/') { dir = estrjoin("/", home, ".cache/thumbnails", td.cache_dir, NULL); } } return dir; } char *feh_thumbnail_get_name(char *uri) { char *prefix, *thumb_file = NULL, *md5_name; /* FIXME: make sure original file isn't under ~/.thumbnails */ prefix = feh_thumbnail_get_prefix(); if (prefix) { md5_name = feh_thumbnail_get_name_md5(uri); thumb_file = estrjoin("/", prefix, md5_name, NULL); free(md5_name); free(prefix); } return thumb_file; } Loading Loading @@ -847,31 +865,36 @@ int feh_thumbnail_setup_thumbnail_dir(void) { int status = 0; struct stat sb; char *dir, *dir_thumbnails, *home; char *dir, *p; home = getenv("HOME"); if (home != NULL) { dir = estrjoin("/", home, ".thumbnails", td.cache_dir, NULL); dir = feh_thumbnail_get_prefix(); if (dir) { if (!stat(dir, &sb)) { if (S_ISDIR(sb.st_mode)) status = 1; else weprintf("%s should be a directory", dir); } else { dir_thumbnails = estrjoin("/", home, ".thumbnails", NULL); if (stat(dir_thumbnails, &sb) != 0) { if (mkdir(dir_thumbnails, 0700) == -1) weprintf("unable to create directory %s", dir_thumbnails); for (p = dir + 1; *p; p++) { if (*p != '/') { continue; } free(dir_thumbnails); *p = 0; if (stat(dir, &sb) != 0) { if (mkdir(dir, 0700) == -1) { weprintf("unable to create directory %s", dir); } } *p = '/'; } if (mkdir(dir, 0700) == -1) if (stat(dir, &sb) != 0) { if (mkdir(dir, 0700) == -1) { weprintf("unable to create directory %s", dir); else status = 1; } } } free(dir); } Loading