| @@ -327,7 +327,6 @@ int tns_cache_enabled() { |
| 327 | 327 | | |
| 328 | 328 | | char* tns_cache_filename(const char *filename) { |
| 329 | 329 | | size_t len; |
| 330 | | − | int i; |
| 331 | 330 | | char *cfile, *abspath; |
| 332 | 331 | | |
| 333 | 332 | | if (!cache_dir || !filename) |
| @@ -341,13 +340,7 @@ char* tns_cache_filename(const char *filename) { |
| 341 | 340 | | strcpy(abspath, filename); |
| 342 | 341 | | } |
| 343 | 342 | | |
| 344 | | − | len = strlen(abspath); |
| 345 | | − | for (i = 0; i < len; ++i) { |
| 346 | | − | if (abspath[i] == '/') |
| 347 | | − | abspath[i] = '%'; |
| 348 | | − | } |
| 349 | | − | |
| 350 | | − | len += strlen(cache_dir) + 6; |
| 343 | + | len = strlen(cache_dir) + strlen(abspath) + 6; |
| 351 | 344 | | cfile = (char*) s_malloc(len); |
| 352 | 345 | | snprintf(cfile, len, "%s/%s.png", cache_dir, abspath + 1); |
| 353 | 346 | | |
| @@ -380,10 +373,10 @@ Imlib_Image* tns_cache_load(const char *filename) { |
| 380 | 373 | | } |
| 381 | 374 | | |
| 382 | 375 | | void tns_cache_write(thumb_t *t, Bool force) { |
| 383 | | − | char *cfile; |
| 376 | + | char *cfile, *dirend; |
| 384 | 377 | | struct stat cstats, fstats; |
| 385 | 378 | | struct timeval times[2]; |
| 386 | | − | Imlib_Load_Error err; |
| 379 | + | Imlib_Load_Error err = 0; |
| 387 | 380 | | |
| 388 | 381 | | if (!t || !t->im || !t->filename) |
| 389 | 382 | | return; |
| @@ -395,9 +388,17 @@ void tns_cache_write(thumb_t *t, Bool force) { |
| 395 | 388 | | cstats.st_mtim.tv_sec != fstats.st_mtim.tv_sec || |
| 396 | 389 | | cstats.st_mtim.tv_nsec != fstats.st_mtim.tv_nsec) |
| 397 | 390 | | { |
| 398 | | − | imlib_context_set_image(t->im); |
| 399 | | − | imlib_image_set_format("png"); |
| 400 | | − | imlib_save_image_with_error_return(cfile, &err); |
| 391 | + | if ((dirend = strrchr(cfile, '/'))) { |
| 392 | + | *dirend = '\0'; |
| 393 | + | err = create_dir_rec(cfile); |
| 394 | + | *dirend = '/'; |
| 395 | + | } |
| 396 | + | |
| 397 | + | if (!err) { |
| 398 | + | imlib_context_set_image(t->im); |
| 399 | + | imlib_image_set_format("png"); |
| 400 | + | imlib_save_image_with_error_return(cfile, &err); |
| 401 | + | } |
| 401 | 402 | | |
| 402 | 403 | | if (err) { |
| 403 | 404 | | warn("could not cache thumbnail: %s", t->filename); |