[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug #17540] cp: cannot backup `./.': Device or resource busy
From: |
Jim Meyering |
Subject: |
Re: [bug #17540] cp: cannot backup `./.': Device or resource busy |
Date: |
Sun, 27 Aug 2006 21:48:46 +0200 |
Andreas Schwab <address@hidden> wrote:
> Summary: cp: cannot backup `./.': Device or resource busy
> Project: GNU Core Utilities
...
> $ cp --version | head -1
> cp (GNU coreutils) 6.2-cvs
> $ mkdir x y
> $ cd y
> $ cp -ab ../x/. .
> cp: cannot backup `./.': Device or resource busy
Thanks for reporting that.
I've fixed it like this:
2006-08-27 Jim Meyering <address@hidden>
* src/copy.c (copy_internal): Don't make a backup if the last
component of the source name is "." or "..".
Reported by Andreas Schwab in https://savannah.gnu.org/bugs/?17540.
* tests/cp/src-base-dot: New file. Test for the above fix.
* tests/cp/Makefile.am (TESTS): Add src-base-dot.
* src/system.h (DOT_OR_DOTDOT): Remove macro. Rewrite as a...
(dot_or_dotdot): ...new static inline function.
* src/remove.c (rm_1): Reflect this renaming.
* src/ls.c (basename_is_dot_or_dotdot): Likewise.
Index: src/system.h
===================================================================
RCS file: /fetish/cu/src/system.h,v
retrieving revision 1.155
diff -u -r1.155 system.h
--- src/system.h 25 Aug 2006 23:30:59 -0000 1.155
+++ src/system.h 27 Aug 2006 16:36:57 -0000
@@ -447,9 +447,14 @@
#include "unlocked-io.h"
#include "same-inode.h"
-#define DOT_OR_DOTDOT(Basename) \
- (Basename[0] == '.' && (Basename[1] == '\0' \
- || (Basename[1] == '.' && Basename[2] == '\0')))
+static inline bool
+dot_or_dotdot (char const *file_name)
+{
+ return (file_name[0] == '.'
+ && (file_name[1] == '\0'
+ || (file_name[1] == '.'
+ && file_name[2] == '\0')));
+}
/* A wrapper for readdir so that callers don't see entries for `.' or `..'. */
static inline struct dirent const *
@@ -458,7 +463,7 @@
while (1)
{
struct dirent const *dp = readdir (dirp);
- if (dp == NULL || ! DOT_OR_DOTDOT (dp->d_name))
+ if (dp == NULL || ! dot_or_dotdot (dp->d_name))
return dp;
}
}
Index: src/remove.c
===================================================================
RCS file: /fetish/cu/src/remove.c,v
retrieving revision 1.156
diff -u -r1.156 remove.c
--- src/remove.c 3 Jul 2006 17:38:20 -0000 1.156
+++ src/remove.c 27 Aug 2006 16:37:58 -0000
@@ -1372,7 +1372,7 @@
struct rm_options const *x, int *cwd_errno)
{
char const *base = last_component (filename);
- if (DOT_OR_DOTDOT (base))
+ if (dot_or_dotdot (base))
{
error (0, 0, _("cannot remove `.' or `..'"));
return RM_ERROR;
Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.439
diff -u -r1.439 ls.c
--- src/ls.c 26 Aug 2006 06:46:17 -0000 1.439
+++ src/ls.c 27 Aug 2006 16:38:41 -0000
@@ -2814,7 +2814,7 @@
basename_is_dot_or_dotdot (const char *name)
{
char const *base = last_component (name);
- return DOT_OR_DOTDOT (base);
+ return dot_or_dotdot (base);
}
/* Remove any entries from FILES that are for directories,
Index: src/copy.c
===================================================================
RCS file: /fetish/cu/src/copy.c,v
retrieving revision 1.208
diff -u -r1.208 copy.c
--- src/copy.c 27 Aug 2006 16:29:11 -0000 1.208
+++ src/copy.c 27 Aug 2006 16:44:02 -0000
@@ -1185,7 +1185,10 @@
}
}
- if (x->backup_type != no_backups)
+ if (x->backup_type != no_backups
+ /* Don't try to back up a destination if the last
+ component of src_name is "." or "..". */
+ && ! dot_or_dotdot (last_component (src_name)))
{
char *tmp_backup = find_backup_file_name (dst_name,
x->backup_type);
Index: tests/cp/src-base-dot
===================================================================
RCS file: tests/cp/src-base-dot
diff -N tests/cp/src-base-dot
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/cp/src-base-dot 27 Aug 2006 19:39:59 -0000
@@ -0,0 +1,54 @@
+#!/bin/sh
+# Ensure that "mkdir x y; cd y; cp -ab ../x/. ." is a successful, silent,
no-op.
+
+# Copyright (C) 2006 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ cp --version
+fi
+
+. $srcdir/../envvar-check
+
+pwd=`pwd`
+t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
+trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+framework_failure=0
+mkdir -p $tmp || framework_failure=1
+cd $tmp || framework_failure=1
+
+mkdir x y || framework_failure=1
+
+if test $framework_failure = 1; then
+ echo "$0: failure in testing framework" 1>&2
+ (exit 1); exit 1
+fi
+
+fail=0
+
+cd y
+cp --verbose -ab ../x/. . > out 2>&1 || fail=1
+cat <<\EOF > exp || fail=1
+EOF
+
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
+
+(exit $fail); exit $fail
Index: tests/cp/Makefile.am
===================================================================
RCS file: /fetish/cu/tests/cp/Makefile.am,v
retrieving revision 1.35
diff -u -r1.35 Makefile.am
--- tests/cp/Makefile.am 19 Aug 2006 14:01:30 -0000 1.35
+++ tests/cp/Makefile.am 27 Aug 2006 10:56:06 -0000
@@ -21,6 +21,7 @@
AUTOMAKE_OPTIONS = 1.1 gnits
TESTS = \
+ src-base-dot \
sparse \
link-no-deref \
cp-deref \