Skip to content

Commit 2029a2d

Browse files
committed
'view purge': read paths as file URIs
1 parent 40b8114 commit 2029a2d

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/settings.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,9 @@ alt-down:preview-page-down --inline-info --layout=reverse-list \
667667
#define DEF_SMENU_OPTIONS "-a t:2,b b:4 c:r ct:2,r sf:6,r st:5,r mt:5,b"
668668

669669
/* Name of the file to store thumbnails original paths.
670-
* Each line in this file has this format: THUMB_FILE@ORIGINAL_FILE,
671-
* where THUMB_FILE is the name of the thumbnail file (md5 hash of the
672-
* absolute path to the original file name), and ORIGNAL_FILE is the
673-
* absolute path to the original file name.
670+
* Each line in this file has this format: THUMB_FILE@FILE_URI,
671+
* where THUMB_FILE is the name of the thumbnail file (MD5 hash of FILE_URI),
672+
* and FILE_URI is the file URI for the absolute path to the original file name.
674673
* This file is located in $XDG_CACHE_HOME/clifm/thumbnails */
675674
#define THUMBNAILS_INFO_FILE "thumbnails.info"
676675

src/view.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ remove_empty_thumbnails(void)
106106
*
107107
* The info file is created by the 'clifmimg' script: every time a new
108108
* thumbnail is generated, a new entry is added to this file.
109-
* Each entry has this form: THUMB@ORIG
110-
* THUMB is the name of the thumbnail file (i.e. an MD5 hash of the original
111-
* file followed by a file extension, either jpg or png).
112-
* ORIG is the absolute path to the original file name.
109+
* Each entry has this form: THUMB_FILE@FILE_URI
110+
* THUMB_FILE is the name of the thumbnail file (i.e. an MD5 hash of
111+
* FILE_URI followed by a file extension, either jpg or png).
112+
* FILE_URI is the file URI for the absolute path to the original file name.
113113
*
114-
* If THUMB does not exist, the entry is removed from the info file.
115-
* If both THUMB and ORIG exist, the entry is preserved.
116-
* Finally, if ORIG does not exist, the current entry is removed and THUMB
117-
* gets deleted. */
114+
* If THUMB_FILE does not exist, the entry is removed from the info file.
115+
* If both THUMB_FILE and FILE_URI exist, the entry is preserved.
116+
* Finally, if FILE_URI does not exist, the current entry is removed and
117+
* THUMB_FILE gets deleted. */
118118
static int
119119
purge_thumbnails_cache(void)
120120
{
@@ -172,19 +172,22 @@ purge_thumbnails_cache(void)
172172

173173
off_t size_sum = 0;
174174
int errors = 0;
175-
char tfile[PATH_MAX + 40]; /* Bigger than line is enough. This just avoids
175+
char tfile[PATH_MAX + 1]; /* Bigger than line is enough. This just avoids
176176
a compiler warning. */
177177

178-
/* MD5 hash (32 bytes) + '.' + extension (usually 3 bytes) + '@'
179-
* + absolute path + new line char + NUL char */
180-
char line[PATH_MAX + 39];
181-
while (fgets(line, (int)sizeof(line), fp) != NULL) {
178+
char *line = (char *)NULL;
179+
size_t line_size = 0;
180+
ssize_t line_len = 0;
181+
182+
while ((line_len = getline(&line, &line_size, fp)) > 0) {
182183
char *p = strchr(line, '@');
183-
if (!p || p[1] != '/') /* Malformed entry: remove it. */
184+
if (!p || strncmp(p + 1, "file:///", 8) != 0)
185+
/* Malformed entry: remove it. */
184186
continue;
185187

186188
*p = '\0';
187-
p++;
189+
p += 8;
190+
188191
const size_t len = strlen(p);
189192
if (len > 1 && p[len - 1] == '\n')
190193
p[len - 1] = '\0';
@@ -195,9 +198,18 @@ purge_thumbnails_cache(void)
195198
/* Thumbnail file does not exist: remove this entry */
196199
continue;
197200

198-
if (lstat(p, &a) != -1) {
201+
char *abs_path = p;
202+
if (strchr(p, '%'))
203+
abs_path = url_decode(p);
204+
205+
const int retval = lstat(abs_path, &a);
206+
207+
if (abs_path != p)
208+
free(abs_path);
209+
210+
if (retval != -1) {
199211
/* Both the thumbnail file and the original file exist. */
200-
fprintf(tmp_fp, "%s@%s\n", line, p);
212+
fprintf(tmp_fp, "%s@file://%s\n", line, p);
201213
continue;
202214
}
203215

@@ -218,6 +230,7 @@ purge_thumbnails_cache(void)
218230

219231
fclose(fp);
220232
fclose(tmp_fp);
233+
free(line);
221234

222235
rename(tmp_file, thumb_file);
223236
unlink(tmp_file);

0 commit comments

Comments
 (0)