copyfile permissions

12 ビュー (過去 30 日間)
Tim Davis
Tim Davis 2011 年 11 月 2 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 11 月 2 日
  1 件のコメント
Tim Davis
Tim Davis 2011 年 11 月 2 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by