Skip to content

Commit

Permalink
Removing log files that are created while calling changeCobraSolver
Browse files Browse the repository at this point in the history
  • Loading branch information
tpfau committed Jan 8, 2018
1 parent 1e7e1ac commit 9e69aed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
42 changes: 7 additions & 35 deletions initCobraToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ function initCobraToolbox()
% define the root path of The COBRA Toolbox and change to it.
CBTDIR = fileparts(which('initCobraToolbox'));
cd(CBTDIR);

%get the current content of the init Folder
CobraContent = dir(CBTDIR);

%clean up after init
finishing = onCleanup(@() cleanDir(CobraContent));


% add the external install folder
addpath(genpath([CBTDIR filesep 'external' filesep 'install']));

% add the install folder
addpath(genpath([CBTDIR filesep 'src' filesep 'base' filesep 'install']));

%create the Cleanup function
%get the current content of the init Folder
CobraContent = dir(CBTDIR);
finishing = onCleanup(@() removeNewLogsFromDir(CBTDIR,CobraContent));


% check if git is installed
checkGit();

Expand Down Expand Up @@ -636,32 +636,4 @@ function checkGit()
end
end
end
end


function cleanDir(content)
% Removes all log files from the cobra base folder that were not present
% in the content
%
% USAGE:
% cleanDir(content)
%
% INPUT:
% content: a directory structure as obtained by dir
%
global CBTDIR

%Get the Content of the CBTDIR
newContent = dir(CBTDIR);

%Get all .log files that were present only after initCobraToolbox was
%called.
diffContent = setdiff({newContent.name},{content.name});
matching = cellfun(@(x) ~isempty(regexp(x,'\.log$','ONCE')),diffContent);
LogFiles = diffContent(matching);
%Attach the CBTDirectory to delete the right files.
LogFiles = strcat(CBTDIR, filesep, LogFiles);
if ~isempty(LogFiles)
delete(LogFiles{:});
end
end
5 changes: 5 additions & 0 deletions src/base/solvers/changeCobraSolver.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
global MINOS_PATH;
global ILOG_CPLEX_PATH;


if nargin < 3
printLevel = 1;
end
Expand Down Expand Up @@ -198,6 +199,10 @@
ENV_VARS.printLevel = true;
end

%Clean up, after changing the solver, this happens only if CBTDIR is
%actually set i.e. initCobraToolbox is called before).
finish = onCleanup(@() removeNewLogsFromDir(pwd, dir(pwd)));

% configure the environment variables
configEnvVars();

Expand Down

0 comments on commit 9e69aed

Please sign in to comment.