Skip to content

Commit 6b99298

Browse files
committed
fix: parse special permissions StT in ls output
1 parent a034e23 commit 6b99298

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
- [Changelog](#changelog)
4+
- [0.3.1](#031)
45
- [0.3.0](#030)
56
- [0.2.1](#021)
67
- [0.2.0](#020)
@@ -13,6 +14,12 @@
1314

1415
---
1516

17+
## 0.3.1
18+
19+
Released on 09/07/2024
20+
21+
- Fix: parse special permissions `StT` in ls output
22+
1623
## 0.3.0
1724

1825
Released on 09/07/2024

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ license = "MIT"
1111
name = "remotefs-ssh"
1212
readme = "README.md"
1313
repository = "https://github.com/veeso/remotefs-rs-ssh"
14-
version = "0.3.0"
14+
version = "0.3.1"
1515

1616
[dependencies]
1717
chrono = "^0.4"
18-
lazy_static = "^1.4"
18+
lazy-regex = "3"
1919
log = "^0.4"
20-
regex = "^1.7"
2120
remotefs = "^0.2"
2221
ssh2-config = "^0.2"
2322
ssh2 = "^0.9"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<p align="center">~ Remotefs SSH client ~</p>
1212

1313
<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
14-
<p align="center">Current version: 0.3.0 (09/07/2024)</p>
14+
<p align="center">Current version: 0.3.1 (09/07/2024)</p>
1515

1616
<p align="center">
1717
<a href="https://opensource.org/licenses/MIT"

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
// -- crates
5555
#[macro_use]
56-
extern crate lazy_static;
56+
extern crate lazy_regex;
5757
#[macro_use]
5858
extern crate log;
5959

src/ssh/scp.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ops::Range;
77
use std::path::{Path, PathBuf};
88
use std::time::{Duration, SystemTime};
99

10-
use regex::Regex;
10+
use lazy_regex::{Lazy, Regex};
1111
use remotefs::fs::{
1212
FileType, Metadata, ReadStream, RemoteError, RemoteErrorType, RemoteFs, RemoteResult, UnixPex,
1313
UnixPexClass, Welcome, WriteStream,
@@ -19,6 +19,11 @@ pub use ssh2::Session as SshSession;
1919
use super::{commons, SshOpts};
2020
use crate::utils::{fmt as fmt_utils, parser as parser_utils, path as path_utils};
2121

22+
/// NOTE: about this damn regex <https://stackoverflow.com/questions/32480890/is-there-a-regex-to-parse-the-values-from-an-ftp-directory-listing>
23+
static LS_RE: Lazy<Regex> = lazy_regex!(
24+
r#"^([\-ld])([\-rwxsStT]{9})\s+(\d+)\s+(.+)\s+(.+)\s+(\d+)\s+(\w{3}\s+\d{1,2}\s+(?:\d{1,2}:\d{1,2}|\d{4}))\s+(.+)$"#
25+
);
26+
2227
/// SCP "filesystem" client
2328
pub struct ScpFs {
2429
session: Option<SshSession>,
@@ -52,15 +57,9 @@ impl ScpFs {
5257
}
5358
}
5459

55-
/// ### parse_ls_output
56-
///
5760
/// Parse a line of `ls -l` output and tokenize the output into a `FsFile`
5861
fn parse_ls_output(&self, path: &Path, line: &str) -> Result<File, ()> {
5962
// Prepare list regex
60-
// NOTE: about this damn regex <https://stackoverflow.com/questions/32480890/is-there-a-regex-to-parse-the-values-from-an-ftp-directory-listing>
61-
lazy_static! {
62-
static ref LS_RE: Regex = Regex::new(r#"^([\-ld])([\-rwxs]{9})\s+(\d+)\s+(.+)\s+(.+)\s+(\d+)\s+(\w{3}\s+\d{1,2}\s+(?:\d{1,2}:\d{1,2}|\d{4}))\s+(.+)$"#).unwrap();
63-
}
6463
trace!("Parsing LS line: '{}'", line);
6564
// Apply regex to result
6665
match LS_RE.captures(line) {
@@ -1385,6 +1384,37 @@ mod test {
13851384
);
13861385
}
13871386

1387+
#[test]
1388+
fn test_should_parse_special_permissions_ls_output() {
1389+
let client = ScpFs::new(SshOpts::new("localhost"));
1390+
assert!(client
1391+
.parse_ls_output(
1392+
Path::new("/tmp"),
1393+
"-rw-rwSrw- 1 manufact manufact 241813 Apr 22 09:31 L9800.SPF",
1394+
)
1395+
.is_ok());
1396+
assert!(client
1397+
.parse_ls_output(
1398+
Path::new("/tmp"),
1399+
"-rw-rwsrw- 1 manufact manufact 241813 Apr 22 09:31 L9800.SPF",
1400+
)
1401+
.is_ok());
1402+
1403+
assert!(client
1404+
.parse_ls_output(
1405+
Path::new("/tmp"),
1406+
"-rw-rwtrw- 1 manufact manufact 241813 Apr 22 09:31 L9800.SPF",
1407+
)
1408+
.is_ok());
1409+
1410+
assert!(client
1411+
.parse_ls_output(
1412+
Path::new("/tmp"),
1413+
"-rw-rwTrw- 1 manufact manufact 241813 Apr 22 09:31 L9800.SPF",
1414+
)
1415+
.is_ok());
1416+
}
1417+
13881418
#[test]
13891419
fn should_return_errors_on_uninitialized_client() {
13901420
let mut client = ScpFs::new(SshOpts::new("localhost"));

0 commit comments

Comments
 (0)