Skip to content

Commit 0ff88b5

Browse files
authored
dd: support nocache on android, freebsd (#12602)
1 parent bd9f32f commit 0ff88b5

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/uu/dd/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ doctest = false
2222
clap = { workspace = true }
2323
gcd = { workspace = true }
2424
libc = { workspace = true }
25+
rustix = { workspace = true }
2526
uucore = { workspace = true, features = [
2627
"format",
2728
"parser-size",
@@ -32,9 +33,6 @@ uucore = { workspace = true, features = [
3233
thiserror = { workspace = true }
3334
fluent = { workspace = true }
3435

35-
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
36-
rustix = { workspace = true, features = ["fs"] }
37-
3836
[[bin]]
3937
name = "dd"
4038
path = "src/main.rs"

src/uu/dd/src/dd.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use uucore::display::Quotable;
5252
use uucore::error::{FromIo, UResult};
5353
#[cfg(unix)]
5454
use uucore::error::{USimpleError, set_exit_code};
55-
#[cfg(target_os = "linux")]
55+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
5656
use uucore::show_if_err;
5757
use uucore::{format_usage, show_error};
5858

@@ -305,7 +305,7 @@ impl Source {
305305
/// source. This function informs the kernel that the specified
306306
/// portion of the source is no longer needed. If not possible,
307307
/// then this function returns an error.
308-
#[cfg(target_os = "linux")]
308+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
309309
fn discard_cache(&self, offset: u64, len: u64) -> io::Result<()> {
310310
#[allow(clippy::match_wildcard_for_single_variants)]
311311
match self {
@@ -492,9 +492,12 @@ impl Input<'_> {
492492
/// the input file is no longer needed. If not possible, then this
493493
/// function prints an error message to stderr and sets the exit
494494
/// status code to 1.
495-
#[cfg_attr(not(target_os = "linux"), allow(clippy::unused_self, unused_variables))]
495+
#[cfg_attr(
496+
not(any(target_os = "linux", target_os = "android", target_os = "freebsd")),
497+
allow(clippy::unused_self, unused_variables)
498+
)]
496499
fn discard_cache(&self, offset: u64, len: u64) {
497-
#[cfg(target_os = "linux")]
500+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
498501
{
499502
let file = self
500503
.settings
@@ -507,11 +510,7 @@ impl Input<'_> {
507510
)
508511
);
509512
}
510-
#[cfg(not(target_os = "linux"))]
511-
{
512-
// TODO Is there a way to discard filesystem cache on
513-
// these other operating systems?
514-
}
513+
// TODO: Is there a way to discard filesystem cache on other targets?
515514
}
516515

517516
/// Fills a given buffer.
@@ -693,7 +692,7 @@ impl Dest {
693692
/// destination. This function informs the kernel that the
694693
/// specified portion of the destination is no longer needed. If
695694
/// not possible, then this function returns an error.
696-
#[cfg(target_os = "linux")]
695+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
697696
fn discard_cache(&self, offset: u64, len: u64) -> io::Result<()> {
698697
match self {
699698
Self::File(f, _) => {
@@ -935,9 +934,12 @@ impl<'a> Output<'a> {
935934
/// the output file is no longer needed. If not possible, then
936935
/// this function prints an error message to stderr and sets the
937936
/// exit status code to 1.
938-
#[cfg_attr(not(target_os = "linux"), allow(clippy::unused_self, unused_variables))]
937+
#[cfg_attr(
938+
not(any(target_os = "linux", target_os = "android", target_os = "freebsd")),
939+
allow(clippy::unused_self, unused_variables)
940+
)]
939941
fn discard_cache(&self, offset: u64, len: u64) {
940-
#[cfg(target_os = "linux")]
942+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
941943
{
942944
let file = self
943945
.settings
@@ -950,11 +952,7 @@ impl<'a> Output<'a> {
950952
)
951953
);
952954
}
953-
#[cfg(not(target_os = "linux"))]
954-
{
955-
// TODO Is there a way to discard filesystem cache on
956-
// these other operating systems?
957-
}
955+
// TODO Is there a way to discard filesystem cache on other targets?
958956
}
959957

960958
/// writes a block of data. optionally retries when first try didn't complete

0 commit comments

Comments
 (0)