Skip to content

Commit 329c80c

Browse files
authored
feat: support Unix path backend for the SFTP provider (#3371)
1 parent a1fb206 commit 329c80c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+410
-401
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yazi-fs/src/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl File {
6060
Url::Archive { loc: Loc::saturated(to.as_os().ok()?, kind), domain }
6161
}
6262
UrlBuf::Sftp { domain, .. } => {
63-
Url::Sftp { loc: Loc::saturated(to.as_os().ok()?, kind), domain }
63+
Url::Sftp { loc: Loc::saturated(to.as_unix().ok()?, kind), domain }
6464
}
6565
})
6666
}

yazi-fs/src/path/expand.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ fn expand_url_impl<'a>(url: Url<'a>) -> UrlCow<'a> {
3636
Url::Regular(_) => UrlBuf::Regular(loc),
3737
Url::Search { domain, .. } => UrlBuf::Search { loc, domain: domain.intern() },
3838
Url::Archive { domain, .. } => UrlBuf::Archive { loc, domain: domain.intern() },
39-
Url::Sftp { domain, .. } => UrlBuf::Sftp { loc, domain: domain.intern() },
39+
Url::Sftp { domain, .. } => {
40+
todo!();
41+
// UrlBuf::Sftp { loc, domain: domain.intern() }
42+
}
4043
};
4144

4245
absolute_url(expanded)

yazi-sftp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ parking_lot = { workspace = true }
1717
russh = { workspace = true }
1818
serde = { workspace = true }
1919
tokio = { workspace = true }
20+
typed-path = { workspace = true }

yazi-sftp/src/byte_str.rs

Lines changed: 0 additions & 114 deletions
This file was deleted.

yazi-sftp/src/fs/dir_entry.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,31 @@
1-
use std::{borrow::Cow, ffi::OsStr, path::PathBuf, sync::Arc};
1+
use std::sync::Arc;
22

3-
use crate::{ByteStr, fs::Attrs};
3+
use typed_path::UnixPathBuf;
4+
5+
use crate::fs::Attrs;
46

57
pub struct DirEntry {
6-
pub(super) dir: Arc<ByteStr<'static>>,
7-
pub(super) name: ByteStr<'static>,
8-
pub(super) long_name: ByteStr<'static>,
8+
pub(super) dir: Arc<typed_path::UnixPathBuf>,
9+
pub(super) name: Vec<u8>,
10+
pub(super) long_name: Vec<u8>,
911
pub(super) attrs: Attrs,
1012
}
1113

1214
impl DirEntry {
1315
#[must_use]
14-
pub fn path(&self) -> PathBuf { self.dir.join(&self.name) }
16+
pub fn path(&self) -> UnixPathBuf { self.dir.join(&self.name) }
1517

16-
#[must_use]
17-
pub fn name(&self) -> Cow<'_, OsStr> { self.name.to_os_str() }
18+
pub fn name(&self) -> &[u8] { &self.name }
1819

19-
#[must_use]
20-
pub fn long_name(&self) -> Cow<'_, OsStr> { self.long_name.to_os_str() }
20+
pub fn long_name(&self) -> &[u8] { &self.long_name }
2121

2222
pub fn attrs(&self) -> &Attrs { &self.attrs }
2323

2424
pub fn nlink(&self) -> Option<u64> { str::from_utf8(self.long_name_field(1)?).ok()?.parse().ok() }
2525

26-
pub fn user(&self) -> Option<Cow<'_, OsStr>> {
27-
let b = self.long_name_field(2)?;
28-
Some(unsafe {
29-
match ByteStr::from_str_bytes_unchecked(b).to_os_str() {
30-
Cow::Borrowed(_) => OsStr::from_encoded_bytes_unchecked(b).into(),
31-
Cow::Owned(s) => s.into(),
32-
}
33-
})
34-
}
26+
pub fn user(&self) -> Option<&[u8]> { self.long_name_field(2) }
3527

36-
pub fn group(&self) -> Option<Cow<'_, OsStr>> {
37-
let b = self.long_name_field(3)?;
38-
Some(unsafe {
39-
match ByteStr::from_str_bytes_unchecked(b).to_os_str() {
40-
Cow::Borrowed(_) => OsStr::from_encoded_bytes_unchecked(b).into(),
41-
Cow::Owned(s) => s.into(),
42-
}
43-
})
44-
}
28+
pub fn group(&self) -> Option<&[u8]> { self.long_name_field(3) }
4529

4630
fn long_name_field(&self, n: usize) -> Option<&[u8]> {
4731
self.long_name.split(|b| b.is_ascii_whitespace()).filter(|s| !s.is_empty()).nth(n)

yazi-sftp/src/fs/read_dir.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::{mem, sync::Arc};
22

3-
use crate::{ByteStr, Error, Session, fs::DirEntry, requests, responses};
3+
use crate::{Error, Session, SftpPath, fs::DirEntry, requests, responses};
44

55
pub struct ReadDir {
66
session: Arc<Session>,
7-
dir: Arc<ByteStr<'static>>,
7+
dir: Arc<typed_path::UnixPathBuf>,
88
handle: String,
99

1010
name: responses::Name<'static>,
@@ -13,7 +13,7 @@ pub struct ReadDir {
1313
}
1414

1515
impl ReadDir {
16-
pub(crate) fn new(session: &Arc<Session>, dir: ByteStr, handle: String) -> Self {
16+
pub(crate) fn new(session: &Arc<Session>, dir: SftpPath, handle: String) -> Self {
1717
Self {
1818
session: session.clone(),
1919
dir: Arc::new(dir.into_owned()),
@@ -33,11 +33,11 @@ impl ReadDir {
3333
};
3434

3535
self.cursor += 1;
36-
if item.name != "." && item.name != ".." {
36+
if &*item.name != b"." && &*item.name != b".." {
3737
return Ok(Some(DirEntry {
3838
dir: self.dir.clone(),
39-
name: item.name,
40-
long_name: item.long_name,
39+
name: item.name.into_owned(),
40+
long_name: item.long_name.into_owned(),
4141
attrs: item.attrs,
4242
}));
4343
}

yazi-sftp/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ pub mod fs;
44
pub mod requests;
55
pub mod responses;
66

7-
mod byte_str;
87
mod de;
98
mod error;
109
mod id;
1110
mod macros;
1211
mod operator;
1312
mod packet;
13+
mod path;
1414
mod ser;
1515
mod session;
16-
#[cfg(windows)]
17-
mod wtf;
1816

19-
pub use byte_str::*;
2017
pub(crate) use de::*;
2118
pub use error::*;
2219
pub(crate) use id::*;
2320
pub use operator::*;
2421
pub use packet::*;
22+
pub use path::*;
2523
pub(crate) use ser::*;
2624
pub use session::*;

0 commit comments

Comments
 (0)