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