Skip to content

Commit 8fe8431

Browse files
committed
Fix file cleanup after downloading and extracting liblsl release.
1 parent 52303f4 commit 8fe8431

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lsl_get_dll.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
% Then check the sister liblsl/build/install/bin folder.
4545
% Finally, check other platform-dependent locations.
4646
lsl_fname = fullfile(binarypath, so_fname);
47-
if ~exist(lsl_fname, 'file')
47+
lsl_include_dir = fullfile(binarypath, 'include');
48+
if ~exist(lsl_fname, 'file') || ~exist(lsl_include_dir, 'dir')
4849
if exist(fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'bin', so_fname), 'file')
4950
lsl_fname = fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'bin', so_fname);
5051
lsl_include_dir = fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'include');
@@ -59,7 +60,10 @@
5960
end
6061
end %if
6162

62-
if ~exist(lsl_fname,'file')
63+
% If liblsl (with headers) could not be found in the default paths,
64+
% then attempt to download it. On Unix, this will have to be installed
65+
% manually. On PC and Mac, this will be extracted then cleaned up.
66+
if ~exist(lsl_fname,'file') || ~exist(lsl_include_dir, 'dir')
6367
disp(['Could not locate the file "' so_fname '" on your computer. Attempting to download...']);
6468
LIBLSL_TAG = 'v1.14.0';
6569
LIBLSL_VER = '1.14.0';
@@ -98,9 +102,6 @@
98102
copyfile(fullfile(binarypath, 'liblsl_archive', 'bin', 'lsl.dll'), lsl_fname);
99103
copyfile(fullfile(binarypath, 'liblsl_archive', 'lib', 'lsl.lib'),...
100104
fullfile(binarypath, 'lsl.lib'));
101-
lsl_include_dir = fullfile(binarypath, 'include');
102-
copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir);
103-
rmdir(fullfile(binarypath, 'liblsl_archive'));
104105
elseif ismac
105106
% Use system tar because Matlab untar does not preserve symlinks.
106107
mkdir(fullfile(binarypath, 'liblsl_archive'));
@@ -109,11 +110,14 @@
109110
dylib_list = dir(fullfile(binarypath, '*.dylib'));
110111
[~, lib_ix] = min(cellfun(@length, {dylib_list.name}));
111112
lsl_fname = fullfile(dylib_list(lib_ix).folder, dylib_list(lib_ix).name);
112-
lsl_include_dir = fullfile(binarypath, 'include');
113-
copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir);
114-
rmdir(fullfile(binarypath, 'liblsl_archive'));
115113
elseif isunix
116114
error(['Reattempt build after manual installation of liblsl debian package:', ...
117115
' sudo dpkg -i ' fullfile(binarypath, liblsl_url_fname)]);
118116
end
117+
% Grab include_dir and Cleanup no-longer-needed downloaded files.
118+
if ispc || ismac
119+
copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir);
120+
rmdir(fullfile(binarypath, 'liblsl_archive'), 's');
121+
delete(fullfile(binarypath, liblsl_url_fname));
122+
end
119123
end

0 commit comments

Comments
 (0)