Skip to content

Commit

Permalink
RF/ENH: remove file prior writing in to_filename
Browse files Browse the repository at this point in the history
Closes #465
  • Loading branch information
yarikoptic committed Jul 29, 2016
1 parent 82a261c commit 99af2f4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion nibabel/filebasedimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
''' Common interface for any image format--volume or surface, binary or xml.'''

import os
import warnings

from .externals.six import string_types
Expand Down Expand Up @@ -347,7 +348,15 @@ def to_filename(self, filename):
-------
None
'''
self.file_map = self.filespec_to_file_map(filename)
self.file_map = file_map = self.filespec_to_file_map(filename)
for _, fh in file_map.items():
if not isinstance(fh, FileHolder):
continue
if os.path.exists(fh.filename):
# Remove previous file where new file would be saved
# Necessary e.g. for cases where file is a symlink pointing
# to some non-writable file (e.g. under git annex control)
os.unlink(fh.filename)
self.to_file_map()

def to_filespec(self, filename):
Expand Down

0 comments on commit 99af2f4

Please sign in to comment.