@@ -92,6 +92,7 @@ struct sparsebundle_t {
9292 bool allow_other = false ;
9393 bool allow_root = false ;
9494 bool noreadbuf = false ;
95+ bool always_close = false ;
9596 } options;
9697};
9798
@@ -212,6 +213,14 @@ static int sparsebundle_open_file(const char *path)
212213 if (iter != sparsebundle->open_files .end ()) {
213214 fd = iter->second ;
214215 } else {
216+ if (sparsebundle->options .always_close ) {
217+ // Escape hatch in case the logic below doesn't work.
218+ // We're closing files here, instead of after use, since
219+ // we don't know when the file will be read in the case
220+ // of read_buf (but looking at the code, it looks like
221+ // it's synchronous).
222+ sparsebundle_close_files ();
223+ }
215224 syslog (LOG_DEBUG, " file %s not opened yet, opening" , path);
216225 if ((fd = open (path, O_RDONLY)) == -1 ) {
217226 if (errno == EMFILE) {
@@ -471,14 +480,15 @@ static int sparsebundle_show_usage(char *program_name)
471480enum {
472481 SPARSEBUNDLE_OPT_HANDLED = 0 , SPARSEBUNDLE_OPT_IGNORED = 1 ,
473482 SPARSEBUNDLE_OPT_DEBUG, SPARSEBUNDLE_OPT_ALLOW_OTHER, SPARSEBUNDLE_OPT_ALLOW_ROOT,
474- SPARSEBUNDLE_OPT_NOREADBUF
483+ SPARSEBUNDLE_OPT_NOREADBUF, SPARSEBUNDLE_OPT_ALWAYS_CLOSE
475484};
476485
477486struct fuse_opt sparsebundle_options[] = {
478487 FUSE_OPT_KEY (" -D" , SPARSEBUNDLE_OPT_DEBUG),
479488 FUSE_OPT_KEY (" allow_other" , SPARSEBUNDLE_OPT_ALLOW_OTHER),
480489 FUSE_OPT_KEY (" allow_root" , SPARSEBUNDLE_OPT_ALLOW_ROOT),
481490 FUSE_OPT_KEY (" noreadbuf" , SPARSEBUNDLE_OPT_NOREADBUF),
491+ FUSE_OPT_KEY (" always_close" , SPARSEBUNDLE_OPT_ALWAYS_CLOSE),
482492 FUSE_OPT_END
483493};
484494
@@ -503,6 +513,10 @@ static int sparsebundle_opt_proc(void *data, const char *arg, int key, struct fu
503513 sparsebundle->options .noreadbuf = true ;
504514 return SPARSEBUNDLE_OPT_HANDLED;
505515
516+ case SPARSEBUNDLE_OPT_ALWAYS_CLOSE:
517+ sparsebundle->options .always_close = true ;
518+ return SPARSEBUNDLE_OPT_HANDLED;
519+
506520 case FUSE_OPT_KEY_NONOPT:
507521 if (!sparsebundle->path ) {
508522 sparsebundle->path = realpath (arg, 0 );
0 commit comments