From 719ce7d39e58b9311b51ac93d828fb26c2bcfbaf Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Mon, 13 May 2024 21:36:25 -0700 Subject: [PATCH] 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. --- ChangeLog | 10 ++++++++++ pygnulib/GLError.py | 3 +++ pygnulib/GLTestDir.py | 26 ++++++++++++++++---------- pygnulib/main.py | 2 ++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 327ea5273b..23fd42e6e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-05-13 Collin Funk + + 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 stdbit: redo clzll without lookcup table diff --git a/pygnulib/GLError.py b/pygnulib/GLError.py index 4288820c97..a6d7d8437d 100644 --- a/pygnulib/GLError.py +++ b/pygnulib/GLError.py @@ -55,6 +55,7 @@ class GLError(Exception): 19: could not create destination 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: 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 diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index d3b819bd0d..ad4549f734 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -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: diff --git a/pygnulib/main.py b/pygnulib/main.py index 585f7df43f..aeb78ad2c7 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -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) -- 2.39.5