|
| 1 | +commit 15909315c49d896281fa6564974924454d094ac8 |
| 2 | +Author: Ruben De Smet < [email protected]> |
| 3 | +Date: Mon Oct 23 20:39:13 2023 +0200 |
| 4 | + |
| 5 | + Revert "Use statx's 64-bit times on 32-bit linux-gnu" |
| 6 | + |
| 7 | + Additionally adds a `dead_code` lint supression on SystemTime::new. |
| 8 | + |
| 9 | + This reverts commit fec4818fdb40c82679f57fa7f26fcddc1a874c13. |
| 10 | + |
| 11 | +diff --git a/library/std/src/os/linux/fs.rs b/library/std/src/os/linux/fs.rs |
| 12 | +index 479bbcc17a8..2e90d8d6be7 100644 |
| 13 | +--- a/library/std/src/os/linux/fs.rs |
| 14 | ++++ b/library/std/src/os/linux/fs.rs |
| 15 | +@@ -356,34 +356,19 @@ fn st_size(&self) -> u64 { |
| 16 | + self.as_inner().as_inner().st_size as u64 |
| 17 | + } |
| 18 | + fn st_atime(&self) -> i64 { |
| 19 | +- let file_attr = self.as_inner(); |
| 20 | +- #[cfg(all(target_env = "gnu", target_pointer_width = "32"))] |
| 21 | +- if let Some(atime) = file_attr.stx_atime() { |
| 22 | +- return atime.tv_sec; |
| 23 | +- } |
| 24 | +- file_attr.as_inner().st_atime as i64 |
| 25 | ++ self.as_inner().as_inner().st_atime as i64 |
| 26 | + } |
| 27 | + fn st_atime_nsec(&self) -> i64 { |
| 28 | + self.as_inner().as_inner().st_atime_nsec as i64 |
| 29 | + } |
| 30 | + fn st_mtime(&self) -> i64 { |
| 31 | +- let file_attr = self.as_inner(); |
| 32 | +- #[cfg(all(target_env = "gnu", target_pointer_width = "32"))] |
| 33 | +- if let Some(mtime) = file_attr.stx_mtime() { |
| 34 | +- return mtime.tv_sec; |
| 35 | +- } |
| 36 | +- file_attr.as_inner().st_mtime as i64 |
| 37 | ++ self.as_inner().as_inner().st_mtime as i64 |
| 38 | + } |
| 39 | + fn st_mtime_nsec(&self) -> i64 { |
| 40 | + self.as_inner().as_inner().st_mtime_nsec as i64 |
| 41 | + } |
| 42 | + fn st_ctime(&self) -> i64 { |
| 43 | +- let file_attr = self.as_inner(); |
| 44 | +- #[cfg(all(target_env = "gnu", target_pointer_width = "32"))] |
| 45 | +- if let Some(ctime) = file_attr.stx_ctime() { |
| 46 | +- return ctime.tv_sec; |
| 47 | +- } |
| 48 | +- file_attr.as_inner().st_ctime as i64 |
| 49 | ++ self.as_inner().as_inner().st_ctime as i64 |
| 50 | + } |
| 51 | + fn st_ctime_nsec(&self) -> i64 { |
| 52 | + self.as_inner().as_inner().st_ctime_nsec as i64 |
| 53 | +diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs |
| 54 | +index b5cc8038ca4..e65dcfcd78b 100644 |
| 55 | +--- a/library/std/src/sys/unix/fs.rs |
| 56 | ++++ b/library/std/src/sys/unix/fs.rs |
| 57 | +@@ -115,19 +115,10 @@ struct StatxExtraFields { |
| 58 | + // This is needed to check if btime is supported by the filesystem. |
| 59 | + stx_mask: u32, |
| 60 | + stx_btime: libc::statx_timestamp, |
| 61 | +- // With statx, we can overcome 32-bit `time_t` too. |
| 62 | +- #[cfg(target_pointer_width = "32")] |
| 63 | +- stx_atime: libc::statx_timestamp, |
| 64 | +- #[cfg(target_pointer_width = "32")] |
| 65 | +- stx_ctime: libc::statx_timestamp, |
| 66 | +- #[cfg(target_pointer_width = "32")] |
| 67 | +- stx_mtime: libc::statx_timestamp, |
| 68 | +- |
| 69 | + } |
| 70 | + |
| 71 | +- // We prefer `statx` on Linux if available, which contains file creation time, |
| 72 | +- // as well as 64-bit timestamps of all kinds. |
| 73 | +- // Default `stat64` contains no creation time and may have 32-bit `time_t`. |
| 74 | ++ // We prefer `statx` on Linux if available, which contains file creation time. |
| 75 | ++ // Default `stat64` contains no creation time. |
| 76 | + unsafe fn try_statx( |
| 77 | + fd: c_int, |
| 78 | + path: *const c_char, |
| 79 | +@@ -203,13 +194,6 @@ fn statx( |
| 80 | + let extra = StatxExtraFields { |
| 81 | + stx_mask: buf.stx_mask, |
| 82 | + stx_btime: buf.stx_btime, |
| 83 | +- // Store full times to avoid 32-bit `time_t` truncation. |
| 84 | +- #[cfg(target_pointer_width = "32")] |
| 85 | +- stx_atime: buf.stx_atime, |
| 86 | +- #[cfg(target_pointer_width = "32")] |
| 87 | +- stx_ctime: buf.stx_ctime, |
| 88 | +- #[cfg(target_pointer_width = "32")] |
| 89 | +- stx_mtime: buf.stx_mtime, |
| 90 | + }; |
| 91 | + |
| 92 | + Some(Ok(FileAttr { stat, statx_extra_fields: Some(extra) })) |
| 93 | +@@ -331,36 +315,6 @@ impl FileAttr { |
| 94 | + fn from_stat64(stat: stat64) -> Self { |
| 95 | + Self { stat, statx_extra_fields: None } |
| 96 | + } |
| 97 | +- |
| 98 | +- #[cfg(target_pointer_width = "32")] |
| 99 | +- pub fn stx_mtime(&self) -> Option<&libc::statx_timestamp> { |
| 100 | +- if let Some(ext) = &self.statx_extra_fields { |
| 101 | +- if (ext.stx_mask & libc::STATX_MTIME) != 0 { |
| 102 | +- return Some(&ext.stx_mtime); |
| 103 | +- } |
| 104 | +- } |
| 105 | +- None |
| 106 | +- } |
| 107 | +- |
| 108 | +- #[cfg(target_pointer_width = "32")] |
| 109 | +- pub fn stx_atime(&self) -> Option<&libc::statx_timestamp> { |
| 110 | +- if let Some(ext) = &self.statx_extra_fields { |
| 111 | +- if (ext.stx_mask & libc::STATX_ATIME) != 0 { |
| 112 | +- return Some(&ext.stx_atime); |
| 113 | +- } |
| 114 | +- } |
| 115 | +- None |
| 116 | +- } |
| 117 | +- |
| 118 | +- #[cfg(target_pointer_width = "32")] |
| 119 | +- pub fn stx_ctime(&self) -> Option<&libc::statx_timestamp> { |
| 120 | +- if let Some(ext) = &self.statx_extra_fields { |
| 121 | +- if (ext.stx_mask & libc::STATX_CTIME) != 0 { |
| 122 | +- return Some(&ext.stx_ctime); |
| 123 | +- } |
| 124 | +- } |
| 125 | +- None |
| 126 | +- } |
| 127 | + } |
| 128 | + } else { |
| 129 | + impl FileAttr { |
| 130 | +@@ -386,15 +340,24 @@ pub fn file_type(&self) -> FileType { |
| 131 | + #[cfg(target_os = "netbsd")] |
| 132 | + impl FileAttr { |
| 133 | + pub fn modified(&self) -> io::Result<SystemTime> { |
| 134 | +- Ok(SystemTime::new(self.stat.st_mtime as i64, self.stat.st_mtimensec as i64)) |
| 135 | ++ Ok(SystemTime::from(libc::timespec { |
| 136 | ++ tv_sec: self.stat.st_mtime as libc::time_t, |
| 137 | ++ tv_nsec: self.stat.st_mtimensec as libc::c_long, |
| 138 | ++ })) |
| 139 | + } |
| 140 | + |
| 141 | + pub fn accessed(&self) -> io::Result<SystemTime> { |
| 142 | +- Ok(SystemTime::new(self.stat.st_atime as i64, self.stat.st_atimensec as i64)) |
| 143 | ++ Ok(SystemTime::from(libc::timespec { |
| 144 | ++ tv_sec: self.stat.st_atime as libc::time_t, |
| 145 | ++ tv_nsec: self.stat.st_atimensec as libc::c_long, |
| 146 | ++ })) |
| 147 | + } |
| 148 | + |
| 149 | + pub fn created(&self) -> io::Result<SystemTime> { |
| 150 | +- Ok(SystemTime::new(self.stat.st_birthtime as i64, self.stat.st_birthtimensec as i64)) |
| 151 | ++ Ok(SystemTime::from(libc::timespec { |
| 152 | ++ tv_sec: self.stat.st_birthtime as libc::time_t, |
| 153 | ++ tv_nsec: self.stat.st_birthtimensec as libc::c_long, |
| 154 | ++ })) |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | +@@ -402,19 +365,18 @@ pub fn created(&self) -> io::Result<SystemTime> { |
| 159 | + impl FileAttr { |
| 160 | + #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] |
| 161 | + pub fn modified(&self) -> io::Result<SystemTime> { |
| 162 | +- #[cfg(target_pointer_width = "32")] |
| 163 | +- cfg_has_statx! { |
| 164 | +- if let Some(mtime) = self.stx_mtime() { |
| 165 | +- return Ok(SystemTime::new(mtime.tv_sec, mtime.tv_nsec as i64)); |
| 166 | +- } |
| 167 | +- } |
| 168 | +- |
| 169 | +- Ok(SystemTime::new(self.stat.st_mtime as i64, self.stat.st_mtime_nsec as i64)) |
| 170 | ++ Ok(SystemTime::from(libc::timespec { |
| 171 | ++ tv_sec: self.stat.st_mtime as libc::time_t, |
| 172 | ++ tv_nsec: self.stat.st_mtime_nsec as _, |
| 173 | ++ })) |
| 174 | + } |
| 175 | + |
| 176 | + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] |
| 177 | + pub fn modified(&self) -> io::Result<SystemTime> { |
| 178 | +- Ok(SystemTime::new(self.stat.st_mtime as i64, 0)) |
| 179 | ++ Ok(SystemTime::from(libc::timespec { |
| 180 | ++ tv_sec: self.stat.st_mtime as libc::time_t, |
| 181 | ++ tv_nsec: 0, |
| 182 | ++ })) |
| 183 | + } |
| 184 | + |
| 185 | + #[cfg(target_os = "horizon")] |
| 186 | +@@ -424,19 +386,18 @@ pub fn modified(&self) -> io::Result<SystemTime> { |
| 187 | + |
| 188 | + #[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] |
| 189 | + pub fn accessed(&self) -> io::Result<SystemTime> { |
| 190 | +- #[cfg(target_pointer_width = "32")] |
| 191 | +- cfg_has_statx! { |
| 192 | +- if let Some(atime) = self.stx_atime() { |
| 193 | +- return Ok(SystemTime::new(atime.tv_sec, atime.tv_nsec as i64)); |
| 194 | +- } |
| 195 | +- } |
| 196 | +- |
| 197 | +- Ok(SystemTime::new(self.stat.st_atime as i64, self.stat.st_atime_nsec as i64)) |
| 198 | ++ Ok(SystemTime::from(libc::timespec { |
| 199 | ++ tv_sec: self.stat.st_atime as libc::time_t, |
| 200 | ++ tv_nsec: self.stat.st_atime_nsec as _, |
| 201 | ++ })) |
| 202 | + } |
| 203 | + |
| 204 | + #[cfg(any(target_os = "vxworks", target_os = "espidf"))] |
| 205 | + pub fn accessed(&self) -> io::Result<SystemTime> { |
| 206 | +- Ok(SystemTime::new(self.stat.st_atime as i64, 0)) |
| 207 | ++ Ok(SystemTime::from(libc::timespec { |
| 208 | ++ tv_sec: self.stat.st_atime as libc::time_t, |
| 209 | ++ tv_nsec: 0, |
| 210 | ++ })) |
| 211 | + } |
| 212 | + |
| 213 | + #[cfg(target_os = "horizon")] |
| 214 | +@@ -452,7 +413,10 @@ pub fn accessed(&self) -> io::Result<SystemTime> { |
| 215 | + target_os = "watchos", |
| 216 | + ))] |
| 217 | + pub fn created(&self) -> io::Result<SystemTime> { |
| 218 | +- Ok(SystemTime::new(self.stat.st_birthtime as i64, self.stat.st_birthtime_nsec as i64)) |
| 219 | ++ Ok(SystemTime::from(libc::timespec { |
| 220 | ++ tv_sec: self.stat.st_birthtime as libc::time_t, |
| 221 | ++ tv_nsec: self.stat.st_birthtime_nsec as libc::c_long, |
| 222 | ++ })) |
| 223 | + } |
| 224 | + |
| 225 | + #[cfg(not(any( |
| 226 | +@@ -466,7 +430,10 @@ pub fn created(&self) -> io::Result<SystemTime> { |
| 227 | + cfg_has_statx! { |
| 228 | + if let Some(ext) = &self.statx_extra_fields { |
| 229 | + return if (ext.stx_mask & libc::STATX_BTIME) != 0 { |
| 230 | +- Ok(SystemTime::new(ext.stx_btime.tv_sec, ext.stx_btime.tv_nsec as i64)) |
| 231 | ++ Ok(SystemTime::from(libc::timespec { |
| 232 | ++ tv_sec: ext.stx_btime.tv_sec as libc::time_t, |
| 233 | ++ tv_nsec: ext.stx_btime.tv_nsec as _, |
| 234 | ++ })) |
| 235 | + } else { |
| 236 | + Err(io::const_io_error!( |
| 237 | + io::ErrorKind::Uncategorized, |
| 238 | +diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs |
| 239 | +index dff973f59d1..067b08f05cc 100644 |
| 240 | +--- a/library/std/src/sys/unix/time.rs |
| 241 | ++++ b/library/std/src/sys/unix/time.rs |
| 242 | +@@ -19,6 +19,7 @@ pub(in crate::sys::unix) struct Timespec { |
| 243 | + |
| 244 | + impl SystemTime { |
| 245 | + #[cfg_attr(target_os = "horizon", allow(unused))] |
| 246 | ++ #[cfg_attr(target_env = "gnu", allow(dead_code))] |
| 247 | + pub fn new(tv_sec: i64, tv_nsec: i64) -> SystemTime { |
| 248 | + SystemTime { t: Timespec::new(tv_sec, tv_nsec) } |
| 249 | + } |
| 250 | + |
0 commit comments