From 8716cf918e75c540814d75ccb9fa26ff6085cf63 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 18 Feb 2016 21:51:50 -0500 Subject: Create and use RAII file abstraction --- src/scoville.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/scoville.cc') diff --git a/src/scoville.cc b/src/scoville.cc index d8d1692..b572b5f 100644 --- a/src/scoville.cc +++ b/src/scoville.cc @@ -15,15 +15,13 @@ // this program. If not, see . #include +#include -#include #include #include -#include -#include #include "operations.h" -#include "utility.h" +#include "posix_extras.h" constexpr char kUsage[] = R"(allow forbidden characters on VFAT file systems @@ -35,15 +33,17 @@ int main(int argc, char* argv[]) { google::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); + // Open an FD to the underlying file system so we can still do operations on + // it while it's overlayed. + std::unique_ptr root; const char* const root_path = argv[argc - 1]; - int root_fd; - if ((root_fd = open(root_path, O_DIRECTORY)) == -1) { - std::cerr << "scoville: bad mount point `" << root_path - << "': " << scoville::ErrnoText(); - std::exit(EXIT_FAILURE); + try { + root.reset(new scoville::File(root_path, O_DIRECTORY)); + } catch (const scoville::IoError& e) { + LOG(FATAL) << "scoville: bad mount point `" << root_path + << "': " << e.what(); } - LOG(INFO) << "overlaying " << root_path; - - const fuse_operations operations = scoville::FuseOperations(root_fd); + LOG(INFO) << "overlaying " << root->path(); + const fuse_operations operations = scoville::FuseOperations(root.get()); return fuse_main(argc, argv, &operations, nullptr); } -- cgit v1.2.3