mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-21 00:51:43 +08:00
Minor improvements to file_id_t
This commit is contained in:
parent
ba2e7db7e8
commit
1c20bdcbf9
|
@ -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 <typename T>
|
||||
int compare(T a, T b) {
|
||||
if (a < b) {
|
||||
|
|
|
@ -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<file_id_t> {
|
|||
#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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user