diff options
author | Adrian Kummerlaender | 2015-12-24 00:11:06 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-12-24 00:11:06 +0100 |
commit | baf30b7b83822b7d6efd0c16761b8e42a1e96101 (patch) | |
tree | 33eebf92abdde2f2cfbba138bb506529a332955e /src | |
parent | cce63aca270c51fb3ce9790438e3c23864de0a87 (diff) | |
download | change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.gz change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.bz2 change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.lz change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.xz change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.zst change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.zip |
Match namespace and directory structure
Diffstat (limited to 'src')
-rw-r--r-- | src/change_log.cc | 29 | ||||
-rw-r--r-- | src/tracking/change_tracker.cc (renamed from src/change_tracker.cc) | 10 | ||||
-rw-r--r-- | src/tracking/change_tracker.h (renamed from src/change_tracker.h) | 12 | ||||
-rw-r--r-- | src/utility/io.h (renamed from src/io.h) | 20 | ||||
-rw-r--r-- | src/utility/logger.h (renamed from src/utility.h) | 10 |
5 files changed, 40 insertions, 41 deletions
diff --git a/src/change_log.cc b/src/change_log.cc index e128383..5d16449 100644 --- a/src/change_log.cc +++ b/src/change_log.cc @@ -5,19 +5,20 @@ #include <algorithm> #include <functional> -#include "io.h" -#include "utility.h" #include "actual_function.h" -#include "change_tracker.h" -static std::unique_ptr<io::FileDescriptorGuard> fd_guard; -static std::unique_ptr<utility::Logger> logger; -static std::unique_ptr<utility::ChangeTracker> tracker; +#include "utility/io.h" +#include "utility/logger.h" +#include "tracking/change_tracker.h" + +static std::unique_ptr<utility::FileDescriptorGuard> fd_guard; +static std::unique_ptr<utility::Logger> logger; +static std::unique_ptr<tracking::ChangeTracker> tracker; void init() __attribute__ ((constructor)); void init() { if ( getenv("CHANGE_LOG_TARGET") != NULL ) { - fd_guard = std::make_unique<io::FileDescriptorGuard>( + fd_guard = std::make_unique<utility::FileDescriptorGuard>( getenv("CHANGE_LOG_TARGET") ); logger = std::make_unique<utility::Logger>(*fd_guard); @@ -25,7 +26,7 @@ void init() { logger = std::make_unique<utility::Logger>(STDERR_FILENO); } - tracker = std::make_unique<utility::ChangeTracker>(logger.get()); + tracker = std::make_unique<tracking::ChangeTracker>(logger.get()); } void exit(int status) { @@ -40,8 +41,8 @@ void exit(int status) { } 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 ( utility::is_regular_file(fd) ) { + const std::string file_name{ utility::get_file_name(fd) }; if ( !tracker->is_tracked(file_name) ) { tracker->track(file_name); @@ -68,7 +69,7 @@ int rmdir(const char* path) { } int unlink(const char* path) { - if ( io::is_regular_file(path) ) { + if ( utility::is_regular_file(path) ) { logger->append("rm '" + std::string(path) + "'"); } @@ -79,15 +80,15 @@ int unlinkat(int dirfd, const char* path, int flags) { if ( dirfd == AT_FDCWD ) { logger->append("removed '" + std::string(path) + "'"); } else { - logger->append("removed '" + io::get_file_name(dirfd) + path + "'"); + logger->append("removed '" + utility::get_file_name(dirfd) + path + "'"); } return actual::unlinkat(dirfd, path, flags); } 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 ( ( prot & PROT_WRITE ) && utility::is_regular_file(fd) ) { + const std::string file_name{ utility::get_file_name(fd) }; if ( !tracker->is_tracked(file_name) ) { tracker->track(file_name); diff --git a/src/change_tracker.cc b/src/tracking/change_tracker.cc index 1373a8a..913604e 100644 --- a/src/change_tracker.cc +++ b/src/tracking/change_tracker.cc @@ -1,7 +1,5 @@ #include "change_tracker.h" -#include <sstream> - #include <boost/optional.hpp> #include <boost/filesystem/fstream.hpp> @@ -12,7 +10,7 @@ constexpr unsigned int EMPLACE_SUCCESS = 1; constexpr unsigned int FILE_NAME = 0; constexpr unsigned int DIFF_PROCESS = 1; -boost::process::context createContext() { +boost::process::context getDefaultContext() { boost::process::context context; context.environment = boost::process::self::get_environment(); @@ -24,7 +22,7 @@ boost::process::context createContext() { } -namespace utility { +namespace tracking { ChangeTracker::ChangeTracker(utility::Logger* logger): logger_(logger), @@ -54,7 +52,7 @@ bool ChangeTracker::is_tracked(const std::string& file_path) const { // is structured in the following sequence: // // diff -p - $file_path -// +// // This means that reading the final file contents is delegated to // `diff` while the initial file contents are read by this method // and written to `diff`'s standard input. @@ -72,7 +70,7 @@ bool ChangeTracker::track(const std::string& file_path) { auto result = this->children_.emplace( file_path, std::make_unique<boost::process::child>( - boost::process::launch_shell("diff -p - " + file_name, createContext()) + boost::process::launch_shell("diff -p - " + file_path, getDefaultContext()) ) ); diff --git a/src/change_tracker.h b/src/tracking/change_tracker.h index e8ffa32..54af4f7 100644 --- a/src/change_tracker.h +++ b/src/tracking/change_tracker.h @@ -1,13 +1,13 @@ -#ifndef CHANGE_SRC_CHANGE_TRACKER_H_ -#define CHANGE_SRC_CHANGE_TRACKER_H_ - -#include "utility.h" +#ifndef CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_ +#define CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_ #include <unordered_map> #include <boost/process.hpp> -namespace utility { +#include "utility/logger.h" + +namespace tracking { class ChangeTracker { public: @@ -29,4 +29,4 @@ class ChangeTracker { } -#endif // CHANGE_SRC_CHANGE_TRACKER_H_ +#endif // CHANGE_SRC_TRACKING_CHANGE_TRACKER_H_ diff --git a/src/io.h b/src/utility/io.h index 69caa5e..ed1f542 100644 --- a/src/io.h +++ b/src/utility/io.h @@ -1,5 +1,5 @@ -#ifndef CHANGE_SRC_IO_H_ -#define CHANGE_SRC_IO_H_ +#ifndef CHANGE_SRC_UTILITY_IO_H_ +#define CHANGE_SRC_UTILITY_IO_H_ #include <unistd.h> #include <dlfcn.h> @@ -8,28 +8,28 @@ #include <cstring> -namespace io { +namespace utility { class FileDescriptorGuard { public: FileDescriptorGuard(const std::string& path) { - this->fd = open(path.c_str(), O_CREAT | O_WRONLY | O_APPEND); + this->fd_ = open(path.c_str(), O_CREAT | O_WRONLY | O_APPEND); - if ( !this->fd ) { - this->fd = STDERR_FILENO; + if ( !this->fd_ ) { + this->fd_ = STDERR_FILENO; } } ~FileDescriptorGuard() { - close(this->fd); + close(this->fd_); } operator int() { - return this->fd; + return this->fd_; } private: - int fd; + int fd_; }; @@ -65,4 +65,4 @@ bool is_regular_file(const char* path) { } -#endif // CHANGE_SRC_IO_H_ +#endif // CHANGE_SRC_UTILITY_IO_H_ diff --git a/src/utility.h b/src/utility/logger.h index 1dc44ed..475f33d 100644 --- a/src/utility.h +++ b/src/utility/logger.h @@ -1,5 +1,5 @@ -#ifndef CHANGE_SRC_UTILITY_H_ -#define CHANGE_SRC_UTILITY_H_ +#ifndef CHANGE_SRC_LOGGER_H_ +#define CHANGE_SRC_LOGGER_H_ #include <ext/stdio_filebuf.h> @@ -13,7 +13,7 @@ class Logger { public: Logger(const int target_fd): buffer_(target_fd, std::ios::out), - stream_(&this->buffer) { } + stream_(&this->buffer_) { } void append(const std::string& msg) { this->stream_ << msg << std::endl; @@ -27,7 +27,7 @@ class Logger { // flag. // void forward(boost::process::pistream& stream) { - this->stream << std::string( + this->stream_ << std::string( (std::istreambuf_iterator<char>(stream)), (std::istreambuf_iterator<char>()) ); @@ -41,4 +41,4 @@ class Logger { } -#endif // CHANGE_SRC_UTILITY_H_ +#endif // CHANGE_SRC_LOGGER_H_ |