mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 10:35:37 +02:00
[cdc_fuse_fs] Fix various issues (#6)
Fixes a couple of issues with the FUSE: - Creates the mount directory if it does not exist. This assumes the mount dir to be the last arg. Ideally, we'd parse the command line and then create the directory, but unfortunately fuse_parse_cmdline already verifies that the dir exists. - Expands the cache_dir (e.g. ~). - Fixes a compile issue in manifest_iterator.
This commit is contained in:
@@ -73,6 +73,31 @@ bool IsUpToDate(const std::string& components_arg) {
|
||||
return true;
|
||||
}
|
||||
|
||||
absl::Status CreateMountDir(const std::vector<char*>& args) {
|
||||
// Assume the mount dir is the last argument.
|
||||
size_t argc = args.size();
|
||||
if (argc < 2 || !args[argc - 1]) {
|
||||
return absl::InvalidArgumentError(
|
||||
"The last argument must be the mount directory");
|
||||
}
|
||||
std::string mount_dir = args[argc - 1];
|
||||
if (mount_dir[0] == '-') {
|
||||
return absl::InvalidArgumentError(absl::StrFormat(
|
||||
"The last argument must be the mount directory, but is '%s'",
|
||||
mount_dir));
|
||||
}
|
||||
|
||||
// Expand ~ etc.
|
||||
RETURN_IF_ERROR(cdc_ft::path::ExpandPathVariables(&mount_dir),
|
||||
"Failed to expand mount directory '%s'", mount_dir);
|
||||
|
||||
// Create expanded directory.
|
||||
RETURN_IF_ERROR(cdc_ft::path::CreateDirRec(mount_dir),
|
||||
"Failed to create directory '%s'", mount_dir);
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace cdc_ft
|
||||
|
||||
@@ -105,7 +130,7 @@ ABSL_FLAG(uint32_t, access_idle_timeout, cdc_ft::DataProvider::kAccessIdleSec,
|
||||
|
||||
static_assert(static_cast<int>(absl::StatusCode::kOk) == 0, "kOk != 0");
|
||||
|
||||
// Usage: cdc_fuse_fs <ABSL_FLAGs> -- mount_dir [-d|-s|..]
|
||||
// Usage: cdc_fuse_fs <ABSL_FLAGs> -- [-d|-s|.. mount_dir]
|
||||
// Any args after -- are FUSE args, search third_party/fuse for FUSE_OPT_KEY or
|
||||
// FUSE_LIB_OPT (there doesn't seem to be a place where they're all described).
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -137,9 +162,16 @@ int main(int argc, char* argv[]) {
|
||||
printf("%s\n", cdc_ft::kFuseUpToDate);
|
||||
fflush(stdout);
|
||||
|
||||
// Create mount dir if it doesn't exist yet.
|
||||
absl::Status status = cdc_ft::CreateMountDir(mount_args);
|
||||
if (!status.ok()) {
|
||||
LOG_ERROR("Failed to create mount directory: %s", status.ToString());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create fs. The rest of the flags are mount flags, so pass them along.
|
||||
absl::Status status = cdc_ft::cdc_fuse_fs::Initialize(
|
||||
static_cast<int>(mount_args.size()), mount_args.data());
|
||||
status = cdc_ft::cdc_fuse_fs::Initialize(static_cast<int>(mount_args.size()),
|
||||
mount_args.data());
|
||||
if (!status.ok()) {
|
||||
LOG_ERROR("Failed to initialize file system: %s", status.ToString());
|
||||
return static_cast<int>(status.code());
|
||||
|
||||
Reference in New Issue
Block a user