[PATCH 1/2] Make 'stg cp' 2nd form safe.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Signed-off-by: Yann Dirson <ydirson@xxxxxxxxxx>
---

 Documentation/stg-cp.txt |    9 +++++----
 stgit/git.py             |    9 +++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/Documentation/stg-cp.txt b/Documentation/stg-cp.txt
index f499309..723d811 100644
--- a/Documentation/stg-cp.txt
+++ b/Documentation/stg-cp.txt
@@ -35,10 +35,11 @@ file not known to Git will not be copied.
 CAVEATS
 -------
 
-The first form doesn't allow yet to overwrite an existing file
-(whether it could be recovered from Git or not), and the second form
-does not check before overwriting any file, possibly leading to loss
-of non-committed modifications.
+This command does not allow yet to overwrite an existing file (whether
+it could be recovered from Git or not).  Further more, when copying a
+directory, the second form does not allow to proceed if a directory by
+that name already exists inside the target, even when no file inside
+that directory would be overwritten.
 
 FUTURE OPTIONS
 --------------
diff --git a/stgit/git.py b/stgit/git.py
index 9129c92..f6d6b43 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -464,6 +464,15 @@ def copy(filespecs, target):
     if os.path.isdir(target):
         # target is a directory: copy each entry on the command line,
         # with the same name, into the target
+        target = target.rstrip('/')
+        
+        # first, check that none of the children of the target
+        # matching the command line aleady exist
+        for filespec in filespecs:
+            entry = target+ '/' + os.path.basename(filespec.rstrip('/'))
+            if os.path.exists(entry):
+                raise GitException, 'Target "%s" already exists' % entry
+        
         for filespec in filespecs:
             filespec = filespec.rstrip('/')
             basename = '/' + os.path.basename(filespec)

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]