]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Don't continue creating testdirs when destdir exists.
authorCollin Funk <collin.funk1@gmail.com>
Tue, 14 May 2024 04:36:25 +0000 (21:36 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Tue, 14 May 2024 04:36:25 +0000 (21:36 -0700)
* pygnulib/GLError.py (GLError.__init__, GLError.__repr__): Add a new
error number for destination directories that already exist.
* pygnulib/main.py (main_with_exception_handling): Print the message.
* pygnulib/GLTestDir.py (GLTestDir.__init__, GLMegaTestdir.__init__):
Fail if the destination directory exists instead of creating files and
failing to patch test driver.

ChangeLog
pygnulib/GLError.py
pygnulib/GLTestDir.py
pygnulib/main.py

index 327ea5273bc6f18c6fa83d0935b559ddbb08dba5..23fd42e6e08ec8cb30d103c548325e793b91b7a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-05-13  Collin Funk  <collin.funk1@gmail.com>
+
+       gnulib-tool.py: Don't continue creating testdirs when destdir exists.
+       * pygnulib/GLError.py (GLError.__init__, GLError.__repr__): Add a new
+       error number for destination directories that already exist.
+       * pygnulib/main.py (main_with_exception_handling): Print the message.
+       * pygnulib/GLTestDir.py (GLTestDir.__init__, GLMegaTestdir.__init__):
+       Fail if the destination directory exists instead of creating files and
+       failing to patch test driver.
+
 2024-05-13  Paul Eggert  <eggert@cs.ucla.edu>
 
        stdbit: redo clzll without lookcup table
index 4288820c976c221a6448421587876ef582a0f09c..a6d7d8437dca28e6463f36f42479384590ea4333 100644 (file)
@@ -55,6 +55,7 @@ class GLError(Exception):
          19: could not create destination directory: <directory>
          20: could not patch test-driver script
          21: Option --automake-subdir is only supported if the definition of AUTOMAKE_OPTIONS in Makefile.am contains 'subdir-objects'.
+         22: not overwriting destination directory: <directory>
         errinfo: additional information'''
         self.errno = errno
         self.errinfo = errinfo
@@ -107,5 +108,7 @@ class GLError(Exception):
                 message = ('Option --automake-subdir/--automake-subdir-tests are only '
                            'supported if the definition of AUTOMAKE_OPTIONS in '
                            'Makefile.am contains \'subdir-objects\'.')
+            elif errno == 22:
+                message = 'not overwriting destination directory: %s' % repr(errinfo)
             self.message = '[Errno %d] %s' % (errno, message)
         return self.message
index d3b819bd0db0e1493d16c8e4a11d3f4be02e5c0c..ad4549f734800fcbf08551a9ad0e287cd2a8ea40 100644 (file)
@@ -107,11 +107,14 @@ class GLTestDir:
                             % type(testdir).__name__)
         self.config = config
         self.testdir = os.path.normpath(testdir)
-        if not os.path.exists(self.testdir):
-            try:  # Try to create directory
-                os.mkdir(self.testdir)
-            except Exception as exc:
-                raise GLError(19, self.testdir) from exc
+        # Don't overwrite the directory.
+        if os.path.exists(self.testdir):
+            raise GLError(22, self.testdir)
+        # Try to create directory.
+        try:
+            os.mkdir(self.testdir)
+        except Exception as exc:
+            raise GLError(19, self.testdir) from exc
         self.emitter = GLEmiter(self.config)
         self.filesystem = GLFileSystem(self.config)
         self.modulesystem = GLModuleSystem(self.config)
@@ -863,11 +866,14 @@ class GLMegaTestDir:
                             % type(megatestdir).__name__)
         self.config = config
         self.megatestdir = os.path.normpath(megatestdir)
-        if not os.path.exists(self.megatestdir):
-            try:  # Try to create directory
-                os.mkdir(self.megatestdir)
-            except Exception as exc:
-                raise GLError(19, self.megatestdir) from exc
+        # Don't overwrite the directory.
+        if os.path.exists(self.megatestdir):
+            raise GLError(22, self.megatestdir)
+        # Try to create directory.
+        try:
+            os.mkdir(self.megatestdir)
+        except Exception as exc:
+            raise GLError(19, self.megatestdir) from exc
         self.modulesystem = GLModuleSystem(self.config)
 
     def execute(self) -> None:
index 585f7df43f38aa7f3cdd12f7d92369cc4fe93564..aeb78ad2c74566c71ff639a0f896f4707c0cb726 100644 (file)
@@ -1438,6 +1438,8 @@ def main_with_exception_handling() -> None:
                 message += ('Option --automake-subdir/--automake-subdir-tests are only '
                             'supported if the definition of AUTOMAKE_OPTIONS in '
                             'Makefile.am contains \'subdir-objects\'.')
+            elif errno == 22:
+                message = 'not overwriting destination directory: %s' % errinfo
             message += '\n%s: *** Stop.\n' % APP['name']
             sys.stderr.write(message)
             sys.exit(1)