Refactoring FtpFileTransfer::parse_unix_list_line
@@ -36,9 +36,12 @@ use crate::utils::parser::{parse_datetime, parse_lstime};
use ftp4::native_tls::TlsConnector;
use ftp4::FtpStream;
use regex::Regex;
-use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::time::SystemTime;
+use std::{
+ io::{Read, Write},
+ ops::Range,
+};
/// ## FtpFileTransfer
///
@@ -105,45 +108,10 @@ impl FtpFileTransfer {
if metadata.get(2).unwrap().as_str().len() < 9 {
return Err(());
}
- // Get unix pex
- let unix_pex: (u8, u8, u8) = {
- let owner_pex: u8 = {
- let mut count: u8 = 0;
- for (i, c) in metadata.get(2).unwrap().as_str()[0..3].chars().enumerate() {
- match c {
- '-' => {}
- _ => {
- count += match i {
- 0 => 4,
- 1 => 2,
- 2 => 1,
- _ => 0,
- }
- }
- }
- }
- count
- };
- let group_pex: u8 = {
- let mut count: u8 = 0;
- for (i, c) in metadata.get(2).unwrap().as_str()[3..6].chars().enumerate() {
- match c {
- '-' => {}
- _ => {
- count += match i {
- 0 => 4,
- 1 => 2,
- 2 => 1,
- _ => 0,
- }
- }
- }
- }
- count
- };
- let others_pex: u8 = {
+
+ let pex = |range: Range<usize>| {
let mut count: u8 = 0;
- for (i, c) in metadata.get(2).unwrap().as_str()[6..9].chars().enumerate() {
+ for (i, c) in metadata.get(2).unwrap().as_str()[range].chars().enumerate() {
match c {
'-' => {}
_ => {
@@ -158,8 +126,10 @@ impl FtpFileTransfer {
}
count
};
- (owner_pex, group_pex, others_pex)
- };
+
+ // Get unix pex
+ let unix_pex = (pex(0..3), pex(3..6), pex(6..9));
+
// Parse mtime and convert to SystemTime
let mtime: SystemTime = match parse_lstime(
metadata.get(7).unwrap().as_str(),
