nsxivf93f4d8
Write cache file for thumbnail directly after creating it
+12 −10
2 files changed
| @@ -47,17 +47,12 @@ void tns_init(tns_t *tns, int cnt) { | |||
| 47 | 47 | ||
| 48 | 48 | void tns_free(tns_t *tns, win_t *win) { | |
| 49 | 49 | int i; | |
| 50 | − | Bool cache; | |
| 51 | 50 | ||
| 52 | 51 | if (!tns || !tns->thumbs) | |
| 53 | 52 | return; | |
| 54 | 53 | ||
| 55 | − | cache = tns_cache_enabled(); | |
| 56 | − | ||
| 57 | 54 | for (i = 0; i < tns->cnt; ++i) { | |
| 58 | 55 | if (tns->thumbs[i].im) { | |
| 59 | − | if (cache) | |
| 60 | − | tns_cache_write(&tns->thumbs[i], False); | |
| 61 | 56 | imlib_context_set_image(tns->thumbs[i].im); | |
| 62 | 57 | imlib_free_image(); | |
| 63 | 58 | } | |
| @@ -69,6 +64,7 @@ void tns_free(tns_t *tns, win_t *win) { | |||
| 69 | 64 | ||
| 70 | 65 | void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |
| 71 | 66 | int w, h; | |
| 67 | + | int use_cache, cached = 0; | |
| 72 | 68 | float z, zw, zh; | |
| 73 | 69 | thumb_t *t; | |
| 74 | 70 | Imlib_Image *im; | |
| @@ -88,8 +84,12 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 88 | 84 | imlib_free_image(); | |
| 89 | 85 | } | |
| 90 | 86 | ||
| 91 | − | if ((tns_cache_enabled() && (im = tns_cache_load(filename))) || | |
| 92 | − | (im = imlib_load_image(filename))) | |
| 87 | + | if ((use_cache = tns_cache_enabled())) { | |
| 88 | + | if ((im = tns_cache_load(filename))) | |
| 89 | + | cached = 1; | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | if (cached || (im = imlib_load_image(filename))) | |
| 93 | 93 | imlib_context_set_image(im); | |
| 94 | 94 | else | |
| 95 | 95 | imlib_context_set_image(im_invalid); | |
| @@ -115,6 +115,8 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 115 | 115 | die("could not allocate memory"); | |
| 116 | 116 | if (im) | |
| 117 | 117 | imlib_free_image_and_decache(); | |
| 118 | + | if (use_cache && !cached) | |
| 119 | + | tns_cache_write(t, False); | |
| 118 | 120 | ||
| 119 | 121 | tns->dirty = 1; | |
| 120 | 122 | } | |
| @@ -334,7 +336,7 @@ char* tns_cache_filename(const char *filename) { | |||
| 334 | 336 | } | |
| 335 | 337 | ||
| 336 | 338 | len = strlen(abspath); | |
| 337 | − | for (i = 1; i < len; ++i) { | |
| 339 | + | for (i = 0; i < len; ++i) { | |
| 338 | 340 | if (abspath[i] == '/') | |
| 339 | 341 | abspath[i] = '%'; | |
| 340 | 342 | } | |
| @@ -392,7 +394,7 @@ void tns_cache_write(thumb_t *t, Bool force) { | |||
| 392 | 394 | imlib_save_image_with_error_return(cfile, &err); | |
| 393 | 395 | ||
| 394 | 396 | if (err) { | |
| 395 | − | warn("could not cache thumbnail:", t->filename); | |
| 397 | + | warn("could not cache thumbnail: %s", t->filename); | |
| 396 | 398 | } else { | |
| 397 | 399 | TIMESPEC_TO_TIMEVAL(×[0], &fstats.st_atim); | |
| 398 | 400 | TIMESPEC_TO_TIMEVAL(×[1], &fstats.st_mtim); | |
| @@ -123,7 +123,7 @@ char* absolute_path(const char *filename) { | |||
| 123 | 123 | twd = (char*) s_realloc(twd, len); | |
| 124 | 124 | } | |
| 125 | 125 | if (chdir(cwd)) | |
| 126 | − | die("could not revert to working directory"); | |
| 126 | + | die("could not revert to prior working directory"); | |
| 127 | 127 | if (!s) | |
| 128 | 128 | goto error; | |
| 129 | 129 | dir = twd; | |