From b02091f847b94e94db465469e723fcf2aee81a01 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 21 Dec 2015 12:18:46 +0100 Subject: Add file mode check in `unlink` --- src/change_log.cc | 10 ++++++---- src/io.h | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/change_log.cc b/src/change_log.cc index 8ff1475..a9e485f 100644 --- a/src/change_log.cc +++ b/src/change_log.cc @@ -29,14 +29,14 @@ void init() { } void exit(int status) { - __attribute__((__noreturn__)) void(*real_exit)(int) = nullptr; + __attribute__((__noreturn__)) void(*actual_exit)(int) = nullptr; const void* symbol_address = dlsym(RTLD_NEXT, "exit"); - std::memcpy(&real_exit, &symbol_address, sizeof(symbol_address)); + std::memcpy(&actual_exit, &symbol_address, sizeof(symbol_address)); logger->append("exit"); - real_exit(status); + actual_exit(status); } bool is_tracked_file(const std::string& file_name) { @@ -78,7 +78,9 @@ int rmdir(const char* path) { } int unlink(const char* path) { - logger->append("removed '" + std::string(path) + "'"); + if ( io::is_regular_file(path) ) { + logger->append("rm '" + std::string(path) + "'"); + } return actual::unlink(path); } diff --git a/src/io.h b/src/io.h index 676ebac..69caa5e 100644 --- a/src/io.h +++ b/src/io.h @@ -56,6 +56,13 @@ bool is_regular_file(int fd) { return S_ISREG(fd_stat.st_mode); } +bool is_regular_file(const char* path) { + struct stat fd_stat; + lstat(path, &fd_stat); + + return S_ISREG(fd_stat.st_mode); +} + } #endif // CHANGE_SRC_IO_H_ -- cgit v1.2.3