From 284a916f1ae1244a7ed38b49c39b2b4b90ea9878 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Tue, 29 Oct 2019 01:08:30 +0000
Subject: [PATCH] MNT: emit warning when dupe image files detected

---
 fsl/data/image.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/fsl/data/image.py b/fsl/data/image.py
index 2e7573389..188167b9a 100644
--- a/fsl/data/image.py
+++ b/fsl/data/image.py
@@ -1443,12 +1443,21 @@ def addExt(prefix, mustExist=True, unambiguous=True):
     """Adds a file extension to the given file ``prefix``.  See
     :func:`~fsl.utils.path.addExt`.
     """
-    return fslpath.addExt(prefix,
-                          allowedExts=ALLOWED_EXTENSIONS,
-                          mustExist=mustExist,
-                          defaultExt=defaultExt(),
-                          fileGroups=FILE_GROUPS,
-                          unambiguous=unambiguous)
+    try:
+        return fslpath.addExt(prefix,
+                              allowedExts=ALLOWED_EXTENSIONS,
+                              mustExist=mustExist,
+                              defaultExt=defaultExt(),
+                              fileGroups=FILE_GROUPS,
+                              unambiguous=unambiguous)
+    except fslpath.PathError as e:
+        # hacky: if more than one file with
+        # the prefix exists, we emit a
+        # warning, because in most cases
+        # this is a bad thing.
+        if str(e).startswith('More than'):
+            log.warning(e)
+        raise e
 
 
 def splitExt(filename):
-- 
GitLab