Skip to content

Commit

Permalink
restore: Add caching for uid/gid names
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Nov 5, 2023
1 parent afcd22f commit c74d5ea
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/backend/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{

use aho_corasick::AhoCorasick;
use bytes::Bytes;
use cached::proc_macro::cached;

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Build docs (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (beta, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (beta, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (beta, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (beta, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (beta, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Test (stable, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-msvc

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-msvc

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-gnu

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-gnu

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (nightly, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (nightly, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (nightly, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (nightly, windows-latest)

unused import: `cached::proc_macro::cached`

Check warning on line 13 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Check Powerset of Features (nightly, windows-latest)

unused import: `cached::proc_macro::cached`
use filetime::{set_symlink_file_times, FileTime};
use log::{debug, trace, warn};
#[cfg(not(windows))]
Expand Down Expand Up @@ -469,6 +470,20 @@ pub struct LocalDestination {
is_file: bool,
}

// Helper functions to cache uid/gid
#[cfg(not(windows))]
#[cached]

fn uid_from_name(name: String) -> Option<Uid> {
User::from_name(&name).unwrap().map(|u| u.uid)
}

#[cfg(not(windows))]
#[cached]
fn gid_from_name(name: String) -> Option<Gid> {
Group::from_name(&name).unwrap().map(|g| g.gid)
}

impl LocalDestination {
/// Create a new [`LocalDestination`]
///
Expand Down Expand Up @@ -650,18 +665,18 @@ impl LocalDestination {

let user = meta
.user
.as_ref()
.and_then(|name| User::from_name(name).unwrap());

.clone()
.and_then(|name| uid_from_name(name.to_string()));

Check failure on line 669 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

redundant clone

error: redundant clone --> src/backend/local.rs:669:48 | 669 | .and_then(|name| uid_from_name(name.to_string())); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use --> src/backend/local.rs:669:44 | 669 | .and_then(|name| uid_from_name(name.to_string())); | ^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone = note: `-D clippy::redundant-clone` implied by `-D warnings`

Check failure on line 669 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

redundant clone

error: redundant clone --> src/backend/local.rs:669:48 | 669 | .and_then(|name| uid_from_name(name.to_string())); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use --> src/backend/local.rs:669:44 | 669 | .and_then(|name| uid_from_name(name.to_string())); | ^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone = note: `-D clippy::redundant-clone` implied by `-D warnings`
// use uid from user if valid, else from saved uid (if saved)
let uid = user.map(|u| u.uid).or_else(|| meta.uid.map(Uid::from_raw));
let uid = user.or_else(|| meta.uid.map(Uid::from_raw));

let group = meta
.group
.as_ref()
.and_then(|name| Group::from_name(name).unwrap());
.clone()
.and_then(|name| gid_from_name(name.to_string()));

Check failure on line 676 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

redundant clone

error: redundant clone --> src/backend/local.rs:676:48 | 676 | .and_then(|name| gid_from_name(name.to_string())); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use --> src/backend/local.rs:676:44 | 676 | .and_then(|name| gid_from_name(name.to_string())); | ^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

Check failure on line 676 in src/backend/local.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

redundant clone

error: redundant clone --> src/backend/local.rs:676:48 | 676 | .and_then(|name| gid_from_name(name.to_string())); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use --> src/backend/local.rs:676:44 | 676 | .and_then(|name| gid_from_name(name.to_string())); | ^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
// use gid from group if valid, else from saved gid (if saved)
let gid = group.map(|g| g.gid).or_else(|| meta.gid.map(Gid::from_raw));
let gid = group.or_else(|| meta.gid.map(Gid::from_raw));

fchownat(None, &filename, uid, gid, FchownatFlags::NoFollowSymlink)
.map_err(LocalErrorKind::FromErrnoError)?;
Ok(())
Expand Down

0 comments on commit c74d5ea

Please sign in to comment.