Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ mod tests {
use super::*;

fn file(name: &str, size: u64) -> EntryInfo {
let name = name.to_string();
let path = PathBuf::from(&name);
EntryInfo {
name: name.to_string(),
path: PathBuf::from(name),
lower_name: name.to_lowercase(),
name,
path,
kind: EntryKind::File,
size_bytes: Some(size),
modified: None,
Expand All @@ -125,9 +128,12 @@ mod tests {
}

fn dir(name: &str) -> EntryInfo {
let name = name.to_string();
let path = PathBuf::from(&name);
EntryInfo {
name: name.to_string(),
path: PathBuf::from(name),
lower_name: name.to_lowercase(),
name,
path,
kind: EntryKind::Directory,
size_bytes: None,
modified: None,
Expand Down
6 changes: 5 additions & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use crate::action::CollisionPolicy;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EntryInfo {
pub name: String,
/// Lower-case version of `name`, cached at construction to avoid repeated
/// `to_lowercase()` allocations during sorting and filtering.
pub lower_name: String,
pub path: PathBuf,
pub kind: EntryKind,
pub size_bytes: Option<u64>,
Expand Down Expand Up @@ -164,6 +167,7 @@ pub fn scan_directory(path: &Path) -> Result<Vec<EntryInfo>, FileSystemError> {
None
};
results.push(EntryInfo {
lower_name: name.to_lowercase(),
name,
path: entry_path,
kind,
Expand Down Expand Up @@ -192,7 +196,7 @@ pub fn scan_directory(path: &Path) -> Result<Vec<EntryInfo>, FileSystemError> {
results.sort_by(|left, right| {
left.kind
.cmp(&right.kind)
.then_with(|| left.name.to_lowercase().cmp(&right.name.to_lowercase()))
.then_with(|| left.lower_name.cmp(&right.lower_name))
});

Ok(results)
Expand Down
1 change: 1 addition & 0 deletions src/fs/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl FsBackend for LocalBackend {
None
};
Ok(EntryInfo {
lower_name: name.to_lowercase(),
name,
path: path.to_path_buf(),
kind,
Expand Down
7 changes: 5 additions & 2 deletions src/fs/scan_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ mod tests {
use std::time::{Duration, SystemTime};

fn entry(name: &str, kind: EntryKind, size: u64, mtime_offset_secs: u64) -> EntryInfo {
let name = name.to_string();
let path = PathBuf::from(&name);
EntryInfo {
name: name.to_string(),
path: PathBuf::from(name),
lower_name: name.to_lowercase(),
name,
path,
kind,
size_bytes: Some(size),
modified: Some(SystemTime::UNIX_EPOCH + Duration::from_secs(mtime_offset_secs)),
Expand Down
13 changes: 8 additions & 5 deletions src/fs/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ impl SftpBackend {
EntryKind::Other
};

let name = path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("")
.to_string();
EntryInfo {
name: path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("")
.to_string(),
lower_name: name.to_lowercase(),
name,
path: path.to_path_buf(),
kind,
size_bytes: Some(stat.size.unwrap_or(0)),
Expand Down Expand Up @@ -85,6 +87,7 @@ impl FsBackend for SftpBackend {
// Add parent directory entry ("..")
if let Some(parent) = remote_path.parent() {
result.push(EntryInfo {
lower_name: "..".to_string(),
name: "..".to_string(),
path: parent.to_path_buf(),
kind: EntryKind::Directory,
Expand Down
6 changes: 4 additions & 2 deletions src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ pub fn spawn_workers() -> (WorkerChannels, Receiver<JobResult>, Receiver<JobResu
None
};
entries.push(EntryInfo {
lower_name: first.to_lowercase(),
name: first.clone(),
path: archive_path.join(first),
kind,
Expand All @@ -913,7 +914,7 @@ pub fn spawn_workers() -> (WorkerChannels, Receiver<JobResult>, Receiver<JobResu
entries.sort_by(|l, r| {
l.kind
.cmp(&r.kind)
.then_with(|| l.name.to_lowercase().cmp(&r.name.to_lowercase()))
.then_with(|| l.lower_name.cmp(&r.lower_name))
});
let _ = result_tx.send(JobResult::ArchiveListed {
workspace_id: req.workspace_id,
Expand Down Expand Up @@ -1005,6 +1006,7 @@ pub fn spawn_workers() -> (WorkerChannels, Receiver<JobResult>, Receiver<JobResu
None
};
entries.push(EntryInfo {
lower_name: first.to_lowercase(),
name: first.clone(),
path: archive_path.join(first),
kind,
Expand All @@ -1019,7 +1021,7 @@ pub fn spawn_workers() -> (WorkerChannels, Receiver<JobResult>, Receiver<JobResu
entries.sort_by(|l, r| {
l.kind
.cmp(&r.kind)
.then_with(|| l.name.to_lowercase().cmp(&r.name.to_lowercase()))
.then_with(|| l.lower_name.cmp(&r.lower_name))
});
let _ = result_tx.send(JobResult::ArchiveListed {
workspace_id: req.workspace_id,
Expand Down
Loading
Loading