diff options
author | Adrian Kummerlaender | 2015-12-23 21:43:51 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-12-23 21:43:51 +0100 |
commit | cce63aca270c51fb3ce9790438e3c23864de0a87 (patch) | |
tree | 1dc5fe5357c7620345950189692130bd415bfd63 /src/change_log.cc | |
parent | b02091f847b94e94db465469e723fcf2aee81a01 (diff) | |
download | change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.gz change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.bz2 change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.lz change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.xz change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.zst change-cce63aca270c51fb3ce9790438e3c23864de0a87.zip |
Implement file change tracking using `diff`
The newly introduced `ChangeTracker` class is now keeping track of all tracked file in addition to spawning and managing a corresponding `diff` instance that enables printing pretty _patch-style_ change summaries to the logging target.
This commit introduces `boost-process` and `diff` as dependencies of this library.
Diffstat (limited to 'src/change_log.cc')
-rw-r--r-- | src/change_log.cc | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/src/change_log.cc b/src/change_log.cc index a9e485f..e128383 100644 --- a/src/change_log.cc +++ b/src/change_log.cc @@ -4,20 +4,18 @@ #include <algorithm> #include <functional> -#include <unordered_set> #include "io.h" #include "utility.h" #include "actual_function.h" +#include "change_tracker.h" -static std::unique_ptr<std::unordered_set<std::string>> tracked_files; -static std::unique_ptr<io::FileDescriptorGuard> fd_guard; -static std::unique_ptr<utility::Logger> logger; +static std::unique_ptr<io::FileDescriptorGuard> fd_guard; +static std::unique_ptr<utility::Logger> logger; +static std::unique_ptr<utility::ChangeTracker> tracker; void init() __attribute__ ((constructor)); void init() { - tracked_files = std::make_unique<std::unordered_set<std::string>>(); - if ( getenv("CHANGE_LOG_TARGET") != NULL ) { fd_guard = std::make_unique<io::FileDescriptorGuard>( getenv("CHANGE_LOG_TARGET") @@ -26,6 +24,8 @@ void init() { } else { logger = std::make_unique<utility::Logger>(STDERR_FILENO); } + + tracker = std::make_unique<utility::ChangeTracker>(logger.get()); } void exit(int status) { @@ -39,22 +39,12 @@ void exit(int status) { actual_exit(status); } -bool is_tracked_file(const std::string& file_name) { - return tracked_files->find(file_name) != tracked_files->end(); -} - -bool track_file(const std::string& file_name) { - return tracked_files->emplace(file_name).second; -} - ssize_t write(int fd, const void* buffer, size_t count) { if ( io::is_regular_file(fd) ) { const std::string file_name{ io::get_file_name(fd) }; - if ( !is_tracked_file(file_name) ) { - track_file(file_name); - - logger->append("wrote to '" + file_name + "'"); + if ( !tracker->is_tracked(file_name) ) { + tracker->track(file_name); } } @@ -62,8 +52,8 @@ ssize_t write(int fd, const void* buffer, size_t count) { } int rename(const char* old_path, const char* new_path) { - if ( !is_tracked_file(old_path) ) { - track_file(old_path); + if ( !tracker->is_tracked(old_path) ) { + tracker->track(old_path); } logger->append("renamed '" + std::string(old_path) + "' to '" + std::string(new_path) + "'"); @@ -99,10 +89,8 @@ void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) if ( ( prot & PROT_WRITE ) && io::is_regular_file(fd) ) { const std::string file_name{ io::get_file_name(fd) }; - if ( !is_tracked_file(file_name) ) { - track_file(file_name); - - logger->append("mmap '" + file_name + "'"); + if ( !tracker->is_tracked(file_name) ) { + tracker->track(file_name); } } |