Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: copyfile()/symlinks on Linux, Matlab < R2020a #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions spm_BIDS_App.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,27 @@
%-Copy participants' data
%------------------------------------------------------------------
for s=1:numel(BIDS_App.participants)
%fprintf('Temporary directory: %s\n',...
% fullfile(BIDS_App.tmpdir,BIDS_App.participants{s}));
sts = copyfile(fullfile(BIDS_App.dir,BIDS_App.participants{s}),...
fullfile(BIDS_App.tmpdir,BIDS_App.participants{s}));
%
% Datasets may be managed with symlinks (e.g. datalad/git-annex)
%
% Prior to Matlab 2020, copyfile() on Linux will not dereference
% the symlink, which can easily break if the target is relative.
% To save space keeping the symblic would be the better choice, but
% it's much harder to determine the correct location for all
% platforms, so we resort to cp -L in that special case and always
% dereference.
%
% https://www.mathworks.com/help/matlab/ref/copyfile.html
%
matlab_ver = str2num(erase(ver('MATLAB').('Version'), '.'));
if isunix && matlab_ver <= 98 % We should always be on Linux, but still
sts = system(sprintf('cp -rL "%s" "%s"', fullfile(BIDS_App.dir, BIDS_App.participants{s}),...
fullfile(BIDS_App.tmpdir, BIDS_App.participants{s})));
sts = ~ sts; % exit semantic is inverted in shell
else
sts = copyfile(fullfile(BIDS_App.dir,BIDS_App.participants{s}),...
fullfile(BIDS_App.tmpdir,BIDS_App.participants{s}));
end
if ~sts
error('Data could not be temporarily copied.');
end
Expand Down