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
* spdlog/1.11.0
Version 0.11.5 (unreleased)
---------------
* Fix an issue when using `-o` atime mount options
Version 0.11.4
---------------
* 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"};
return flags.end() != std::find(flags.begin(), flags.end(), flag);
};
*csv_options = ranges::make_subrange(csv_options->begin(), csv_options->end())
| ranges::views::split(',')
| ranges::views::filter(
[&] (auto&& elem_) {
// TODO string_view would be better
const std::string elem(&*elem_.begin(), ranges::distance(elem_));
if (is_fuse_unsupported_atime_flag(elem)) {
result->push_back(elem);
return false;
}
if (is_fuse_supported_atime_flag(elem)) {
result->push_back(elem);
}
return true;
})
| ranges::views::join(',')
| ranges::to<string>();
}
*csv_options = ranges::make_subrange(csv_options->begin(), csv_options->end()) | ranges::views::split(',') | ranges::views::filter(
[&](auto &&elem_) {
// TODO string_view would be better
const std::string elem(&*elem_.begin(), ranges::distance(elem_));
if (is_fuse_unsupported_atime_flag(elem)) {
result->push_back(elem);
return false;
}
if (is_fuse_supported_atime_flag(elem)) {
result->push_back(elem);
}
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
// 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> result;
bool lastOptionWasDashO = false;
for (string& option : *fuseOptions) {
if (lastOptionWasDashO) {
extractAllAtimeOptionsAndRemoveOnesUnknownToLibfuse_(&option, &result);
for (size_t i = 0; i < fuseOptions->size(); ++i)
{
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;
}
}