@@ -75,7 +75,14 @@ impl Stat {
75
75
}
76
76
}
77
77
78
- /// Creates stat information from the result of `symlink_metadata`.
78
+ /// Creates stat information from file metadata.
79
+ ///
80
+ /// The information passed to this function should originate from a function like
81
+ /// `symlink_metadata`/`lstat` or `File::metadata`/`fstat`.
82
+ ///
83
+ /// The data are adjusted for use in the index, using default values of fields that are not
84
+ /// meaningful on the target operating system or that are unavailable, and truncating data
85
+ /// where doing so does not lose essential information for keeping track of file status.
79
86
pub fn from_fs ( stat : & crate :: fs:: Metadata ) -> Result < Stat , SystemTimeError > {
80
87
let mtime = stat. modified ( ) . unwrap_or ( std:: time:: UNIX_EPOCH ) ;
81
88
let ctime = stat. created ( ) . unwrap_or ( std:: time:: UNIX_EPOCH ) ;
@@ -88,23 +95,22 @@ impl Stat {
88
95
ino : 0 ,
89
96
uid : 0 ,
90
97
gid : 0 ,
91
- // truncation to 32 bits is on purpose (git does the same).
98
+ // Truncation to 32 bits is on purpose (git does the same).
92
99
size : stat. len ( ) as u32 ,
93
100
} ;
94
101
#[ cfg( not( windows) ) ]
95
102
let res = {
96
103
Stat {
97
104
mtime : mtime. try_into ( ) . unwrap_or_default ( ) ,
98
105
ctime : ctime. try_into ( ) . unwrap_or_default ( ) ,
99
- // truncating to 32 bits is fine here because
100
- // that's what the linux syscalls returns
101
- // just rust upcasts to 64 bits for some reason?
102
- // numbers this large are impractical anyway (that's a lot of hard-drives).
106
+ // Truncating the device and inode numbers to 32 bits should be fine even on
107
+ // targets where they are represented as 64 bits, since we do not use them
108
+ // precisely for tracking changes and we do not map them back to the inode.
103
109
dev : stat. dev ( ) as u32 ,
104
110
ino : stat. ino ( ) as u32 ,
105
111
uid : stat. uid ( ) ,
106
112
gid : stat. gid ( ) ,
107
- // truncation to 32 bits is on purpose (git does the same).
113
+ // Truncation to 32 bits is on purpose (git does the same).
108
114
size : stat. len ( ) as u32 ,
109
115
}
110
116
} ;
0 commit comments