Skip to content

Commit 827556a

Browse files
committed
fix(redox): gate Metadata and nix-dependent methods for Redox compatibility
Fixes compilation errors on Redox by properly gating code that depends on nix crate types (FileStat) which are not available on Redox. Changes: - Add direct libc import for Redox (nix::libc not available) - Gate Metadata struct, impl, and MetadataExt trait (use FileStat) - Gate metadata_at() and metadata() methods (return Metadata) - Revert unrelated locale test changes from commit 5704355 The Redox platform lacks support for nix::sys::stat::FileStat, causing build failures. These items now follow the existing pattern of returning "safe_traversal is not supported on Redox" errors via gated stub methods.
1 parent e4f13ef commit 827556a

File tree

2 files changed

+34
-50
lines changed

2 files changed

+34
-50
lines changed

src/uu/date/src/locale.rs

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -121,62 +121,39 @@ mod tests {
121121
#[test]
122122
fn test_default_format_contains_valid_codes() {
123123
let format = get_locale_default_format();
124-
// On platforms without locale support, fallback may not contain all codes
125-
#[cfg(any(
126-
target_os = "linux",
127-
target_vendor = "apple",
128-
target_os = "freebsd",
129-
target_os = "netbsd",
130-
target_os = "openbsd",
131-
target_os = "dragonfly"
132-
))]
133-
{
134-
// We only strictly check for timezone because ensure_timezone_in_format guarantees it
135-
assert!(format.contains("%Z") || format.contains("%z")); // timezone
136-
137-
// Other components depend on the system locale and might vary (e.g. %F, %c, etc.)
138-
// so we don't strictly assert %a or %b here.
139-
}
124+
assert!(format.contains("%a")); // abbreviated weekday
125+
assert!(format.contains("%b")); // abbreviated month
126+
assert!(format.contains("%Y") || format.contains("%y")); // year (4-digit or 2-digit)
127+
assert!(format.contains("%Z")); // timezone
140128
}
141129

142130
#[test]
143131
fn test_locale_format_structure() {
132+
// Verify we're using actual locale format strings, not hardcoded ones
144133
let format = get_locale_default_format();
134+
135+
// The format should not be empty
145136
assert!(!format.is_empty(), "Locale format should not be empty");
146-
#[cfg(any(
147-
target_os = "linux",
148-
target_vendor = "apple",
149-
target_os = "freebsd",
150-
target_os = "netbsd",
151-
target_os = "openbsd",
152-
target_os = "dragonfly"
153-
))]
154-
{
155-
let has_date_component = format.contains("%a")
156-
|| format.contains("%A")
157-
|| format.contains("%b")
158-
|| format.contains("%B")
159-
|| format.contains("%d")
160-
|| format.contains("%e")
161-
|| format.contains("%F") // YYYY-MM-DD
162-
|| format.contains("%D") // MM/DD/YY
163-
|| format.contains("%x") // Locale's date representation
164-
|| format.contains("%c") // Locale's date and time
165-
|| format.contains("%+"); // date(1) extended format
166-
assert!(has_date_component, "Format should contain date components");
167-
168-
let has_time_component = format.contains("%H")
169-
|| format.contains("%I")
170-
|| format.contains("%k")
171-
|| format.contains("%l")
172-
|| format.contains("%r")
173-
|| format.contains("%R")
174-
|| format.contains("%T")
175-
|| format.contains("%X")
176-
|| format.contains("%c") // Locale's date and time
177-
|| format.contains("%+"); // date(1) extended format
178-
assert!(has_time_component, "Format should contain time components");
179-
}
137+
138+
// Should contain date/time components
139+
let has_date_component = format.contains("%a")
140+
|| format.contains("%A")
141+
|| format.contains("%b")
142+
|| format.contains("%B")
143+
|| format.contains("%d")
144+
|| format.contains("%e");
145+
assert!(has_date_component, "Format should contain date components");
146+
147+
// Should contain time component (hour)
148+
let has_time_component = format.contains("%H")
149+
|| format.contains("%I")
150+
|| format.contains("%k")
151+
|| format.contains("%l")
152+
|| format.contains("%r")
153+
|| format.contains("%R")
154+
|| format.contains("%T")
155+
|| format.contains("%X");
156+
assert!(has_time_component, "Format should contain time components");
180157
}
181158

182159
#[test]

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use nix::libc;
3030
use nix::sys::stat::{FchmodatFlags, FileStat, Mode, fchmodat, fstatat};
3131
#[cfg(not(target_os = "redox"))]
3232
use nix::unistd::{Gid, Uid, UnlinkatFlags, fchown, fchownat, unlinkat};
33+
#[cfg(target_os = "redox")]
34+
use libc;
3335
use os_display::Quotable;
3436

3537
use crate::translate;
@@ -249,11 +251,13 @@ impl DirFd {
249251
}
250252

251253
/// Get metadata for a file relative to this directory
254+
#[cfg(not(target_os = "redox"))]
252255
pub fn metadata_at(&self, name: &OsStr, follow_symlinks: bool) -> io::Result<Metadata> {
253256
self.stat_at(name, follow_symlinks).map(Metadata::from_stat)
254257
}
255258

256259
/// Get metadata for this directory
260+
#[cfg(not(target_os = "redox"))]
257261
pub fn metadata(&self) -> io::Result<Metadata> {
258262
self.fstat().map(Metadata::from_stat)
259263
}
@@ -470,11 +474,13 @@ impl FileType {
470474
}
471475

472476
/// Metadata wrapper for safer access to file information
477+
#[cfg(not(target_os = "redox"))]
473478
#[derive(Debug, Clone)]
474479
pub struct Metadata {
475480
stat: FileStat,
476481
}
477482

483+
#[cfg(not(target_os = "redox"))]
478484
impl Metadata {
479485
pub fn from_stat(stat: FileStat) -> Self {
480486
Self { stat }
@@ -523,6 +529,7 @@ impl Metadata {
523529
}
524530

525531
// Add MetadataExt trait implementation for compatibility
532+
#[cfg(not(target_os = "redox"))]
526533
impl std::os::unix::fs::MetadataExt for Metadata {
527534
// st_dev type varies by platform (i32 on macOS, u64 on Linux)
528535
#[allow(clippy::unnecessary_cast)]

0 commit comments

Comments
 (0)