From 61b85230e42441a7c6ded0f5d35c034adecfe82c Mon Sep 17 00:00:00 2001 From: Michael Krause Date: Wed, 6 May 2020 09:23:26 +0200 Subject: [PATCH 1/2] FIX: copyfile()/symlinks on Linux, Matlab < R2020a --- spm_BIDS_App.m | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/spm_BIDS_App.m b/spm_BIDS_App.m index 5db30b4..82ae071 100644 --- a/spm_BIDS_App.m +++ b/spm_BIDS_App.m @@ -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 managed data 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 From 3cf147e218f4b05bd73b0725839b8ff85ad119d4 Mon Sep 17 00:00:00 2001 From: Michael Krause Date: Sun, 10 May 2020 11:56:05 +0200 Subject: [PATCH 2/2] Fix comment --- spm_BIDS_App.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spm_BIDS_App.m b/spm_BIDS_App.m index 82ae071..a1e6f47 100644 --- a/spm_BIDS_App.m +++ b/spm_BIDS_App.m @@ -224,7 +224,7 @@ %------------------------------------------------------------------ for s=1:numel(BIDS_App.participants) % - % Datasets may managed data with symlinks (e.g. datalad/git-annex) + % 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.