bug 483800 - fix nsinstall.py to not error if a target dir already exists. r=pike
authorTed Mielczarek <ted.mielczarek@gmail.com>
Tue, 17 Mar 2009 12:09:50 -0400
changeset 26253 0659666e3aa4fa0cfd9ea55b935ad9db9f68bd8f
parent 26252 01987cfc569b7a2eb76e3dc1089bf5483012353c
child 26254 3f28dada65ff3ffe087c277a001c762ed43a46d0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspike
bugs483800
milestone1.9.2a1pre
bug 483800 - fix nsinstall.py to not error if a target dir already exists. r=pike
config/nsinstall.py
config/tests/unit-nsinstall.py
js/src/config/nsinstall.py
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -125,17 +125,18 @@ def nsinstall(argv):
     # we're supposed to create directories
     def handleTarget(srcpath, targetpath):
       # target directory was already created, just use mkdir
       os.mkdir(targetpath)
   else:
     # we're supposed to copy files
     def handleTarget(srcpath, targetpath):
       if os.path.isdir(srcpath):
-        os.mkdir(targetpath)
+        if not os.path.exists(targetpath):
+          os.mkdir(targetpath)
         entries = [os.path.join(srcpath, e) for e in os.listdir(srcpath)]
         copy_all_entries(entries, targetpath)
         # options.t is not relevant for directories
         if options.m:
           os.chmod(targetpath, options.m)
       elif options.t:
         shutil.copy2(srcpath, targetpath)
       else:
--- a/config/tests/unit-nsinstall.py
+++ b/config/tests/unit-nsinstall.py
@@ -59,16 +59,23 @@ class TestNsinstall(unittest.TestCase):
                      self.touch("testfile2"),
                      self.touch("testfile3")]
         testdir = self.mkdirs("testdir")
         self.assertEqual(nsinstall(testfiles + [testdir]), 0)
         for f in testfiles:
             self.assert_(os.path.isfile(os.path.join(testdir,
                                                      os.path.basename(f))))
 
+    def test_nsinstall_dir_exists(self):
+        "Test nsinstall <dir> <dest dir>, where <dest dir>/<dir> already exists"
+        srcdir = self.mkdirs("test")
+        destdir = self.mkdirs("testdir/test")
+        self.assertEqual(nsinstall([srcdir, os.path.dirname(destdir)]), 0)
+        self.assert_(os.path.isdir(destdir))
+
     def test_nsinstall_t(self):
         "Test that nsinstall -t works (preserve timestamp)"
         testfile = self.touch("testfile")
         testdir = self.mkdirs("testdir")
         # set mtime to now - 30 seconds
         t = int(time.time()) - 30
         os.utime(testfile, (t, t))
         self.assertEqual(nsinstall(["-t", testfile, testdir]), 0)
--- a/js/src/config/nsinstall.py
+++ b/js/src/config/nsinstall.py
@@ -125,17 +125,18 @@ def nsinstall(argv):
     # we're supposed to create directories
     def handleTarget(srcpath, targetpath):
       # target directory was already created, just use mkdir
       os.mkdir(targetpath)
   else:
     # we're supposed to copy files
     def handleTarget(srcpath, targetpath):
       if os.path.isdir(srcpath):
-        os.mkdir(targetpath)
+        if not os.path.exists(targetpath):
+          os.mkdir(targetpath)
         entries = [os.path.join(srcpath, e) for e in os.listdir(srcpath)]
         copy_all_entries(entries, targetpath)
         # options.t is not relevant for directories
         if options.m:
           os.chmod(targetpath, options.m)
       elif options.t:
         shutil.copy2(srcpath, targetpath)
       else: