aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-02-13 20:56:05 +0100
committerAdrian Kummerlaender2016-02-13 20:56:05 +0100
commit23b56fad3873b03a4b1f04e299104a7b52c62391 (patch)
tree7a37de26c018998302ae3da14da1b4651596a988 /src
parent0ba583aa35bccf268e30dd03a6d423df5f98b40e (diff)
downloadchange-23b56fad3873b03a4b1f04e299104a7b52c62391.tar
change-23b56fad3873b03a4b1f04e299104a7b52c62391.tar.gz
change-23b56fad3873b03a4b1f04e299104a7b52c62391.tar.bz2
change-23b56fad3873b03a4b1f04e299104a7b52c62391.tar.lz
change-23b56fad3873b03a4b1f04e299104a7b52c62391.tar.xz
change-23b56fad3873b03a4b1f04e299104a7b52c62391.tar.zst
change-23b56fad3873b03a4b1f04e299104a7b52c62391.zip
Add filesystem exception handling where required
Diffstat (limited to 'src')
-rw-r--r--src/tracking/change_tracker.cc28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/tracking/change_tracker.cc b/src/tracking/change_tracker.cc
index 74e656f..0feae34 100644
--- a/src/tracking/change_tracker.cc
+++ b/src/tracking/change_tracker.cc
@@ -1,6 +1,6 @@
#include "change_tracker.h"
-#include <boost/optional.hpp>
+#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
namespace {
@@ -68,6 +68,11 @@ ChangeTracker::~ChangeTracker() {
}
}
+// Both `is_tracked` and `create_child` may throw filesystem exceptions
+// if the given path doesn't exist. We are able to disregard this as
+// both functions are only and should only be called when existance is
+// guaranteed. If this is not the case we want the library to fail visibly.
+
bool ChangeTracker::is_tracked(const std::string& file_path) const {
return this->children_.find(
boost::filesystem::canonical(file_path).string()
@@ -102,13 +107,20 @@ bool ChangeTracker::track(const std::string& file_path) {
auto result = this->create_child(file_path);
if ( std::get<EMPLACE_SUCCESS>(result) ) {
- boost::filesystem::ifstream file(
- std::get<FILE_PATH>(*result.first)
- );
-
- if ( file.is_open() ) {
- *std::get<FILE_CONTENT>(*result.first) << file.rdbuf();
- std::get<FILE_CONTENT>(*result.first)->sync();
+ try {
+ boost::filesystem::ifstream file(
+ std::get<FILE_PATH>(*result.first)
+ );
+
+ if ( file.is_open() ) {
+ *std::get<FILE_CONTENT>(*result.first) << file.rdbuf();
+ std::get<FILE_CONTENT>(*result.first)->sync();
+ }
+ } catch ( boost::filesystem::filesystem_error& ) {
+ // we catch this exception in case the parent process is
+ // performing system calls that are allowed to fail - e.g.
+ // in this instance writing to files that we are not allowed
+ // to read.
}
return true;