mirror of
https://github.com/nushell/nushell.git
synced 2025-04-26 22:28:19 +02:00
Termux/Android target support for v0.60.0 (#4956)
* Add android as target os for procfs-based ps * Turn off code for dealing with trash on platforms which are known to not support a standard trash protocol * Update lib.rs * Update lib.rs Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This commit is contained in:
parent
7a789d68a2
commit
71dd857926
@ -73,7 +73,6 @@ terminal_size = "0.1.17"
|
|||||||
thiserror = "1.0.29"
|
thiserror = "1.0.29"
|
||||||
titlecase = "1.1.0"
|
titlecase = "1.1.0"
|
||||||
toml = "0.5.8"
|
toml = "0.5.8"
|
||||||
trash = { version = "2.0.2", optional = true }
|
|
||||||
unicode-segmentation = "1.8.0"
|
unicode-segmentation = "1.8.0"
|
||||||
url = "2.2.1"
|
url = "2.2.1"
|
||||||
uuid = { version = "0.8.2", features = ["v4"] }
|
uuid = { version = "0.8.2", features = ["v4"] }
|
||||||
@ -85,6 +84,10 @@ zip = { version="0.5.9", optional = true }
|
|||||||
umask = "1.0.0"
|
umask = "1.0.0"
|
||||||
users = "0.11.0"
|
users = "0.11.0"
|
||||||
|
|
||||||
|
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies.trash]
|
||||||
|
version = "2.0.2"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[dependencies.polars]
|
[dependencies.polars]
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
optional = true
|
optional = true
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
#[cfg(feature = "trash-support")]
|
#[cfg(all(
|
||||||
|
feature = "trash-support",
|
||||||
|
not(target_os = "android"),
|
||||||
|
not(target_os = "ios")
|
||||||
|
))]
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::prelude::FileTypeExt;
|
use std::os::unix::prelude::FileTypeExt;
|
||||||
@ -35,7 +39,13 @@ impl Command for Rm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("rm")
|
let sig = Signature::build("rm");
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "trash-support",
|
||||||
|
not(target_os = "android"),
|
||||||
|
not(target_os = "ios")
|
||||||
|
))]
|
||||||
|
let sig = sig
|
||||||
.switch(
|
.switch(
|
||||||
"trash",
|
"trash",
|
||||||
"use the platform's recycle bin instead of permanently deleting",
|
"use the platform's recycle bin instead of permanently deleting",
|
||||||
@ -45,8 +55,8 @@ impl Command for Rm {
|
|||||||
"permanent",
|
"permanent",
|
||||||
"don't use recycle bin, delete permanently",
|
"don't use recycle bin, delete permanently",
|
||||||
Some('p'),
|
Some('p'),
|
||||||
)
|
);
|
||||||
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
sig.switch("recursive", "delete subdirectories recursively", Some('r'))
|
||||||
.switch("force", "suppress error when no file", Some('f'))
|
.switch("force", "suppress error when no file", Some('f'))
|
||||||
.switch("quiet", "suppress output showing files deleted", Some('q'))
|
.switch("quiet", "suppress output showing files deleted", Some('q'))
|
||||||
// .switch("interactive", "ask user to confirm action", Some('i'))
|
// .switch("interactive", "ask user to confirm action", Some('i'))
|
||||||
@ -69,12 +79,18 @@ impl Command for Rm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
let mut examples = vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Delete or move a file to the system trash (depending on 'rm_always_trash' config option)",
|
description: "Delete or move a file to the system trash (depending on 'rm_always_trash' config option)",
|
||||||
example: "rm file.txt",
|
example: "rm file.txt",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
}];
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "trash-support",
|
||||||
|
not(target_os = "android"),
|
||||||
|
not(target_os = "ios")
|
||||||
|
))]
|
||||||
|
examples.append(&mut vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Move a file to the system trash",
|
description: "Move a file to the system trash",
|
||||||
example: "rm --trash file.txt",
|
example: "rm --trash file.txt",
|
||||||
@ -85,12 +101,13 @@ impl Command for Rm {
|
|||||||
example: "rm --permanent file.txt",
|
example: "rm --permanent file.txt",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
]);
|
||||||
|
examples.push(Example {
|
||||||
description: "Delete a file, and suppress errors if no file is found",
|
description: "Delete a file, and suppress errors if no file is found",
|
||||||
example: "rm --force file.txt",
|
example: "rm --force file.txt",
|
||||||
result: None,
|
result: None,
|
||||||
}
|
});
|
||||||
]
|
examples
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +117,11 @@ fn rm(
|
|||||||
call: &Call,
|
call: &Call,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let trash = call.has_flag("trash");
|
let trash = call.has_flag("trash");
|
||||||
#[cfg(feature = "trash-support")]
|
#[cfg(all(
|
||||||
|
feature = "trash-support",
|
||||||
|
not(target_os = "android"),
|
||||||
|
not(target_os = "ios")
|
||||||
|
))]
|
||||||
let permanent = call.has_flag("permanent");
|
let permanent = call.has_flag("permanent");
|
||||||
let recursive = call.has_flag("recursive");
|
let recursive = call.has_flag("recursive");
|
||||||
let force = call.has_flag("force");
|
let force = call.has_flag("force");
|
||||||
@ -116,20 +137,26 @@ fn rm(
|
|||||||
|
|
||||||
let rm_always_trash = config.rm_always_trash;
|
let rm_always_trash = config.rm_always_trash;
|
||||||
|
|
||||||
#[cfg(not(feature = "trash-support"))]
|
#[cfg(any(
|
||||||
|
not(feature = "trash-support"),
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "ios"
|
||||||
|
))]
|
||||||
{
|
{
|
||||||
if rm_always_trash {
|
if rm_always_trash {
|
||||||
return Err(ShellError::SpannedLabeledError(
|
return Err(ShellError::SpannedLabeledError(
|
||||||
"Cannot execute `rm`; the current configuration specifies \
|
"Cannot execute `rm`; the current configuration specifies \
|
||||||
`rm_always_trash = true`, but the current nu executable was not \
|
`rm_always_trash = true`, but the current nu executable was not \
|
||||||
built with feature `trash_support`."
|
built with feature `trash_support` or trash is not supported on \
|
||||||
|
your platform."
|
||||||
.into(),
|
.into(),
|
||||||
"trash required to be true but not supported".into(),
|
"trash required to be true but not supported".into(),
|
||||||
span,
|
span,
|
||||||
));
|
));
|
||||||
} else if trash {
|
} else if trash {
|
||||||
return Err(ShellError::SpannedLabeledError(
|
return Err(ShellError::SpannedLabeledError(
|
||||||
"Cannot execute `rm` with option `--trash`; feature `trash-support` not enabled"
|
"Cannot execute `rm` with option `--trash`; feature `trash-support` not \
|
||||||
|
enabled or trash is not supported on your platform"
|
||||||
.into(),
|
.into(),
|
||||||
"this option is only available if nu is built with the `trash-support` feature"
|
"this option is only available if nu is built with the `trash-support` feature"
|
||||||
.into(),
|
.into(),
|
||||||
@ -241,7 +268,11 @@ fn rm(
|
|||||||
|| is_empty()
|
|| is_empty()
|
||||||
{
|
{
|
||||||
let result;
|
let result;
|
||||||
#[cfg(feature = "trash-support")]
|
#[cfg(all(
|
||||||
|
feature = "trash-support",
|
||||||
|
not(target_os = "android"),
|
||||||
|
not(target_os = "ios")
|
||||||
|
))]
|
||||||
{
|
{
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
result = if trash || (rm_always_trash && !permanent) {
|
result = if trash || (rm_always_trash && !permanent) {
|
||||||
@ -254,7 +285,11 @@ fn rm(
|
|||||||
std::fs::remove_dir_all(&f)
|
std::fs::remove_dir_all(&f)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "trash-support"))]
|
#[cfg(any(
|
||||||
|
not(feature = "trash-support"),
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "ios"
|
||||||
|
))]
|
||||||
{
|
{
|
||||||
result = if metadata.is_file() || is_socket || is_fifo {
|
result = if metadata.is_file() || is_socket || is_fifo {
|
||||||
std::fs::remove_file(&f)
|
std::fs::remove_file(&f)
|
||||||
|
@ -921,7 +921,12 @@ mod test {
|
|||||||
// this test assumes that there is a /root directory and that
|
// this test assumes that there is a /root directory and that
|
||||||
// the user running this test is not root or otherwise doesn't
|
// the user running this test is not root or otherwise doesn't
|
||||||
// have permission to read its contents
|
// have permission to read its contents
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(
|
||||||
|
unix,
|
||||||
|
not(target_os = "macos"),
|
||||||
|
not(target_os = "android"),
|
||||||
|
not(target_os = "ios")
|
||||||
|
))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_iteration_errors() {
|
fn test_iteration_errors() {
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -15,7 +15,7 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
||||||
procfs = "0.12.0"
|
procfs = "0.12.0"
|
||||||
users = "0.11"
|
users = "0.11"
|
||||||
which = "4"
|
which = "4"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||||
mod linux;
|
mod linux;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod macos;
|
mod macos;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod windows;
|
mod windows;
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||||
pub use self::linux::*;
|
pub use self::linux::*;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub use self::macos::*;
|
pub use self::macos::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user