@@ -106,15 +106,15 @@ remove_empty_thumbnails(void)
106
106
*
107
107
* The info file is created by the 'clifmimg' script: every time a new
108
108
* 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.
113
113
*
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. */
118
118
static int
119
119
purge_thumbnails_cache (void )
120
120
{
@@ -172,19 +172,22 @@ purge_thumbnails_cache(void)
172
172
173
173
off_t size_sum = 0 ;
174
174
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
176
176
a compiler warning. */
177
177
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 ) {
182
183
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. */
184
186
continue ;
185
187
186
188
* p = '\0' ;
187
- p ++ ;
189
+ p += 8 ;
190
+
188
191
const size_t len = strlen (p );
189
192
if (len > 1 && p [len - 1 ] == '\n' )
190
193
p [len - 1 ] = '\0' ;
@@ -195,9 +198,18 @@ purge_thumbnails_cache(void)
195
198
/* Thumbnail file does not exist: remove this entry */
196
199
continue ;
197
200
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 ) {
199
211
/* 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 );
201
213
continue ;
202
214
}
203
215
@@ -218,6 +230,7 @@ purge_thumbnails_cache(void)
218
230
219
231
fclose (fp );
220
232
fclose (tmp_fp );
233
+ free (line );
221
234
222
235
rename (tmp_file , thumb_file );
223
236
unlink (tmp_file );
0 commit comments