aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-02-06 23:33:47 +0100
committerAdrian Kummerlaender2016-02-06 23:33:47 +0100
commitbfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3 (patch)
tree7367fa5d4b72c1cf40e951753c7ff9068afbdd5d
parent8923cf4f88ae6e665b0571ac435c72f62461efb3 (diff)
downloadchange-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.tar
change-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.tar.gz
change-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.tar.bz2
change-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.tar.lz
change-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.tar.xz
change-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.tar.zst
change-bfa7c9e7ea1f818482a4205a500e87fb9d8a8ec3.zip
Prevent deleted files from being displayed using `diff`
-rw-r--r--src/tracking/change_tracker.cc30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/tracking/change_tracker.cc b/src/tracking/change_tracker.cc
index 9416576..c32a3c5 100644
--- a/src/tracking/change_tracker.cc
+++ b/src/tracking/change_tracker.cc
@@ -7,7 +7,7 @@ namespace {
// constants for increasing pair access readability
constexpr unsigned int EMPLACE_SUCCESS = 1;
-constexpr unsigned int FILE_NAME = 0;
+constexpr unsigned int FILE_PATH = 0;
constexpr unsigned int FILE_CONTENT = 1;
boost::process::context getDefaultContext() {
@@ -48,19 +48,23 @@ ChangeTracker::ChangeTracker(utility::Logger* logger):
ChangeTracker::~ChangeTracker() {
for ( auto&& tracked : this->children_ ) {
- boost::process::child diffProcess{
- boost::process::launch_shell(
- getDiffCommand(this->diff_cmd_, std::get<FILE_NAME>(tracked)),
- getDefaultContext()
- )
- };
+ const auto& tracked_path = std::get<FILE_PATH>(tracked);
- diffProcess.get_stdin() << std::get<FILE_CONTENT>(tracked)->rdbuf();
- diffProcess.get_stdin().close();
+ if ( boost::filesystem::exists(tracked_path) ) {
+ boost::process::child diffProcess{
+ boost::process::launch_shell(
+ getDiffCommand(this->diff_cmd_, tracked_path),
+ getDefaultContext()
+ )
+ };
- this->logger_->forward(diffProcess.get_stdout());
+ diffProcess.get_stdin() << std::get<FILE_CONTENT>(tracked)->rdbuf();
+ diffProcess.get_stdin().close();
- diffProcess.wait();
+ this->logger_->forward(diffProcess.get_stdout());
+
+ diffProcess.wait();
+ }
}
}
@@ -83,7 +87,7 @@ bool ChangeTracker::is_tracked(const std::string& file_path) const {
// reading the file from permanent storage. e.g. it opens all relevant
// file descriptors at launch and only reads the first block of the
// file contents until more is required. This leads to problems when
-// the tracked file is modified after `diff` has been spawned.
+// the tracked file is modified after `diff` has been spawned.
//
bool ChangeTracker::track(const std::string& file_path) {
const std::string full_file_path{
@@ -101,7 +105,7 @@ bool ChangeTracker::track(const std::string& file_path) {
if ( std::get<EMPLACE_SUCCESS>(result) ) {
boost::filesystem::ifstream file(
- std::get<FILE_NAME>(*result.first)
+ std::get<FILE_PATH>(*result.first)
);
if ( file.is_open() ) {