Skip to content

Commit

Permalink
SetupPsychtoolbox(): Try to fix it properly for macOS wrt. xattr.
Browse files Browse the repository at this point in the history
Skip xattr calls for .mltbx installed files via Matlab Add-On explorer, as those already
have their quarantine flags removed.

For other (zip file) install locations, handle blanks/spaces in the installation path.

Also some output text cleanups and fixes. Tested with .mltbx and zip file path install on
path with spaces etc. Lets hope this goes better.
  • Loading branch information
kleinerm committed Jun 12, 2024
1 parent 631bb29 commit 956264a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Psychtoolbox/SetupPsychtoolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)
% folder. Obviously you need to somehow get a copy, either via conventional
% download from a computer with network connection, visit this URL for that
% download: http://psychtoolbox.org/download.html
% Or from a helpful colleague or copied from some other machine.
% Or from a helpful colleague, or copied from some other machine.
%
% 2. Change your Matlab/Octave working directory to the Psychtoolbox installation
% folder, e.g., 'cd /Applications/Psychtoolbox'.
Expand Down Expand Up @@ -55,6 +55,8 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)
% 04/01/16 mk 64-Bit Octave-4 support for MS-Windows established.
% 06/01/16 mk 32-Bit Octave-4 support for MS-Windows removed.
% 01/25/24 mk Cleanup, dead code removal.
% 06/12/24 mk Fixup for spaces in install path on macOS for use of xattr,
% and skip xattr if installed as .mltbx file via Add-On explorer.

% Flush all MEX files: This is needed at least on M$-Windows if Screen et al. are still loaded.
clear mex; %#ok<CLMEX>
Expand All @@ -75,7 +77,7 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)

if ~IsWin && ~IsOSX && ~IsLinux
fprintf('Sorry, this updater doesn''t support your operating system: %s.\n', computer);
fprintf([mfilename ' can only install the Linux, Windows and macOS versions of the Psychtoolbox-3.\n']);
fprintf([mfilename ' can only set up the Linux, Windows and macOS versions of the Psychtoolbox-3.\n']);
error(['Your operating system is not supported by ' mfilename '.']);
end

Expand Down Expand Up @@ -106,7 +108,7 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)

fprintf(['Once "savepath" works (no error message), run ' mfilename ' again.\n']);
fprintf('Alternatively you can choose to continue with installation, but then you will have\n');
fprintf('to resolve this permission isssue later and add the path to the Psychtoolbox manually.\n\n');
fprintf('to resolve this permission issue later and add the path to the Psychtoolbox manually.\n\n');
if ~tryNonInteractiveSetup
answer=input('Do you want to continue the installation despite the failure of SAVEPATH (yes or no)? ','s');
else
Expand Down Expand Up @@ -196,7 +198,8 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)
fprintf('Success.\n\n');
end

if IsOSX
% macOS and not a Matlab add-on? Add-on toolboxes don't need quarantine removal.
if IsOSX && isempty(strfind(targetdirectory, 'MATLAB Add-Ons')) %#ok<STREMP>
% Apples trainwreck needs special treatment. If Psychtoolbox has been
% downloaded via a webbrowser as a zip file or tgz file and then
% extracted, then all binary executable files like .dylib's and
Expand All @@ -205,6 +208,10 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)
% Thanks Apple! Use the xattr command to remove the quarantine flag.
fprintf('Trying to fixup Apple macOS broken security workflow by removing the quarantine flag from our mex files...\n\n');

% Escape all spaces in the path p with a backslash, so shell utilities
% like xattr can work and don't choke on pathes with blanks:
p = strrep(p, ' ', '\ ');

if IsOctave
% Fix the Octave mex files:
if IsARM
Expand All @@ -231,7 +238,7 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)
if isempty(strfind(msg, 'xattr: com.apple.quarantine')) %#ok<STREMP>
fprintf('FAILED! Psychtoolbox will likely not work correctly!\n');
PsychPaidSupportAndServices(2);
error(['Removing the quarantine flag from our mex files to workaround macOS brokeness failed! Error was: ' msg]);
warning(['Removing the quarantine flag from our mex files to workaround macOS brokeness failed! Error was: ' msg]);
end
end
end
Expand Down

0 comments on commit 956264a

Please sign in to comment.