Fix an issue when using -o atime mount options

This commit is contained in:
Sebastian Messmer 2023-08-06 22:14:40 -07:00
parent 7a3f2b6114
commit d6252896e0
2 changed files with 34 additions and 22 deletions

View File

@ -9,6 +9,10 @@ Version 0.12.0 (unreleased)
* boost 1.79 * boost 1.79
* spdlog/1.11.0 * spdlog/1.11.0
Version 0.11.5 (unreleased)
---------------
* Fix an issue when using `-o` atime mount options
Version 0.11.4 Version 0.11.4
--------------- ---------------
* Fixed build issue with GCC 13 (see https://github.com/cryfs/cryfs/pull/448 ) * Fixed build issue with GCC 13 (see https://github.com/cryfs/cryfs/pull/448 )

View File

@ -311,24 +311,20 @@ void extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(string* csv_options, v
constexpr std::array<const char*, 3> flags = {"strictatime", "relatime", "nodiratime"}; constexpr std::array<const char*, 3> flags = {"strictatime", "relatime", "nodiratime"};
return flags.end() != std::find(flags.begin(), flags.end(), flag); return flags.end() != std::find(flags.begin(), flags.end(), flag);
}; };
*csv_options = ranges::make_subrange(csv_options->begin(), csv_options->end()) *csv_options = ranges::make_subrange(csv_options->begin(), csv_options->end()) | ranges::views::split(',') | ranges::views::filter(
| ranges::views::split(',') [&](auto &&elem_) {
| ranges::views::filter( // TODO string_view would be better
[&] (auto&& elem_) { const std::string elem(&*elem_.begin(), ranges::distance(elem_));
// TODO string_view would be better if (is_fuse_unsupported_atime_flag(elem)) {
const std::string elem(&*elem_.begin(), ranges::distance(elem_)); result->push_back(elem);
if (is_fuse_unsupported_atime_flag(elem)) { return false;
result->push_back(elem); }
return false; if (is_fuse_supported_atime_flag(elem)) {
} result->push_back(elem);
if (is_fuse_supported_atime_flag(elem)) { }
result->push_back(elem); return true;
} }) | ranges::views::join(',') | ranges::to<string>();
return true; }
})
| ranges::views::join(',')
| ranges::to<string>();
}
// Return a list of all atime options (e.g. atime, noatime, relatime, strictatime, nodiratime) that occur in the // Return a list of all atime options (e.g. atime, noatime, relatime, strictatime, nodiratime) that occur in the
// fuseOptions input. They must be preceded by a '-o', i.e. {..., '-o', 'noatime', ...} and multiple ones can be // fuseOptions input. They must be preceded by a '-o', i.e. {..., '-o', 'noatime', ...} and multiple ones can be
@ -338,12 +334,24 @@ void extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(string* csv_options, v
vector<string> extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(vector<string>* fuseOptions) { vector<string> extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(vector<string>* fuseOptions) {
vector<string> result; vector<string> result;
bool lastOptionWasDashO = false; bool lastOptionWasDashO = false;
for (string& option : *fuseOptions) { for (size_t i = 0; i < fuseOptions->size(); ++i)
if (lastOptionWasDashO) { {
extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(&option, &result); string &option = (*fuseOptions)[i];
if (lastOptionWasDashO)
{
extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(&option, &result);
if (option.empty()) {
// All options were removed, remove the empty argument
fuseOptions->erase(fuseOptions->begin() + i);
--i;
// And also remove the now value-less '-o' before it
fuseOptions->erase(fuseOptions->begin() + i);
--i;
} }
lastOptionWasDashO = (option == "-o"); }
lastOptionWasDashO = (option == "-o");
} }
return result; return result;
} }
} }