@@ -405,6 +405,61 @@ int appimage_print_binary(char* fname, unsigned long offset, unsigned long lengt
405405 return 0 ;
406406}
407407
408+ char * find_fusermount () {
409+ char * fusermount_base = "fusermount" ;
410+ int i = 0 ;
411+
412+ char * fusermount_path = getenv ("PATH" );
413+ if (fusermount_path == NULL ) {
414+ return NULL ;
415+ }
416+
417+ char * path_copy = strdup (fusermount_path );
418+ char * dir = strtok (path_copy , ":" );
419+
420+ while (dir != NULL ) {
421+ DIR * dir_ptr = opendir (dir );
422+ if (dir_ptr == NULL ) {
423+ dir = strtok (NULL , ":" );
424+ continue ;
425+ }
426+
427+ struct dirent * entry ;
428+ while ((entry = readdir (dir_ptr )) != NULL ) {
429+ // Check if the entry starts with "fusermount"
430+ if (strncmp (entry -> d_name , fusermount_base , 10 ) == 0 ) {
431+ // Check if the rest of the entry is a digit
432+ char * suffix = entry -> d_name + 10 ;
433+ int j = 0 ;
434+ while (suffix [j ] != '\0' && isdigit (suffix [j ])) {
435+ j ++ ;
436+ }
437+
438+ if (suffix [j ] == '\0' ) {
439+ // Construct the full path of the entry
440+ char * fusermount_full_path = malloc (strlen (dir ) + strlen (entry -> d_name ) + 2 );
441+ sprintf (fusermount_full_path , "%s/%s" , dir , entry -> d_name );
442+
443+ // Check if the entry is executable
444+ if (access (fusermount_full_path , X_OK ) == 0 ) {
445+ closedir (dir_ptr );
446+ free (path_copy );
447+ return fusermount_full_path ;
448+ }
449+
450+ free (fusermount_full_path );
451+ }
452+ }
453+ }
454+
455+ closedir (dir_ptr );
456+ dir = strtok (NULL , ":" );
457+ }
458+
459+ free (path_copy );
460+ return NULL ;
461+ }
462+
408463/* Exit status to use when launching an AppImage fails.
409464 * For applications that assign meanings to exit status codes (e.g. rsync),
410465 * we avoid "cluttering" pre-defined exit status codes by using 127 which
@@ -474,6 +529,20 @@ sqfs_err private_sqfs_stat(sqfs* fs, sqfs_inode* inode, struct stat* st) {
474529
475530/* ================= End ELF parsing */
476531
532+ char * fusermount_prog = getenv ("FUSERMOUNT_PROG" );
533+ if (fusermount_prog == NULL ) {
534+ fusermount_prog = find_fusermount ();
535+ if (fusermount_prog != NULL ) {
536+ setenv ("FUSERMOUNT_PROG" , fusermount_prog , 1 );
537+ // printf("FUSERMOUNT_PROG set to %s\n", fusermount_prog);
538+ free (fusermount_prog );
539+ } else {
540+ printf ("Error: fusermount not found\n" );
541+ }
542+ } else {
543+ printf ("FUSERMOUNT_PROG is already set to %s\n" , fusermount_prog );
544+ }
545+
477546extern int fusefs_main (int argc , char * argv [], void (* mounted )(void ));
478547// extern void ext2_quit(void);
479548
0 commit comments