From ca8f5516e9ec2fcb5b252c21353aca457e0c5473 Mon Sep 17 00:00:00 2001 From: Zephiris Date: Fri, 4 Nov 2016 20:27:02 -0700 Subject: [PATCH 1/3] ln: Make sure we can symlink directories on Windows. --- src/ln/ln.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ln/ln.rs b/src/ln/ln.rs index 03c8170aa..ad1a89b11 100644 --- a/src/ln/ln.rs +++ b/src/ln/ln.rs @@ -15,8 +15,8 @@ extern crate uucore; use std::fs; use std::io::{BufRead, BufReader, Result, stdin, Write}; -#[cfg(unix)] use std::os::unix::fs::symlink as symlink_file; -#[cfg(windows)] use std::os::windows::fs::symlink_file; +#[cfg(unix)] use std::os::unix::fs::symlink; +#[cfg(windows)] use std::os::windows::fs::{symlink_file,symlink_dir}; use std::path::{Path, PathBuf}; static NAME: &'static str = "ln"; @@ -292,8 +292,16 @@ fn existing_backup_path(path: &PathBuf, suffix: &str) -> PathBuf { simple_backup_path(path, suffix) } +#[cfg(windows)] pub fn symlink>(src: P, dst: P) -> Result<()> { - symlink_file(src, dst) + if src.as_ref().is_dir() + { + symlink_dir(src,dst) + } + else + { + symlink_file(src,dst) + } } pub fn is_symlink>(path: P) -> bool { From 606c1badd26077a4d7b4a52c8d3df2840e743647 Mon Sep 17 00:00:00 2001 From: Zephiris Date: Fri, 4 Nov 2016 21:03:54 -0700 Subject: [PATCH 2/3] ls: Change symlink behavior to be more POSIX compliant. Symlink directories are read by default, and symlink targets are listed on Windows. --- src/ls/ls.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ls/ls.rs b/src/ls/ls.rs index f73cf4326..dcf52ae81 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -147,7 +147,7 @@ fn list(options: getopts::Matches) { if p.is_dir() && !options.opt_present("d") { dir = true; - if !options.opt_present("L") { + if options.opt_present("l") && !(options.opt_present("L")) { if let Ok(md) = p.symlink_metadata() { if md.file_type().is_symlink() { dir = false; @@ -451,6 +451,21 @@ fn display_file_name(path: &Path, name.push('@'); } } + + if options.opt_present("long") && metadata.file_type().is_symlink() { + if let Ok(target) = path.read_link() { + // We don't bother updating width here because it's not used for long listings + let code = if target.exists() { + "fi" + } else { + "mi" + }; + let target_name = target.to_string_lossy().to_string(); + name.push_str(" -> "); + name.push_str(&target_name); + } + } + name.into() } From 0d0087053f615505221721773ea72ad6c16e25b2 Mon Sep 17 00:00:00 2001 From: Zephiris Date: Sat, 5 Nov 2016 01:29:55 -0700 Subject: [PATCH 3/3] ls: Fix '-aR' recursion. ls with -aR was recursing infinitely becacuse it added ./.. to every node. I don't see a way to avoid this except by cloning when that option is used. --- src/ls/ls.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ls/ls.rs b/src/ls/ls.rs index dcf52ae81..e6716a03b 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -236,15 +236,21 @@ fn enter_directory(dir: &PathBuf, options: &getopts::Matches) { } let mut entries: Vec<_> = entries.iter().map(DirEntry::path).collect(); - - if options.opt_present("a") { - entries.push(dir.join(".")); - entries.push(dir.join("..")); - } - sort_entries(&mut entries, options); - display_items(&entries, Some(dir), options); + + + if options.opt_present("a") { + let mut display_entries = entries.clone(); + display_entries.insert(0, dir.join("..")); + display_entries.insert(0, dir.join(".")); + display_items(&display_entries, Some(dir), options); + } + else + { + display_items(&entries, Some(dir), options); + } + if options.opt_present("R") { for e in entries.iter().filter(|p| p.is_dir()) {