File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 17
17
splitext_addext )
18
18
from .openers import ImageOpener
19
19
20
+ # OS-specific path
21
+ _GIT_ANNEX_OBJECTS_PATH = os .path .join ('.git' , 'annex' , 'objects' )
22
+
23
+
24
+ def _is_annex_symlink (path ):
25
+ """Return True if file is a symlink to the git-annex objects"""
26
+ return os .path .islink (path ) and _GIT_ANNEX_OBJECTS_PATH in os .path .realpath (path )
27
+
20
28
21
29
class ImageFileError (Exception ):
22
30
pass
@@ -349,10 +357,11 @@ def to_filename(self, filename):
349
357
None
350
358
'''
351
359
self .file_map = file_map = self .filespec_to_file_map (filename )
360
+ remove_env = os .environ .get ('NIBABEL_REMOVE_BEFORE_TO_FILENAME' , None )
352
361
for _ , fh in file_map .items ():
353
362
if not isinstance (fh , FileHolder ):
354
363
continue
355
- if os .path .exists (fh .filename ):
364
+ if os .path .lexists (fh .filename ) and ( remove_env or _is_annex_symlink ( fh . filename ) ):
356
365
# Remove previous file where new file would be saved
357
366
# Necessary e.g. for cases where file is a symlink pointing
358
367
# to some non-writable file (e.g. under git annex control)
You can’t perform that action at this time.
0 commit comments