##// END OF EJS Templates
rust-dirstate: make the reliable timestamp comparison more usable from outside...
Raphaël Gomès -
r52948:0529e1a4 default
parent child Browse files
Show More
@@ -116,7 +116,12 impl TruncatedTimestamp {
116 metadata: &fs::Metadata,
116 metadata: &fs::Metadata,
117 boundary: &Self,
117 boundary: &Self,
118 ) -> io::Result<Option<Self>> {
118 ) -> io::Result<Option<Self>> {
119 let mut mtime = Self::for_mtime_of(metadata)?;
119 Ok(Self::for_mtime_of(metadata)?.for_reliable_mtime_of_self(boundary))
120 }
121
122 /// See [`Self::for_reliable_mtime_of`]
123 pub fn for_reliable_mtime_of_self(&self, boundary: &Self) -> Option<Self> {
124 let mut new = *self;
120 // If the mtime of the ambiguous file is younger (or equal) to the
125 // If the mtime of the ambiguous file is younger (or equal) to the
121 // starting point of the `status` walk, we cannot garantee that
126 // starting point of the `status` walk, we cannot garantee that
122 // another, racy, write will not happen right after with the same mtime
127 // another, racy, write will not happen right after with the same mtime
@@ -126,23 +131,23 impl TruncatedTimestamp {
126 // mismatch between the current clock and previous file system
131 // mismatch between the current clock and previous file system
127 // operation. So mtime more than one days in the future are considered
132 // operation. So mtime more than one days in the future are considered
128 // fine.
133 // fine.
129 let reliable = if mtime.truncated_seconds == boundary.truncated_seconds
134 let reliable = if self.truncated_seconds == boundary.truncated_seconds
130 {
135 {
131 mtime.second_ambiguous = true;
136 new.second_ambiguous = true;
132 mtime.nanoseconds != 0
137 self.nanoseconds != 0
133 && boundary.nanoseconds != 0
138 && boundary.nanoseconds != 0
134 && mtime.nanoseconds < boundary.nanoseconds
139 && self.nanoseconds < boundary.nanoseconds
135 } else {
140 } else {
136 // `truncated_seconds` is less than 2**31,
141 // `truncated_seconds` is less than 2**31,
137 // so this does not overflow `u32`:
142 // so this does not overflow `u32`:
138 let one_day_later = boundary.truncated_seconds + 24 * 3600;
143 let one_day_later = boundary.truncated_seconds + 24 * 3600;
139 mtime.truncated_seconds < boundary.truncated_seconds
144 self.truncated_seconds < boundary.truncated_seconds
140 || mtime.truncated_seconds > one_day_later
145 || self.truncated_seconds > one_day_later
141 };
146 };
142 if reliable {
147 if reliable {
143 Ok(Some(mtime))
148 Some(new)
144 } else {
149 } else {
145 Ok(None)
150 None
146 }
151 }
147 }
152 }
148
153
General Comments 0
You need to be logged in to leave comments. Login now