From 464e558aeacfca0c4547ad24b895fc29e5f4bf5e Mon Sep 17 00:00:00 2001 From: George Hartzell Date: Tue, 17 Oct 2017 11:26:05 -0700 Subject: filter_file, don't remove absent backup file (#5733) I'm tracking down a problem with the perl package that's been generating this error: ``` OSError: OSError: [Errno 2] No such file or directory: '/blah/blah/blah/lib/5.24.1/x86_64-linux/Config.pm~' ``` The real problem is upstream, but it's being masked by an exception raised in `filter_file`s finally block. In my case, `backup` is `False`. The backup is created around line 127, the `re.sub()` calls fails (working on that), the `except` block fires and moves the backup file back, then the finally block tries to remove the non-existent backup file. This change just avoids trying to remove the non-existent file. --- lib/spack/llnl/util/filesystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 1d7b9ff7a3..5ed4d9249a 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -136,7 +136,7 @@ def filter_file(regex, repl, *filenames, **kwargs): raise finally: - if not backup: + if not backup and os.path.exists(backup_filename): os.remove(backup_filename) -- cgit v1.2.3-60-g2f50