Add an --immediate flag to cryfs-unmount that tries to unmount immediately and doesn't wait for processes to release their locks on the file system.
This commit is contained in:
parent
7d48336f8d
commit
b603d3b58a
@ -9,6 +9,7 @@ Other changes:
|
||||
|
||||
New features:
|
||||
* Add support for atime mount options (noatime, strictatime, relatime, atime, nodiratime). As before, relatime is the default.
|
||||
* Add an --immediate flag to cryfs-unmount that tries to unmount immediately and doesn't wait for processes to release their locks on the file system.
|
||||
|
||||
|
||||
Version 0.10.3 (unreleased)
|
||||
|
@ -25,12 +25,33 @@ void Cli::main(int argc, const char **argv) {
|
||||
if (!boost::filesystem::exists(options.mountDir())) {
|
||||
throw cryfs::CryfsException("Given mountdir doesn't exist", cryfs::ErrorCode::InaccessibleMountDir);
|
||||
}
|
||||
|
||||
bool immediate = options.immediate();
|
||||
#if defined(__APPLE__)
|
||||
if (options.immediate()) {
|
||||
std::cerr << "Warning: OSX doesn't support the --immediate flag. Ignoring it.";
|
||||
immediate = false;
|
||||
}
|
||||
#elif defined(_MSC_VER)
|
||||
if (options.immediate()) {
|
||||
std::cerr << "Warning: Windows doesn't support the --immediate flag. Ignoring it.";
|
||||
immediate = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO This doesn't seem to work with relative paths
|
||||
std::cout << "Unmounting CryFS filesystem at " << options.mountDir() << "." << std::endl;
|
||||
Fuse::unmount(options.mountDir());
|
||||
if (immediate) {
|
||||
Fuse::unmount(options.mountDir(), true);
|
||||
|
||||
// TODO Wait until it is actually unmounted and then show a better success message?
|
||||
std::cout << "Filesystem is unmounting now." << std::endl;
|
||||
// TODO Wait until it is actually unmounted and then show a better success message?
|
||||
std::cout << "Filesystem is unmounting." << std::endl;
|
||||
} else {
|
||||
Fuse::unmount(options.mountDir(), false);
|
||||
|
||||
// TODO Wait until it is actually unmounted and then show a better success message?
|
||||
std::cout << "Filesystem will unmount as soon as nothing is accessing it anymore." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,8 +36,9 @@ ProgramOptions Parser::parse() const {
|
||||
_showHelpAndExit("Please specify a mount directory.", ErrorCode::InvalidArguments);
|
||||
}
|
||||
bf::path mountDir = vm["mount-dir"].as<string>();
|
||||
bool immediate = vm.count("immediate");
|
||||
|
||||
return ProgramOptions(std::move(mountDir));
|
||||
return ProgramOptions(std::move(mountDir), immediate);
|
||||
}
|
||||
|
||||
po::variables_map Parser::_parseOptionsOrShowHelp(const vector<string> &options) {
|
||||
@ -95,8 +96,9 @@ void Parser::_addAllowedOptions(po::options_description *desc) {
|
||||
string blocksize_description = "The block size used when storing ciphertext blocks (in bytes). Default: ";
|
||||
blocksize_description += std::to_string(CryConfigConsole::DEFAULT_BLOCKSIZE_BYTES);
|
||||
options.add_options()
|
||||
("immediate", "unmount immediately without waiting for processes that currently access the file system to finish their file system operations. With this flag, unmounting can fail if there's processes having a lock on the file system.")
|
||||
("help,h", "show help message")
|
||||
("version", "Show CryFS version number")
|
||||
("version", "show CryFS version number")
|
||||
;
|
||||
desc->add(options);
|
||||
}
|
||||
|
@ -7,19 +7,28 @@ using namespace cryfs_unmount::program_options;
|
||||
using std::string;
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
ProgramOptions::ProgramOptions(bf::path mountDir)
|
||||
:_mountDir(std::move(mountDir)),
|
||||
_mountDirIsDriveLetter(cpputils::path_is_just_drive_letter(_mountDir))
|
||||
ProgramOptions::ProgramOptions(bf::path mountDir, bool immediate)
|
||||
: _mountDir(std::move(mountDir)),
|
||||
_mountDirIsDriveLetter(cpputils::path_is_just_drive_letter(_mountDir)),
|
||||
_immediate(immediate)
|
||||
{
|
||||
if (!_mountDirIsDriveLetter) {
|
||||
if (!_mountDirIsDriveLetter)
|
||||
{
|
||||
_mountDir = bf::absolute(std::move(_mountDir));
|
||||
}
|
||||
}
|
||||
|
||||
const bf::path &ProgramOptions::mountDir() const {
|
||||
const bf::path &ProgramOptions::mountDir() const
|
||||
{
|
||||
return _mountDir;
|
||||
}
|
||||
|
||||
bool ProgramOptions::mountDirIsDriveLetter() const {
|
||||
bool ProgramOptions::mountDirIsDriveLetter() const
|
||||
{
|
||||
return _mountDirIsDriveLetter;
|
||||
}
|
||||
|
||||
bool ProgramOptions::immediate() const
|
||||
{
|
||||
return _immediate;
|
||||
}
|
||||
|
@ -8,23 +8,28 @@
|
||||
#include <cpp-utils/macros.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace cryfs_unmount {
|
||||
namespace program_options {
|
||||
class ProgramOptions final {
|
||||
namespace cryfs_unmount
|
||||
{
|
||||
namespace program_options
|
||||
{
|
||||
class ProgramOptions final
|
||||
{
|
||||
public:
|
||||
ProgramOptions(boost::filesystem::path mountDir);
|
||||
ProgramOptions(boost::filesystem::path mountDir, bool immediate);
|
||||
ProgramOptions(ProgramOptions &&rhs) = default;
|
||||
|
||||
const boost::filesystem::path &mountDir() const;
|
||||
bool mountDirIsDriveLetter() const;
|
||||
bool immediate() const;
|
||||
|
||||
private:
|
||||
boost::filesystem::path _mountDir;
|
||||
bool _mountDirIsDriveLetter;
|
||||
bool _immediate;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProgramOptions);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace program_options
|
||||
} // namespace cryfs_unmount
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user