Don't have a duplicate slash in root dir.
This commit is contained in:
parent
69f815e653
commit
8379405bb6
5 changed files with 29 additions and 11 deletions
|
@ -25,7 +25,8 @@ impl TrashDir {
|
|||
///
|
||||
/// > For every user2 a “home trash” directory MUST be available.
|
||||
/// > Its name and location are $XDG_DATA_HOME/Trash
|
||||
/// > $XDG_DATA_HOME is the base directory for user-specific data, as defined in the Desktop Base Directory Specification.
|
||||
/// > $XDG_DATA_HOME is the base directory for user-specific data, as
|
||||
/// defined in the Desktop Base Directory Specification.
|
||||
pub fn get_home_trash() -> Self {
|
||||
TrashDir::from(XDG.get_data_home().join("Trash"))
|
||||
}
|
||||
|
@ -38,7 +39,8 @@ impl TrashDir {
|
|||
.unwrap_or_else(|| TrashDir::get_home_trash())
|
||||
}
|
||||
|
||||
/// Actually create the directory on disk corresponding to this trash directory
|
||||
/// Actually create the directory on disk corresponding to this trash
|
||||
/// directory
|
||||
pub fn create(&self) -> Result<(), Error> {
|
||||
let path = &self.0;
|
||||
if !path.exists() {
|
||||
|
|
|
@ -41,7 +41,8 @@ pub struct TrashInfo {
|
|||
}
|
||||
|
||||
impl TrashInfo {
|
||||
/// Create a new TrashInfo based on the .trashinfo path and the deleted file path
|
||||
/// Create a new TrashInfo based on the .trashinfo path and the deleted file
|
||||
/// path
|
||||
///
|
||||
/// This is useful for reading files from the Trash.
|
||||
pub fn from_files(
|
||||
|
|
|
@ -21,8 +21,9 @@ enum Command {
|
|||
/// Puts files into the trash.
|
||||
///
|
||||
/// If a trash directory isn't specified, the best strategy is picked
|
||||
/// for each file that's deleted (after shell glob expansion). The algorithm
|
||||
/// for deciding a strategy is specified in the FreeDesktop Trash spec.
|
||||
/// for each file that's deleted (after shell glob expansion). The
|
||||
/// algorithm for deciding a strategy is specified in the FreeDesktop
|
||||
/// Trash spec.
|
||||
#[structopt(name = "put")]
|
||||
Put(PutOptions),
|
||||
|
||||
|
|
|
@ -98,7 +98,8 @@ enum DeletionStrategy {
|
|||
Fixed(TrashDir),
|
||||
|
||||
/// move the candidate files/directories to the trash directory
|
||||
/// (this requires that both the candidate and the trash directories be on the same filesystem)
|
||||
/// (this requires that both the candidate and the trash directories be on
|
||||
/// the same filesystem)
|
||||
MoveTo(TrashDir),
|
||||
|
||||
/// recursively copy the candidate files/directories to the trash directory
|
||||
|
|
23
src/utils.rs
23
src/utils.rs
|
@ -2,7 +2,7 @@ use std::env;
|
|||
use std::ffi::{OsStr, OsString};
|
||||
use std::fs;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
|
||||
use std::path::{Component, Path, PathBuf, MAIN_SEPARATOR};
|
||||
|
||||
use anyhow::Result;
|
||||
use percent_encoding::AsciiSet;
|
||||
|
@ -61,10 +61,23 @@ pub fn recursive_copy(
|
|||
/// Percent-encodes a path, but only the file names, not the separators.
|
||||
pub fn percent_encode(path: impl AsRef<Path>) -> String {
|
||||
let path = path.as_ref();
|
||||
path.iter()
|
||||
.map(|segment| {
|
||||
percent_encoding::percent_encode(segment.as_bytes(), MASK)
|
||||
.to_string()
|
||||
path.components()
|
||||
.filter_map(|segment| {
|
||||
match segment {
|
||||
Component::RootDir => Some(String::new()),
|
||||
Component::Prefix(_) => unreachable!("windows"),
|
||||
|
||||
// TODO: separate type for normalized path
|
||||
Component::ParentDir => {
|
||||
unreachable!("path should be normalized")
|
||||
}
|
||||
Component::CurDir => unreachable!("path should be normalized"),
|
||||
|
||||
Component::Normal(s) => Some(
|
||||
percent_encoding::percent_encode(s.as_bytes(), MASK)
|
||||
.to_string(),
|
||||
),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(&MAIN_SEPARATOR.to_string())
|
||||
|
|
Loading…
Reference in a new issue