Skip to content

Commit 4dd4d7d

Browse files
refactor: remove duplicate Docker import logic, prevent Windows batch generation in Docker, and fix file descriptor leaks (fixes #285)
1 parent 0467ce5 commit 4dd4d7d

2 files changed

Lines changed: 108 additions & 84 deletions

File tree

import_concore.m

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,63 @@
1-
function import_concore
2-
global concore;
3-
4-
try
5-
pid = getpid();
6-
catch exc
7-
pid = feature('getpid');
8-
end
9-
outputpid = fopen('concorekill.bat','w');
10-
fprintf(outputpid,'%s',['taskkill /F /PID ',num2str(pid)]);
11-
fclose(outputpid);
12-
13-
14-
try
15-
iportfile = fopen('concore.iport');
16-
concore.iports = fscanf(iportfile,'%c');
17-
catch exc
18-
iportfile = '';
19-
end
20-
21-
try
22-
oportfile = fopen('concore.oport');
23-
concore.oports = fscanf(oportfile,'%c');
24-
catch exc
25-
oportfile = '';
26-
end
27-
28-
concore.s = '';
29-
concore.olds = '';
30-
concore.delay = 1;
31-
concore.retrycount = 0;
32-
if exist('/in1','dir')==7 % 5/20/21 work for docker or local
33-
concore.inpath = '/in';
34-
concore.outpath = '/out';
35-
else
36-
concore.inpath = 'in';
37-
concore.outpath = 'out';
38-
end
39-
concore.simtime = 0;
40-
41-
concore_default_maxtime(100);
42-
end
1+
function import_concore
2+
global concore;
3+
4+
if ispc
5+
try
6+
pid = getpid();
7+
catch exc
8+
pid = feature('getpid');
9+
end
10+
outputpid = fopen('concorekill.bat','w');
11+
if outputpid ~= -1
12+
fprintf(outputpid,'%s',['taskkill /F /PID ',num2str(pid)]);
13+
fclose(outputpid);
14+
else
15+
warning('import_concore:ConcoreKillFileOpenFailed', ...
16+
'Could not create concorekill.bat. Continuing without kill script.');
17+
end
18+
end
19+
20+
21+
try
22+
iportfile = fopen('concore.iport');
23+
concore.iports = fscanf(iportfile,'%c');
24+
if isnumeric(iportfile) && iportfile ~= -1
25+
fclose(iportfile);
26+
end
27+
iportfile = -1;
28+
catch exc
29+
if exist('iportfile', 'var') && isnumeric(iportfile) && iportfile ~= -1
30+
fclose(iportfile);
31+
end
32+
iportfile = -1;
33+
end
34+
35+
try
36+
oportfile = fopen('concore.oport');
37+
concore.oports = fscanf(oportfile,'%c');
38+
if isnumeric(oportfile) && oportfile ~= -1
39+
fclose(oportfile);
40+
end
41+
oportfile = -1;
42+
catch exc
43+
if exist('oportfile', 'var') && isnumeric(oportfile) && oportfile ~= -1
44+
fclose(oportfile);
45+
end
46+
oportfile = -1;
47+
end
48+
49+
concore.s = '';
50+
concore.olds = '';
51+
concore.delay = 1;
52+
concore.retrycount = 0;
53+
if exist('/in1','dir')==7 % 5/20/21 work for docker or local
54+
concore.inpath = '/in';
55+
concore.outpath = '/out';
56+
else
57+
concore.inpath = 'in';
58+
concore.outpath = 'out';
59+
end
60+
concore.simtime = 0;
61+
62+
concore_default_maxtime(100);
63+
end

import_concoredocker.m

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
function import_concore
2-
global concore;
3-
4-
try
5-
pid = getpid();
6-
catch exc
7-
pid = feature('getpid');
8-
end
9-
outputpid = fopen('concorekill.bat','w');
10-
fprintf(outputpid,'%s',['taskkill /F /PID ',num2str(pid)]);
11-
fclose(outputpid);
12-
13-
14-
try
15-
iportfile = fopen('concore.iport');
16-
concore.iports = fscanf(iportfile,'%c');
17-
catch exc
18-
iportfile = '';
19-
end
20-
21-
try
22-
oportfile = fopen('concore.oport');
23-
concore.oports = fscanf(oportfile,'%c');
24-
catch exc
25-
oportfile = '';
26-
end
27-
28-
concore.s = '';
29-
concore.olds = '';
30-
concore.delay = 1;
31-
concore.retrycount = 0;
32-
if exist('/in1','dir')==7 % 5/20/21 work for docker or local
33-
concore.inpath = '/in';
34-
concore.outpath = '/out';
35-
else
36-
concore.inpath = 'in';
37-
concore.outpath = 'out';
38-
end
39-
concore.simtime = 0;
40-
41-
concore_default_maxtime(100);
42-
end
1+
function import_concore
2+
global concore;
3+
4+
% Docker/Linux environment — no Windows batch file generation
5+
6+
7+
iportfile = fopen('concore.iport');
8+
if iportfile ~= -1
9+
try
10+
concore.iports = fscanf(iportfile,'%c');
11+
catch exc
12+
concore.iports = '';
13+
end
14+
fclose(iportfile);
15+
else
16+
concore.iports = '';
17+
end
18+
19+
oportfile = fopen('concore.oport');
20+
if oportfile ~= -1
21+
try
22+
concore.oports = fscanf(oportfile,'%c');
23+
catch exc
24+
concore.oports = '';
25+
end
26+
fclose(oportfile);
27+
else
28+
concore.oports = '';
29+
end
30+
31+
concore.s = '';
32+
concore.olds = '';
33+
concore.delay = 1;
34+
concore.retrycount = 0;
35+
if exist('/in1','dir')==7 % 5/20/21 work for docker or local
36+
concore.inpath = '/in';
37+
concore.outpath = '/out';
38+
else
39+
concore.inpath = 'in';
40+
concore.outpath = 'out';
41+
end
42+
concore.simtime = 0;
43+
44+
concore_default_maxtime(100);
45+
end

0 commit comments

Comments
 (0)