Skip to content

Commit

Permalink
Fixed compile warning and ran rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturKovacs committed Oct 21, 2020
1 parent cdde3a7 commit c556d28
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl error::Error for Error {}
/// Removes a single file or directory.
///
/// Warning: when a symbolic link is provided to this function the link target will be removed and
/// the link will become dangling. That is if 'sl' refers to 'my-text-file' and `remove("sl")` is
/// the link will become dangling. That is if 'sl' refers to 'my-text-file' and `remove("sl")` is
/// called then 'my-text-file' will be removed and 'sl' will be left dangling.
///
/// # Example
Expand All @@ -93,9 +93,9 @@ pub fn remove<T: AsRef<Path>>(path: T) -> Result<(), Error> {
/// Removes all files/directories specified by the collection of paths provided as an argument.
///
/// Warning: when a symbolic link is provided to this function the link target will be removed and
/// the link will become dangling. That is if 'sl' refers to 'my-text-file' and `remove("sl")` is
/// the link will become dangling. That is if 'sl' refers to 'my-text-file' and `remove("sl")` is
/// called then 'my-text-file' will be removed and 'sl' will be left dangling.
///
///
/// # Example
///
/// ```
Expand Down Expand Up @@ -123,7 +123,7 @@ where
/// Removes a single file or directory.
///
/// When a symbolic link is provided to this function, the sybolic link will be removed and the link
/// target will be kept intact.
/// target will be kept intact.
///
/// # Example
///
Expand All @@ -141,8 +141,8 @@ pub fn delete<T: AsRef<Path>>(path: T) -> Result<(), Error> {
/// Removes all files/directories specified by the collection of paths provided as an argument.
///
/// When a symbolic link is provided to this function, the sybolic link will be removed and the link
/// target will be kept intact.
///
/// target will be kept intact.
///
/// # Example
///
/// ```
Expand All @@ -163,9 +163,9 @@ where
let full_paths = paths
.map(|x| {
let target = x.as_ref();
let cannonical = target.canonicalize().map_err(|e| {
Error::CanonicalizePath { code: e.raw_os_error() }
})?;
let cannonical = target
.canonicalize()
.map_err(|e| Error::CanonicalizePath { code: e.raw_os_error() })?;
let parent = cannonical.parent().ok_or(Error::TargetedRoot)?;
if let Some(file_name) = target.file_name() {
Ok(parent.join(file_name))
Expand Down
3 changes: 1 addition & 2 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub fn is_implemented() -> bool {

/// This is based on the electron library's implementation.
/// See: https://github.com/electron/electron/blob/34c4c8d5088fa183f56baea28809de6f2a427e02/shell/common/platform_util_linux.cc#L96
pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error>
{
pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error> {
let trash = {
// Determine desktop environment and set accordingly.
let desktop_env = get_desktop_environment();
Expand Down
10 changes: 5 additions & 5 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pub fn is_implemented() -> bool {
true
}

pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error>
{
let full_paths = full_paths.into_iter().map(|p| {
p.to_str().ok_or(Error::Unknown).map(|s| s.to_owned())
}).collect::<Result<Vec<_>, _>>()?;
pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error> {
let full_paths = full_paths
.into_iter()
.map(|p| p.to_str().ok_or(Error::Unknown).map(|s| s.to_owned()))
.collect::<Result<Vec<_>, _>>()?;
// AppleScript command to move files (or directories) to Trash looks like
// osascript -e 'tell application "Finder" to delete { POSIX file "file1", POSIX "file2" }'
// The `-e` flag is used to execute only one line of AppleScript.
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[allow(deprecated)]
use crate::{remove, remove_all, delete, delete_all};
use crate::{delete, delete_all, remove, remove_all};
use std::fs::{create_dir, File};
use std::path::{Path, PathBuf};
use std::path::PathBuf;

#[test]
#[allow(deprecated)]
Expand Down
3 changes: 1 addition & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pub fn is_implemented() -> bool {
true
}

pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error>
{
pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error> {
let mut wide_paths = Vec::with_capacity(full_paths.len());
for path in full_paths.iter() {
let mut os_string = OsString::from(path);
Expand Down

0 comments on commit c556d28

Please sign in to comment.