@@ -181,128 +181,129 @@ static void scan_dir(FileBrowserModePrivateData *pd, GFile *path) {
181
181
GQueue * dirs_to_scan = g_queue_new ();
182
182
g_queue_push_tail (dirs_to_scan , g_object_ref (path ));
183
183
GFile * dir_to_scan = NULL ;
184
- while ( (dir_to_scan = g_queue_pop_head (dirs_to_scan )) != NULL ) {
185
- char * cdir = g_file_get_path (dir_to_scan );
186
- DIR * dir = opendir (cdir );
187
- g_object_unref (dir_to_scan );
188
- if (dir ) {
189
- struct dirent * rd = NULL ;
190
- while (pd -> end_thread == FALSE && (rd = readdir (dir )) != NULL ) {
191
- if (g_strcmp0 (rd -> d_name , ".." ) == 0 ) {
192
- continue ;
193
- }
194
- if (g_strcmp0 (rd -> d_name , "." ) == 0 ) {
195
- continue ;
196
- }
197
- if (pd -> filter_regex &&
198
- g_regex_match (pd -> filter_regex , rd -> d_name , 0 , NULL )) {
199
- continue ;
200
- }
201
- switch (rd -> d_type ) {
202
- case DT_BLK :
203
- case DT_CHR :
204
- case DT_FIFO :
205
- case DT_SOCK :
206
- default :
207
- break ;
208
- case DT_REG : {
209
- FBFile * f = g_malloc0 (sizeof (FBFile ));
210
- // Rofi expects utf-8, so lets convert the filename.
211
- f -> path = g_build_filename (cdir , rd -> d_name , NULL );
212
- f -> name = g_filename_to_utf8 (f -> path , -1 , NULL , NULL , NULL );
213
- if (f -> name == NULL ) {
214
- f -> name = rofi_force_utf8 (rd -> d_name , -1 );
215
- }
216
- if (f -> name == NULL ) {
217
- f -> name = g_strdup ("n/a" );
218
- }
219
- f -> type = (rd -> d_type == DT_DIR ) ? DIRECTORY : RFILE ;
220
- f -> icon_fetch_uid = 0 ;
221
- f -> icon_fetch_size = 0 ;
222
- f -> link = FALSE;
223
-
224
- g_async_queue_push (pd -> async_queue , f );
225
- if (g_async_queue_length (pd -> async_queue ) > 10000 ) {
226
- write (pd -> pipefd2 [1 ], "r" , 1 );
227
- }
228
- break ;
229
- }
230
- case DT_DIR : {
231
- char * d = g_build_filename (cdir , rd -> d_name , NULL );
232
- GFile * dirp = g_file_new_for_path (d );
233
- g_queue_push_tail (dirs_to_scan , dirp );
234
- g_free (d );
235
- break ;
236
- }
237
- case DT_UNKNOWN :
238
- case DT_LNK : {
239
- FBFile * f = g_malloc0 (sizeof (FBFile ));
240
- // Rofi expects utf-8, so lets convert the filename.
241
- f -> path = g_build_filename (cdir , rd -> d_name , NULL );
242
- f -> name = g_filename_to_utf8 (f -> path , -1 , NULL , NULL , NULL );
243
- if (f -> name == NULL ) {
244
- f -> name = rofi_force_utf8 (rd -> d_name , -1 );
245
- }
246
- if (f -> name == NULL ) {
247
- f -> name = g_strdup ("n/a" );
248
- }
249
- f -> icon_fetch_uid = 0 ;
250
- f -> icon_fetch_size = 0 ;
251
- // Default to file.
252
- f -> type = RFILE ;
253
- if (rd -> d_type == DT_LNK ) {
254
- f -> link = TRUE;
255
- } else {
256
- f -> link = FALSE;
257
- }
258
- {
259
- // If we have link, use a stat to fine out what it is, if we fail, we
260
- // mark it as file.
261
- // TODO have a 'broken link' mode?
262
- // Convert full path to right encoding.
263
- // DD: Path should be in file encoding, not utf-8
264
- // char *file =
265
- // g_filename_from_utf8(pd->array[pd->array_length].path,
266
- // -1, NULL, NULL, NULL);
267
- // TODO: How to handle loops in links.
268
- if (f -> path ) {
269
- GStatBuf statbuf ;
270
- if (g_stat (f -> path , & statbuf ) == 0 ) {
271
- if (S_ISDIR (statbuf .st_mode )) {
272
- char * new_full_path = g_build_filename (cdir , rd -> d_name , NULL );
273
- g_free (f -> path );
274
- g_free (f -> name );
275
- g_free (f );
276
- f = NULL ;
277
- GFile * dirp = g_file_new_for_path (new_full_path );
278
- g_queue_push_tail (dirs_to_scan , dirp );
279
- g_free (new_full_path );
280
- break ;
281
- } else if (S_ISREG (statbuf .st_mode )) {
282
- f -> type = RFILE ;
283
- }
284
-
285
- } else {
286
- g_warning ("Failed to stat file: %s, %s" , f -> path ,
287
- strerror (errno ));
288
- }
289
-
290
- // g_free(file);
291
- }
292
- }
293
- if (f != NULL ) {
294
- g_async_queue_push (pd -> async_queue , f );
295
- if (g_async_queue_length (pd -> async_queue ) > 10000 ) {
296
- write (pd -> pipefd2 [1 ], "r" , 1 );
297
- }
298
- }
299
- break ;
300
- }
301
- }
302
- }
303
- closedir (dir );
304
- }
305
- g_free (cdir );
184
+ while ((dir_to_scan = g_queue_pop_head (dirs_to_scan )) != NULL ) {
185
+ char * cdir = g_file_get_path (dir_to_scan );
186
+ DIR * dir = opendir (cdir );
187
+ g_object_unref (dir_to_scan );
188
+ if (dir ) {
189
+ struct dirent * rd = NULL ;
190
+ while (pd -> end_thread == FALSE && (rd = readdir (dir )) != NULL ) {
191
+ if (g_strcmp0 (rd -> d_name , ".." ) == 0 ) {
192
+ continue ;
193
+ }
194
+ if (g_strcmp0 (rd -> d_name , "." ) == 0 ) {
195
+ continue ;
196
+ }
197
+ if (pd -> filter_regex &&
198
+ g_regex_match (pd -> filter_regex , rd -> d_name , 0 , NULL )) {
199
+ continue ;
200
+ }
201
+ switch (rd -> d_type ) {
202
+ case DT_BLK :
203
+ case DT_CHR :
204
+ case DT_FIFO :
205
+ case DT_SOCK :
206
+ default :
207
+ break ;
208
+ case DT_REG : {
209
+ FBFile * f = g_malloc0 (sizeof (FBFile ));
210
+ // Rofi expects utf-8, so lets convert the filename.
211
+ f -> path = g_build_filename (cdir , rd -> d_name , NULL );
212
+ f -> name = g_filename_to_utf8 (f -> path , -1 , NULL , NULL , NULL );
213
+ if (f -> name == NULL ) {
214
+ f -> name = rofi_force_utf8 (rd -> d_name , -1 );
215
+ }
216
+ if (f -> name == NULL ) {
217
+ f -> name = g_strdup ("n/a" );
218
+ }
219
+ f -> type = (rd -> d_type == DT_DIR ) ? DIRECTORY : RFILE ;
220
+ f -> icon_fetch_uid = 0 ;
221
+ f -> icon_fetch_size = 0 ;
222
+ f -> link = FALSE;
223
+
224
+ g_async_queue_push (pd -> async_queue , f );
225
+ if (g_async_queue_length (pd -> async_queue ) > 10000 ) {
226
+ write (pd -> pipefd2 [1 ], "r" , 1 );
227
+ }
228
+ break ;
229
+ }
230
+ case DT_DIR : {
231
+ char * d = g_build_filename (cdir , rd -> d_name , NULL );
232
+ GFile * dirp = g_file_new_for_path (d );
233
+ g_queue_push_tail (dirs_to_scan , dirp );
234
+ g_free (d );
235
+ break ;
236
+ }
237
+ case DT_UNKNOWN :
238
+ case DT_LNK : {
239
+ FBFile * f = g_malloc0 (sizeof (FBFile ));
240
+ // Rofi expects utf-8, so lets convert the filename.
241
+ f -> path = g_build_filename (cdir , rd -> d_name , NULL );
242
+ f -> name = g_filename_to_utf8 (f -> path , -1 , NULL , NULL , NULL );
243
+ if (f -> name == NULL ) {
244
+ f -> name = rofi_force_utf8 (rd -> d_name , -1 );
245
+ }
246
+ if (f -> name == NULL ) {
247
+ f -> name = g_strdup ("n/a" );
248
+ }
249
+ f -> icon_fetch_uid = 0 ;
250
+ f -> icon_fetch_size = 0 ;
251
+ // Default to file.
252
+ f -> type = RFILE ;
253
+ if (rd -> d_type == DT_LNK ) {
254
+ f -> link = TRUE;
255
+ } else {
256
+ f -> link = FALSE;
257
+ }
258
+ {
259
+ // If we have link, use a stat to fine out what it is, if we fail,
260
+ // we mark it as file.
261
+ // TODO have a 'broken link' mode?
262
+ // Convert full path to right encoding.
263
+ // DD: Path should be in file encoding, not utf-8
264
+ // char *file =
265
+ // g_filename_from_utf8(pd->array[pd->array_length].path,
266
+ // -1, NULL, NULL, NULL);
267
+ // TODO: How to handle loops in links.
268
+ if (f -> path ) {
269
+ GStatBuf statbuf ;
270
+ if (g_stat (f -> path , & statbuf ) == 0 ) {
271
+ if (S_ISDIR (statbuf .st_mode )) {
272
+ char * new_full_path =
273
+ g_build_filename (cdir , rd -> d_name , NULL );
274
+ g_free (f -> path );
275
+ g_free (f -> name );
276
+ g_free (f );
277
+ f = NULL ;
278
+ GFile * dirp = g_file_new_for_path (new_full_path );
279
+ g_queue_push_tail (dirs_to_scan , dirp );
280
+ g_free (new_full_path );
281
+ break ;
282
+ } else if (S_ISREG (statbuf .st_mode )) {
283
+ f -> type = RFILE ;
284
+ }
285
+
286
+ } else {
287
+ g_warning ("Failed to stat file: %s, %s" , f -> path ,
288
+ strerror (errno ));
289
+ }
290
+
291
+ // g_free(file);
292
+ }
293
+ }
294
+ if (f != NULL ) {
295
+ g_async_queue_push (pd -> async_queue , f );
296
+ if (g_async_queue_length (pd -> async_queue ) > 10000 ) {
297
+ write (pd -> pipefd2 [1 ], "r" , 1 );
298
+ }
299
+ }
300
+ break ;
301
+ }
302
+ }
303
+ }
304
+ closedir (dir );
305
+ }
306
+ g_free (cdir );
306
307
}
307
308
308
309
g_queue_free (dirs_to_scan );
@@ -496,11 +497,12 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
496
497
if (rofi_icon_fetcher_file_is_image (dr -> path )) {
497
498
dr -> icon_fetch_uid = rofi_icon_fetcher_query (dr -> path , height );
498
499
} else if (dr -> type == RFILE ) {
499
- gchar * _path = g_strconcat ("thumbnail://" , dr -> path , NULL );
500
+ gchar * _path = g_strconcat ("thumbnail://" , dr -> path , NULL );
500
501
dr -> icon_fetch_uid = rofi_icon_fetcher_query (_path , height );
501
502
g_free (_path );
502
503
} else {
503
- dr -> icon_fetch_uid = rofi_icon_fetcher_query (rb_icon_name [dr -> type ], height );
504
+ dr -> icon_fetch_uid =
505
+ rofi_icon_fetcher_query (rb_icon_name [dr -> type ], height );
504
506
}
505
507
dr -> icon_fetch_size = height ;
506
508
return rofi_icon_fetcher_get (dr -> icon_fetch_uid );
0 commit comments