mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
commit
29a2eca451
2 changed files with 40 additions and 11 deletions
14
src/ln/ln.rs
14
src/ln/ln.rs
|
@ -15,8 +15,8 @@ extern crate uucore;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{BufRead, BufReader, Result, stdin, Write};
|
use std::io::{BufRead, BufReader, Result, stdin, Write};
|
||||||
#[cfg(unix)] use std::os::unix::fs::symlink as symlink_file;
|
#[cfg(unix)] use std::os::unix::fs::symlink;
|
||||||
#[cfg(windows)] use std::os::windows::fs::symlink_file;
|
#[cfg(windows)] use std::os::windows::fs::{symlink_file,symlink_dir};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
static NAME: &'static str = "ln";
|
static NAME: &'static str = "ln";
|
||||||
|
@ -292,8 +292,16 @@ fn existing_backup_path(path: &PathBuf, suffix: &str) -> PathBuf {
|
||||||
simple_backup_path(path, suffix)
|
simple_backup_path(path, suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
pub fn symlink<P: AsRef<Path>>(src: P, dst: P) -> Result<()> {
|
pub fn symlink<P: AsRef<Path>>(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<P: AsRef<Path>>(path: P) -> bool {
|
pub fn is_symlink<P: AsRef<Path>>(path: P) -> bool {
|
||||||
|
|
35
src/ls/ls.rs
35
src/ls/ls.rs
|
@ -147,7 +147,7 @@ fn list(options: getopts::Matches) {
|
||||||
|
|
||||||
if p.is_dir() && !options.opt_present("d") {
|
if p.is_dir() && !options.opt_present("d") {
|
||||||
dir = true;
|
dir = true;
|
||||||
if !options.opt_present("L") {
|
if options.opt_present("l") && !(options.opt_present("L")) {
|
||||||
if let Ok(md) = p.symlink_metadata() {
|
if let Ok(md) = p.symlink_metadata() {
|
||||||
if md.file_type().is_symlink() {
|
if md.file_type().is_symlink() {
|
||||||
dir = false;
|
dir = false;
|
||||||
|
@ -236,15 +236,21 @@ fn enter_directory(dir: &PathBuf, options: &getopts::Matches) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut entries: Vec<_> = entries.iter().map(DirEntry::path).collect();
|
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);
|
sort_entries(&mut entries, 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);
|
display_items(&entries, Some(dir), options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if options.opt_present("R") {
|
if options.opt_present("R") {
|
||||||
for e in entries.iter().filter(|p| p.is_dir()) {
|
for e in entries.iter().filter(|p| p.is_dir()) {
|
||||||
|
@ -451,6 +457,21 @@ fn display_file_name(path: &Path,
|
||||||
name.push('@');
|
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()
|
name.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue