Skip to content

Commit f0f659d

Browse files
committed
Improve command line parsing
Correctly process the -- POSIX separator. Prevent mount point from being mistaken as an option.
1 parent 341ac5d commit f0f659d

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

mount-zip.cc

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ struct Operations : fuse_operations {
399399
cfg->use_ino = true;
400400
cfg->nullpath_ok = true;
401401
cfg->direct_io = g_direct_io;
402+
LOG(DEBUG) << "Initialized FUSE server";
402403
return nullptr;
403404
}
404405
#endif
@@ -554,17 +555,16 @@ static int ProcessArg(void* data,
554555

555556
case KEY_DEFAULT_PERMISSIONS:
556557
DataNode::original_permissions = true;
557-
return KEEP;
558+
return DISCARD;
558559

559560
#if FUSE_USE_VERSION >= 30
560561
case KEY_DIRECT_IO:
561562
g_direct_io = true;
562563
return DISCARD;
563564
#endif
564-
565-
default:
566-
return KEEP;
567565
}
566+
567+
return KEEP;
568568
}
569569

570570
// Removes directory |dir| in destructor.
@@ -662,6 +662,23 @@ int main(int argc, char* argv[]) try {
662662
return EXIT_FAILURE;
663663
}
664664

665+
// Single-threaded operation.
666+
fuse_opt_add_arg(&args, "-s");
667+
668+
// Mount read-only.
669+
fuse_opt_add_arg(&args, "-r");
670+
671+
#if FUSE_USE_VERSION < 30
672+
// Respect inode numbers.
673+
fuse_opt_add_arg(&args, "-o");
674+
fuse_opt_add_arg(&args, "use_ino");
675+
#endif
676+
677+
if (DataNode::original_permissions) {
678+
fuse_opt_add_arg(&args, "-o");
679+
fuse_opt_add_arg(&args, "default_permissions");
680+
}
681+
665682
std::string mount_point;
666683
if (param.paths.size() > 1) {
667684
mount_point = std::move(param.paths.back());
@@ -731,18 +748,13 @@ int main(int argc, char* argv[]) try {
731748
}
732749
}
733750

734-
fuse_opt_add_arg(&args, mount_point.c_str());
735-
736-
#if FUSE_USE_VERSION < 30
737-
// Respect inode numbers.
738-
fuse_opt_add_arg(&args, "-ouse_ino");
739-
#endif
740-
741-
// Read-only mounting.
742-
fuse_opt_add_arg(&args, "-r");
743-
744-
// Single-threaded operation.
745-
fuse_opt_add_arg(&args, "-s");
751+
// The mount point is in place.
752+
if (mount_point.starts_with('-')) {
753+
// To prevent the mount point from being mistaken as a command line option.
754+
fuse_opt_add_arg(&args, StrCat("./", mount_point).c_str());
755+
} else {
756+
fuse_opt_add_arg(&args, mount_point.c_str());
757+
}
746758

747759
return fuse_main(args.argc, args.argv, &operations, nullptr);
748760
} catch (const ZipError& e) {

tests/blackbox/data/--help

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foobar.zip

tests/blackbox/test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def MountZipAndGetTree(zip_names, options=[], password='', use_md5=True):
142142
]
143143
logging.debug(f'Mounting {zip_paths!r} on {mount_point!r}...')
144144
subprocess.run(
145-
[mount_program, *options] + zip_paths + [mount_point],
145+
[mount_program, *options, '--', *zip_paths, mount_point],
146146
check=True,
147147
capture_output=True,
148148
input=password,
@@ -421,6 +421,15 @@ def TestZipWithDefaultOptions():
421421
'md5': 'c157a79031e1c40f85931829bc5fc552',
422422
},
423423
},
424+
'--help': {
425+
'.': {'ino': 1, 'mode': 'drwxr-xr-x', 'nlink': 2},
426+
'foo': {
427+
'nlink': 1,
428+
'mtime': 1565484162000000000,
429+
'size': 4,
430+
'md5': 'c157a79031e1c40f85931829bc5fc552',
431+
},
432+
},
424433
'hlink-before-target.zip': {
425434
'.': {'ino': 1, 'mode': 'drwxr-xr-x', 'nlink': 2},
426435
'0hlink': {
@@ -1856,7 +1865,7 @@ def TestBigZip(options=[]):
18561865
zip_path = os.path.join(script_dir, 'data', zip_name)
18571866
logging.debug(f'Mounting {zip_path!r} on {mount_point!r}...')
18581867
subprocess.run(
1859-
[mount_program] + options + [zip_path, mount_point],
1868+
[mount_program, *options, '--', zip_path, mount_point],
18601869
check=True,
18611870
capture_output=True,
18621871
input='',
@@ -1916,7 +1925,7 @@ def TestBigZipNoCache(options=['-o', 'nocache']):
19161925
zip_path = os.path.join(script_dir, 'data', zip_name)
19171926
logging.debug(f'Mounting {zip_path!r} on {mount_point!r}...')
19181927
subprocess.run(
1919-
[mount_program] + options + [zip_path, mount_point],
1928+
[mount_program, *options, '--', zip_path, mount_point],
19201929
check=True,
19211930
capture_output=True,
19221931
input='',

0 commit comments

Comments
 (0)