Fix cp and mv so 'cp foo/README bar' where foo and bar are directories,
authorErik Andersen <andersen@codepoet.org>
Sat, 8 Jan 2000 21:16:29 +0000 (21:16 -0000)
committerErik Andersen <andersen@codepoet.org>
Sat, 8 Jan 2000 21:16:29 +0000 (21:16 -0000)
and README is a file.
 -Erik

Changelog
Makefile
coreutils/cp.c
coreutils/mv.c
cp.c
mv.c

index 5c06ec1b12dfcff71eb8fe5190664b9ee6736daa..52b34b663a103d60d7c50559e11108fb21befd4b 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,10 @@
+0.41
+       * Fixed a bug in both cp and mv preventing 'cp foo/README bar'
+           type commands (file in a directory to another directory) 
+           from working.
+
+       -Erik Andersen, 
+
 0.40
        * New Apps: sort, uniq. -beppu
        * New Apps: lsmod, rmmod -erik
index f1f25cd43c6d953f05495a413bcef20b22340135..9a59c1fff639fb94a2c2bed7aaa78e1071d2210b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ BUILDTIME=$(shell date "+%Y%m%d-%H%M")
 
 # Comment out the following to make a debuggable build
 # Leave this off for production use.
-DODEBUG=false
+DODEBUG=true
 # If you want a static binary, turn this on.  I can't think
 # of many situations where anybody would ever want it static, 
 # but...
index 4af73c274633ba574beac6cc7ac82195e3fe323a..e96012d500fea7916d4b84ae2ad6545ef521a26d 100644 (file)
@@ -48,6 +48,7 @@ static int srcDirFlag = FALSE;
 static int fileAction(const char *fileName, struct stat* statbuf)
 {
     char newdestName[NAME_MAX];
+    char* newsrcName = NULL;
 
     strcpy(newdestName, destName);
     if ( srcDirFlag == TRUE ) {
@@ -62,7 +63,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
        if (newdestName[strlen(newdestName)-1] != '/' ) {
            strcat(newdestName, "/");
        }
-       strcat(newdestName, srcName);
+       newsrcName = strrchr(srcName, '/');
+       if (newsrcName && *newsrcName != '\0')
+           strcat(newdestName, newsrcName);
+       else
+           strcat(newdestName, srcName);
     }
     
     return (copyFile(fileName, newdestName, preserveFlag, followLinks));
index 92c40c9b7866bf8f8b1f2f9f9a0345e9b32783ae..467a360dea59121875842a39fbfbc88b07c868ab 100644 (file)
@@ -40,6 +40,7 @@ static int srcDirFlag = FALSE;
 static int fileAction(const char *fileName, struct stat* statbuf)
 {
     char newdestName[NAME_MAX];
+    char* newsrcName = NULL;
 
     strcpy(newdestName, destName);
     if ( srcDirFlag == TRUE ) {
@@ -50,7 +51,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
        if (newdestName[strlen(newdestName)-1] != '/' ) {
            strcat(newdestName, "/");
        }
-       strcat(newdestName, srcName);
+       newsrcName = strrchr(srcName, '/');
+       if (newsrcName && *newsrcName != '\0')
+           strcat(newdestName, newsrcName);
+       else
+           strcat(newdestName, srcName);
     }
     
     return (copyFile(fileName, newdestName, TRUE, TRUE));
diff --git a/cp.c b/cp.c
index 4af73c274633ba574beac6cc7ac82195e3fe323a..e96012d500fea7916d4b84ae2ad6545ef521a26d 100644 (file)
--- a/cp.c
+++ b/cp.c
@@ -48,6 +48,7 @@ static int srcDirFlag = FALSE;
 static int fileAction(const char *fileName, struct stat* statbuf)
 {
     char newdestName[NAME_MAX];
+    char* newsrcName = NULL;
 
     strcpy(newdestName, destName);
     if ( srcDirFlag == TRUE ) {
@@ -62,7 +63,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
        if (newdestName[strlen(newdestName)-1] != '/' ) {
            strcat(newdestName, "/");
        }
-       strcat(newdestName, srcName);
+       newsrcName = strrchr(srcName, '/');
+       if (newsrcName && *newsrcName != '\0')
+           strcat(newdestName, newsrcName);
+       else
+           strcat(newdestName, srcName);
     }
     
     return (copyFile(fileName, newdestName, preserveFlag, followLinks));
diff --git a/mv.c b/mv.c
index 92c40c9b7866bf8f8b1f2f9f9a0345e9b32783ae..467a360dea59121875842a39fbfbc88b07c868ab 100644 (file)
--- a/mv.c
+++ b/mv.c
@@ -40,6 +40,7 @@ static int srcDirFlag = FALSE;
 static int fileAction(const char *fileName, struct stat* statbuf)
 {
     char newdestName[NAME_MAX];
+    char* newsrcName = NULL;
 
     strcpy(newdestName, destName);
     if ( srcDirFlag == TRUE ) {
@@ -50,7 +51,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
        if (newdestName[strlen(newdestName)-1] != '/' ) {
            strcat(newdestName, "/");
        }
-       strcat(newdestName, srcName);
+       newsrcName = strrchr(srcName, '/');
+       if (newsrcName && *newsrcName != '\0')
+           strcat(newdestName, newsrcName);
+       else
+           strcat(newdestName, srcName);
     }
     
     return (copyFile(fileName, newdestName, TRUE, TRUE));