copyfile permissions

12 views (last 30 days)
Tim Davis
Tim Davis on 2 Nov 2011
I have MATLAB running on a networked filesystem (Linux, NFS). When I do 'cp -p' at the Linux command line to copy with permissions preserved, the copy is made but I get a warning
cp: preserving permissions for `targetfilenamehere': Operation not supported.
OK, I can ignore my OS complaints. Now, the real problem is that this messes up MATLAB. The copyfile command used inside MATLAB generates the same error, while it actually does copy the file.
The error causes copyfile to 'fail' by throwing an error.
>> copyfile gunk3.txt gunk4.txt ??? Error using ==> copyfile cp: preserving permissions for `/cise/homes/davis/gunk4.txt': Operation not supported
There appears to be no way to tell copyfile that this 'error' is not really an error.
There is an ugly workaround (see below), but this seems very ad hoc and fragile. What if the error message changes, for example? This code, below, is not very portable, yet I must rely on it in code that must be portable and usable for end-users on many OS's and many MATLAB versions. Not a trivial problem.
is there a more elegant solution? A better solution would be for 'copyfile' to issue a warning about permissions, not an error. But that requires a change to MATLAB itself.
function cpfile (src, dst)
% cpfile: copy the src file to the filename dst, overwriting dst if it exists
rmfile (dst)
if (length (dir (src)) == 0) %#ok
error ('File does not exist') ;
end
try
copyfile (src, dst) ;
catch ME
% ignore errors of the form "cp: preserving permissions: ...
% Operation not supported". rethrow all other errors.
if (isempty (strfind (ME.message, 'Operation not supported')))
rethrow (ME) ;
end
end

Answers (1)

Walter Roberson
Walter Roberson on 2 Nov 2011
  1 Comment
Tim Davis
Tim Davis on 2 Nov 2011
That's not a workable solution. This is code that goes out to thousands of people, and I can't ask them all to add a fake 'cp' to their linux path.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!