Skip to content

Commit 3121096

Browse files
authored
Remove StatExt, which was deprecated. (#1280)
Fix the `Stat` "secs" fields to be signed instead of unsigned, and remove `StatExt`, which was a workaround for the types incorrectly being unsigned.
1 parent 8270a91 commit 3121096

6 files changed

Lines changed: 40 additions & 107 deletions

File tree

src/backend/libc/fs/types.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,11 @@ pub struct Stat {
10351035
pub st_size: i64,
10361036
pub st_blksize: u32,
10371037
pub st_blocks: u64,
1038-
#[deprecated(note = "Use `rustix::fs::StatExt::atime` instead.")]
1039-
pub st_atime: u64,
1038+
pub st_atime: i64,
10401039
pub st_atime_nsec: u32,
1041-
#[deprecated(note = "Use `rustix::fs::StatExt::mtime` instead.")]
1042-
pub st_mtime: u64,
1040+
pub st_mtime: i64,
10431041
pub st_mtime_nsec: u32,
1044-
#[deprecated(note = "Use `rustix::fs::StatExt::ctime` instead.")]
1045-
pub st_ctime: u64,
1042+
pub st_ctime: i64,
10461043
pub st_ctime_nsec: u32,
10471044
pub st_ino: u64,
10481045
}

src/backend/linux_raw/fs/types.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,11 @@ pub struct Stat {
665665
pub st_size: i64,
666666
pub st_blksize: u32,
667667
pub st_blocks: u64,
668-
#[deprecated(note = "Use `rustix::fs::StatExt::atime` instead.")]
669-
pub st_atime: u64,
668+
pub st_atime: i64,
670669
pub st_atime_nsec: u32,
671-
#[deprecated(note = "Use `rustix::fs::StatExt::mtime` instead.")]
672-
pub st_mtime: u64,
670+
pub st_mtime: i64,
673671
pub st_mtime_nsec: u32,
674-
#[deprecated(note = "Use `rustix::fs::StatExt::ctime` instead.")]
675-
pub st_ctime: u64,
672+
pub st_ctime: i64,
676673
pub st_ctime_nsec: u32,
677674
pub st_ino: u64,
678675
}

src/fs/mod.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -133,62 +133,3 @@ pub use std::os::unix::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, Open
133133
#[cfg(feature = "std")]
134134
#[cfg(all(wasi_ext, target_os = "wasi"))]
135135
pub use std::os::wasi::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, OpenOptionsExt};
136-
137-
/// Extension trait for accessing timestamp fields of `Stat`.
138-
///
139-
/// Rustix's `Stat` type on some platforms has unsigned `st_mtime`,
140-
/// `st_atime`, and `st_ctime` fields. This is incorrect, as Unix defines
141-
/// these fields to be signed, with negative values representing dates before
142-
/// the Unix epoch. Until the next semver bump, these unsigned fields are
143-
/// deprecated, and this trait provides accessors which return their values
144-
/// as signed integers.
145-
#[cfg(unix)]
146-
pub trait StatExt {
147-
/// Return the value of the `st_atime` field, casted to the correct type.
148-
fn atime(&self) -> i64;
149-
/// Return the value of the `st_mtime` field, casted to the correct type.
150-
fn mtime(&self) -> i64;
151-
/// Return the value of the `st_ctime` field, casted to the correct type.
152-
fn ctime(&self) -> i64;
153-
}
154-
155-
#[cfg(all(
156-
unix,
157-
not(any(target_os = "aix", target_os = "hurd", target_os = "nto"))
158-
))]
159-
#[allow(deprecated)]
160-
impl StatExt for Stat {
161-
#[inline]
162-
fn atime(&self) -> i64 {
163-
self.st_atime as i64
164-
}
165-
166-
#[inline]
167-
fn mtime(&self) -> i64 {
168-
self.st_mtime as i64
169-
}
170-
171-
#[inline]
172-
fn ctime(&self) -> i64 {
173-
self.st_ctime as i64
174-
}
175-
}
176-
177-
#[cfg(any(target_os = "aix", target_os = "hurd", target_os = "nto"))]
178-
#[allow(deprecated)]
179-
impl StatExt for Stat {
180-
#[inline]
181-
fn atime(&self) -> i64 {
182-
self.st_atim.tv_sec as i64
183-
}
184-
185-
#[inline]
186-
fn mtime(&self) -> i64 {
187-
self.st_mtim.tv_sec as i64
188-
}
189-
190-
#[inline]
191-
fn ctime(&self) -> i64 {
192-
self.st_ctim.tv_sec as i64
193-
}
194-
}

tests/fs/futimens.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
22
#[test]
33
fn test_futimens() {
4-
use rustix::fs::{fstat, futimens, openat, Mode, OFlags, StatExt, Timespec, Timestamps, CWD};
4+
use rustix::fs::{fstat, futimens, openat, Mode, OFlags, Timespec, Timestamps, CWD};
55

66
let tmp = tempfile::tempdir().unwrap();
77
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
@@ -28,7 +28,7 @@ fn test_futimens() {
2828

2929
let after = fstat(&file).unwrap();
3030

31-
assert_eq!(times.last_modification.tv_sec as u64, after.mtime() as u64);
31+
assert_eq!(times.last_modification.tv_sec as u64, after.st_mtime as u64);
3232
#[cfg(not(target_os = "netbsd"))]
3333
assert_eq!(
3434
times.last_modification.tv_nsec as u64,

tests/fs/utimensat.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
22
#[test]
33
fn test_utimensat() {
4-
use rustix::fs::{
5-
openat, statat, utimensat, AtFlags, Mode, OFlags, StatExt, Timespec, Timestamps, CWD,
6-
};
4+
use rustix::fs::{openat, statat, utimensat, AtFlags, Mode, OFlags, Timespec, Timestamps, CWD};
75

86
let tmp = tempfile::tempdir().unwrap();
97
let dir = openat(
@@ -36,7 +34,7 @@ fn test_utimensat() {
3634

3735
let after = statat(&dir, "file", AtFlags::empty()).unwrap();
3836

39-
assert_eq!(times.last_modification.tv_sec as u64, after.mtime() as u64);
37+
assert_eq!(times.last_modification.tv_sec as u64, after.st_mtime as u64);
4038
#[cfg(not(target_os = "netbsd"))]
4139
assert_eq!(
4240
times.last_modification.tv_nsec as u64,
@@ -47,15 +45,15 @@ fn test_utimensat() {
4745
times.last_modification.tv_nsec as u64,
4846
after.st_mtimensec as u64
4947
);
50-
assert!(times.last_access.tv_sec as u64 >= after.atime() as u64);
48+
assert!(times.last_access.tv_sec as u64 >= after.st_atime as u64);
5149
#[cfg(not(target_os = "netbsd"))]
5250
assert!(
53-
times.last_access.tv_sec as u64 > after.atime() as u64
51+
times.last_access.tv_sec as u64 > after.st_atime as u64
5452
|| times.last_access.tv_nsec as u64 >= after.st_atime_nsec as u64
5553
);
5654
#[cfg(target_os = "netbsd")]
5755
assert!(
58-
times.last_access.tv_sec as u64 > after.atime() as u64
56+
times.last_access.tv_sec as u64 > after.st_atime as u64
5957
|| times.last_access.tv_nsec as u64 >= after.st_atimensec as u64
6058
);
6159
}

tests/fs/y2038.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#[test]
1010
fn test_y2038_with_utimensat() {
1111
use rustix::fs::{
12-
fstat, openat, statat, utimensat, AtFlags, Mode, OFlags, StatExt, Timespec, Timestamps, CWD,
12+
fstat, openat, statat, utimensat, AtFlags, Mode, OFlags, Timespec, Timestamps, CWD,
1313
};
1414

1515
let tmp = tempfile::tempdir().unwrap();
@@ -46,47 +46,47 @@ fn test_y2038_with_utimensat() {
4646
// Use `statat` to read back the timestamp.
4747
let stat = statat(&dir, "file", AtFlags::empty()).unwrap();
4848

49-
assert_eq!(TryInto::<u64>::try_into(stat.mtime()).unwrap(), m_sec);
49+
assert_eq!(TryInto::<u64>::try_into(stat.st_mtime).unwrap(), m_sec);
5050

5151
#[cfg(not(target_os = "netbsd"))]
5252
assert_eq!(stat.st_mtime_nsec as u32, m_nsec);
5353
#[cfg(target_os = "netbsd")]
5454
assert_eq!(stat.st_mtimensec as u32, m_nsec);
5555

56-
assert!(TryInto::<u64>::try_into(stat.atime()).unwrap() >= a_sec);
56+
assert!(TryInto::<u64>::try_into(stat.st_atime).unwrap() >= a_sec);
5757

5858
#[cfg(not(target_os = "netbsd"))]
5959
assert!(
60-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
60+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
6161
|| stat.st_atime_nsec as u32 >= a_nsec
6262
);
6363
#[cfg(target_os = "netbsd")]
6464
assert!(
65-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
65+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
6666
|| stat.st_atimensec as u32 >= a_nsec
6767
);
6868

6969
// Now test the same thing, but with `fstat`.
7070
let file = openat(&dir, "file", OFlags::RDONLY, Mode::empty()).unwrap();
7171
let stat = fstat(&file).unwrap();
7272

73-
assert_eq!(TryInto::<u64>::try_into(stat.mtime()).unwrap(), m_sec);
73+
assert_eq!(TryInto::<u64>::try_into(stat.st_mtime).unwrap(), m_sec);
7474

7575
#[cfg(not(target_os = "netbsd"))]
7676
assert_eq!(stat.st_mtime_nsec as u32, m_nsec);
7777
#[cfg(target_os = "netbsd")]
7878
assert_eq!(stat.st_mtimensec as u32, m_nsec);
7979

80-
assert!(TryInto::<u64>::try_into(stat.atime()).unwrap() >= a_sec);
80+
assert!(TryInto::<u64>::try_into(stat.st_atime).unwrap() >= a_sec);
8181

8282
#[cfg(not(target_os = "netbsd"))]
8383
assert!(
84-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
84+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
8585
|| stat.st_atime_nsec as u32 >= a_nsec
8686
);
8787
#[cfg(target_os = "netbsd")]
8888
assert!(
89-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
89+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
9090
|| stat.st_atimensec as u32 >= a_nsec
9191
);
9292
}
@@ -102,7 +102,7 @@ fn test_y2038_with_utimensat() {
102102
#[test]
103103
fn test_y2038_with_futimens() {
104104
use rustix::fs::{
105-
fstat, futimens, openat, statat, AtFlags, Mode, OFlags, StatExt, Timespec, Timestamps, CWD,
105+
fstat, futimens, openat, statat, AtFlags, Mode, OFlags, Timespec, Timestamps, CWD,
106106
};
107107

108108
let tmp = tempfile::tempdir().unwrap();
@@ -139,47 +139,47 @@ fn test_y2038_with_futimens() {
139139
// Use `statat` to read back the timestamp.
140140
let stat = statat(&dir, "file", AtFlags::empty()).unwrap();
141141

142-
assert_eq!(TryInto::<u64>::try_into(stat.mtime()).unwrap(), m_sec);
142+
assert_eq!(TryInto::<u64>::try_into(stat.st_mtime).unwrap(), m_sec);
143143

144144
#[cfg(not(target_os = "netbsd"))]
145145
assert_eq!(stat.st_mtime_nsec as u32, m_nsec);
146146
#[cfg(target_os = "netbsd")]
147147
assert_eq!(stat.st_mtimensec as u32, m_nsec);
148148

149-
assert!(TryInto::<u64>::try_into(stat.atime()).unwrap() >= a_sec);
149+
assert!(TryInto::<u64>::try_into(stat.st_atime).unwrap() >= a_sec);
150150

151151
#[cfg(not(target_os = "netbsd"))]
152152
assert!(
153-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
153+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
154154
|| stat.st_atime_nsec as u32 >= a_nsec
155155
);
156156
#[cfg(target_os = "netbsd")]
157157
assert!(
158-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
158+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
159159
|| stat.st_atimensec as u32 >= a_nsec
160160
);
161161

162162
// Now test the same thing, but with `fstat`.
163163
let file = openat(&dir, "file", OFlags::RDONLY, Mode::empty()).unwrap();
164164
let stat = fstat(&file).unwrap();
165165

166-
assert_eq!(TryInto::<u64>::try_into(stat.mtime()).unwrap(), m_sec);
166+
assert_eq!(TryInto::<u64>::try_into(stat.st_mtime).unwrap(), m_sec);
167167

168168
#[cfg(not(target_os = "netbsd"))]
169169
assert_eq!(stat.st_mtime_nsec as u32, m_nsec);
170170
#[cfg(target_os = "netbsd")]
171171
assert_eq!(stat.st_mtimensec as u32, m_nsec);
172172

173-
assert!(TryInto::<u64>::try_into(stat.atime()).unwrap() >= a_sec);
173+
assert!(TryInto::<u64>::try_into(stat.st_atime).unwrap() >= a_sec);
174174

175175
#[cfg(not(target_os = "netbsd"))]
176176
assert!(
177-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
177+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
178178
|| stat.st_atime_nsec as u32 >= a_nsec
179179
);
180180
#[cfg(target_os = "netbsd")]
181181
assert!(
182-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
182+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
183183
|| stat.st_atimensec as u32 >= a_nsec
184184
);
185185
}
@@ -193,7 +193,7 @@ fn test_y2038_with_futimens() {
193193
#[cfg(not(all(target_os = "emscripten", target_pointer_width = "32")))]
194194
#[test]
195195
fn test_y2038_with_futimens_and_stat() {
196-
use rustix::fs::{fstat, futimens, open, stat, Mode, OFlags, StatExt, Timespec, Timestamps};
196+
use rustix::fs::{fstat, futimens, open, stat, Mode, OFlags, Timespec, Timestamps};
197197

198198
let tmp = tempfile::tempdir().unwrap();
199199

@@ -233,47 +233,47 @@ fn test_y2038_with_futimens_and_stat() {
233233
// Use `statat` to read back the timestamp.
234234
let stat = stat(tmp.path().join("file")).unwrap();
235235

236-
assert_eq!(TryInto::<u64>::try_into(stat.mtime()).unwrap(), m_sec);
236+
assert_eq!(TryInto::<u64>::try_into(stat.st_mtime).unwrap(), m_sec);
237237

238238
#[cfg(not(target_os = "netbsd"))]
239239
assert_eq!(stat.st_mtime_nsec as u32, m_nsec);
240240
#[cfg(target_os = "netbsd")]
241241
assert_eq!(stat.st_mtimensec as u32, m_nsec);
242242

243-
assert!(TryInto::<u64>::try_into(stat.atime()).unwrap() >= a_sec);
243+
assert!(TryInto::<u64>::try_into(stat.st_atime).unwrap() >= a_sec);
244244

245245
#[cfg(not(target_os = "netbsd"))]
246246
assert!(
247-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
247+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
248248
|| stat.st_atime_nsec as u32 >= a_nsec
249249
);
250250
#[cfg(target_os = "netbsd")]
251251
assert!(
252-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
252+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
253253
|| stat.st_atimensec as u32 >= a_nsec
254254
);
255255

256256
// Now test the same thing, but with `fstat`.
257257
let file = open(tmp.path().join("file"), OFlags::RDONLY, Mode::empty()).unwrap();
258258
let stat = fstat(&file).unwrap();
259259

260-
assert_eq!(TryInto::<u64>::try_into(stat.mtime()).unwrap(), m_sec);
260+
assert_eq!(TryInto::<u64>::try_into(stat.st_mtime).unwrap(), m_sec);
261261

262262
#[cfg(not(target_os = "netbsd"))]
263263
assert_eq!(stat.st_mtime_nsec as u32, m_nsec);
264264
#[cfg(target_os = "netbsd")]
265265
assert_eq!(stat.st_mtimensec as u32, m_nsec);
266266

267-
assert!(TryInto::<u64>::try_into(stat.atime()).unwrap() >= a_sec);
267+
assert!(TryInto::<u64>::try_into(stat.st_atime).unwrap() >= a_sec);
268268

269269
#[cfg(not(target_os = "netbsd"))]
270270
assert!(
271-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
271+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
272272
|| stat.st_atime_nsec as u32 >= a_nsec
273273
);
274274
#[cfg(target_os = "netbsd")]
275275
assert!(
276-
TryInto::<u64>::try_into(stat.atime()).unwrap() > a_sec
276+
TryInto::<u64>::try_into(stat.st_atime).unwrap() > a_sec
277277
|| stat.st_atimensec as u32 >= a_nsec
278278
);
279279
}

0 commit comments

Comments
 (0)