diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-02-19 00:44:08 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-02-19 00:44:08 +0000 |
commit | e0cbe4863704c78ea703c06c0dd2d76ebac90f75 (patch) | |
tree | bbdb6a67c5ef096f90bdf6fc91821f94d0f3e50a /libbb/copy_file.c | |
parent | 03a0643fbc5ae3e1ab2e7e29bb64617a4b94a5c9 (diff) | |
download | busybox-w32-e0cbe4863704c78ea703c06c0dd2d76ebac90f75.tar.gz busybox-w32-e0cbe4863704c78ea703c06c0dd2d76ebac90f75.tar.bz2 busybox-w32-e0cbe4863704c78ea703c06c0dd2d76ebac90f75.zip |
Chris Larson (kergoth) writes:
I was adding -s/--symbolic-link support to busybox cp when I noticed a
bug with -r/-a. Test case:
mkdir -p test/out
cd test
busybox cp -a * out/
Will never return until we run out of open files or similar.
Coreutils cp on the other hand will error with "cannot copy a directory,
`out', into itself, `out'". Patch attached.
Diffstat (limited to 'libbb/copy_file.c')
-rw-r--r-- | libbb/copy_file.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 7ddb9a23f..637b8179b 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -65,12 +65,28 @@ int copy_file(const char *source, const char *dest, int flags) | |||
65 | DIR *dp; | 65 | DIR *dp; |
66 | struct dirent *d; | 66 | struct dirent *d; |
67 | mode_t saved_umask = 0; | 67 | mode_t saved_umask = 0; |
68 | char *dstparent; | ||
69 | struct stat dstparent_stat; | ||
68 | 70 | ||
69 | if (!(flags & FILEUTILS_RECUR)) { | 71 | if (!(flags & FILEUTILS_RECUR)) { |
70 | bb_error_msg("%s: omitting directory", source); | 72 | bb_error_msg("%s: omitting directory", source); |
71 | return -1; | 73 | return -1; |
72 | } | 74 | } |
73 | 75 | ||
76 | dstparent = dirname(bb_xstrdup(dest)); | ||
77 | if (lstat(dstparent, &dstparent_stat) < 0) { | ||
78 | bb_perror_msg("unable to stat `%s'", dstparent); | ||
79 | free(dstparent); | ||
80 | return -1; | ||
81 | } | ||
82 | free(dstparent); | ||
83 | |||
84 | if (source_stat.st_dev == dstparent_stat.st_dev && | ||
85 | source_stat.st_ino == dstparent_stat.st_ino) { | ||
86 | bb_error_msg("cannot copy a directory, `%s', into itself, `%s'", source, dest); | ||
87 | return -1; | ||
88 | } | ||
89 | |||
74 | /* Create DEST. */ | 90 | /* Create DEST. */ |
75 | if (dest_exists) { | 91 | if (dest_exists) { |
76 | if (!S_ISDIR(dest_stat.st_mode)) { | 92 | if (!S_ISDIR(dest_stat.st_mode)) { |