diff --git a/src/wutil.cpp b/src/wutil.cpp index b12c0c5c3..b9601ba06 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -26,6 +26,7 @@ #include "common.h" #include "fallback.h" // IWYU pragma: keep +#include "fds.h" #include "flog.h" #include "wcstringutil.h" @@ -764,6 +765,10 @@ file_id_t file_id_for_fd(int fd) { return result; } +file_id_t file_id_for_fd(const autoclose_fd_t &fd) { + return file_id_for_fd(fd.fd()); +} + file_id_t file_id_for_path(const wcstring &path) { file_id_t result = kInvalidFileID; struct stat buf = {}; @@ -786,6 +791,20 @@ bool file_id_t::operator==(const file_id_t &rhs) const { return this->compare_fi bool file_id_t::operator!=(const file_id_t &rhs) const { return !(*this == rhs); } + +wcstring file_id_t::dump() const { + using llong = long long; + wcstring result; + append_format(result, L" device: %lld\n", llong(device)); + append_format(result, L" inode: %lld\n", llong(inode)); + append_format(result, L" size: %lld\n", llong(size)); + append_format(result, L" change: %lld\n", llong(change_seconds)); + append_format(result, L"change_nano: %lld\n", llong(change_nanoseconds)); + append_format(result, L" mod: %lld\n", llong(mod_seconds)); + append_format(result, L" mod_nano: %lld", llong(mod_nanoseconds)); + return result; +} + template int compare(T a, T b) { if (a < b) { diff --git a/src/wutil.h b/src/wutil.h index 8fecde585..6698b29f9 100644 --- a/src/wutil.h +++ b/src/wutil.h @@ -19,6 +19,8 @@ #include "common.h" #include "maybe.h" +class autoclose_fd_t; + /// Wide character version of opendir(). Note that opendir() is guaranteed to set close-on-exec by /// POSIX (hooray). DIR *wopendir(const wcstring &name); @@ -155,6 +157,8 @@ struct file_id_t { static file_id_t from_stat(const struct stat &buf); + wcstring dump() const; + private: int compare_file_id(const file_id_t &rhs) const; }; @@ -184,6 +188,7 @@ struct hash { #endif file_id_t file_id_for_fd(int fd); +file_id_t file_id_for_fd(const autoclose_fd_t &fd); file_id_t file_id_for_path(const wcstring &path); file_id_t file_id_for_path(const std::string &path);