[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
edit on a read only file
From: |
Peter Cloetens |
Subject: |
edit on a read only file |
Date: |
Tue, 24 Nov 2009 21:45:40 +0100 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090302) |
Hello,
When you call 'edit' on a read only file, a copy of the file is made in
your home directory and the copy is edited.
People tend to edit scripts just to view the code and learn from it. The
issue is that after they used 'edit' a single time on a standard script
they will have a copy in their home directory that will become their
default.
This copy will not be maintained and necessarily give incompatibility
issues with later versions of octave.
Is there a way to change this behavior and just edit the read only file
as it is (read only)?
It could be solved by asking the user if a copy should be made or not,
something along the lines:
## If the file exists and is modifiable in place then edit it,
## otherwise copy it and then edit it.
if (! isempty (path))
fid = fopen (path, "r+t");
if (fid < 0)
copyreadonly = input("File is read-only, make a copy [y/n] ? ","s");
if strcmp(copyreadonly, "y")
from = path;
path = strcat (FUNCTION.HOME, from (rindex (from, filesep):end))
[status, msg] = copyfile (from, path, 1);
if (status == 0)
error (msg);
endif
endif
else
fclose(fid);
endif
system (sprintf (FUNCTION.EDITOR, strcat ("\"", path, "\"")),
[], FUNCTION.MODE);
return;
endif
Peter
--
Peter Cloetens
X-Ray Imaging Group
Tel: +33 4 76 88 26 50
Mailto: address@hidden
European Synchrotron Radiation Facility (ESRF)
6 rue Jules Horowitz
F-38043 Grenoble
http://www.esrf.eu
- edit on a read only file,
Peter Cloetens <=