summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-12-31 08:29:17 +0000
committerJim Meyering <jim@meyering.net>2000-12-31 08:29:17 +0000
commit769b95b7514a2e4bde8556495f1de793df0cc4bc (patch)
tree14c27b679842c0ccfc2a500232d77c7d61bf2243 /src
parentde0ebc7eb6c7e3b3de13ff9b85ee5ca1e184b08c (diff)
downloadcoreutils-769b95b7514a2e4bde8556495f1de793df0cc4bc.tar.xz
Avoid an unnecessary `stat' when using --dereference.
(same_file_ok): Use stat only if lstat reported that the file was a symbolic link.
Diffstat (limited to 'src')
-rw-r--r--src/copy.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/copy.c b/src/copy.c
index a875892ed..f1d527cb1 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -512,9 +512,17 @@ same_file_ok (const char *src_path, const struct stat *src_sb,
if (x->xstat == lstat)
{
- if (stat (dst_path, &tmp_dst_sb)
- || stat (src_path, &tmp_src_sb)
- || ! SAME_INODE (tmp_src_sb, tmp_dst_sb))
+ if ( ! S_ISLNK (src_sb_link->st_mode))
+ tmp_src_sb = *src_sb_link;
+ else if (stat (src_path, &tmp_src_sb))
+ return 1;
+
+ if ( ! S_ISLNK (dst_sb_link->st_mode))
+ tmp_dst_sb = *dst_sb_link;
+ else if (stat (dst_path, &tmp_dst_sb))
+ return 1;
+
+ if ( ! SAME_INODE (tmp_src_sb, tmp_dst_sb))
return 1;
/* FIXME: shouldn't this be testing whether we're making symlinks? */