copyfile permissions
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2011-11-2
Please see the previous discussion at http://www.mathworks.com/matlabcentral/answers/8201-couldn-t-run-codegen-under-matlab
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!