Skip to content

saving image to a "new" file, which is a symlink... what should happen? #465

Open
@yarikoptic

Description

@yarikoptic

ATM

  • even if intend to write to a "new" file, if file exists and a symlink, it would write into a file pointed by the symlink... (well -- to say the truth -- this behavior is consistent with e.g. how > in shell works):
In [1]: import nibabel as nib

In [2]: !ln -s nonexistent out.nii.gz

In [3]: !ls -l nonexistent out.nii.gz
ls: cannot access 'nonexistent': No such file or directory
lrwxrwxrwx 1 yoh yoh 11 Jul 28 23:29 out.nii.gz -> nonexistent

*In [7]: nib.Nifti1Image(np.arange(12).reshape((2,2,3)), None, None).to_filename('out.nii.gz')

In [8]: !ls -l nonexistent out.nii.gz
-rw------- 1 yoh yoh 96 Jul 28 23:30 nonexistent
lrwxrwxrwx 1 yoh yoh 11 Jul 28 23:29 out.nii.gz -> nonexistent
  • if file pointed by a symlink exists but with permissions removed for writing (belongs to other user, or explicitly write bit removed, e.g. under annex):

In [9]: !chmod a-w nonexistent

In [10]: nib.Nifti1Image(np.arange(12).reshape((2,2,3)), None, None).to_filename('out.nii.gz')
...
/home/yoh/proj/nipy/nipy-suite/nibabel/nibabel/openers.py in _gzip_open(fileish, *args, **kwargs)
     62 
     63 def _gzip_open(fileish, *args, **kwargs):
---> 64     gzip_file = BufferedGzipFile(fileish, *args, **kwargs)
     65 
     66     # Speedup for #209; attribute not present in in Python 3.5

/usr/lib/python2.7/gzip.pyc in __init__(self, filename, mode, compresslevel, fileobj, mtime)
     92             mode += 'b'
     93         if fileobj is None:
---> 94             fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
     95         if filename is None:
     96             # Issue #13781: os.fdopen() creates a fileobj with a bogus name

IOError: [Errno 13] Permission denied: 'out.nii.gz'

I wondered... would it be sensible to suggest to first remove the file intended to be written to (at least in to_filename) before writing? that would allow to interact with git-annex'ed datasets more easily,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions