This repository was archived by the owner on Jan 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbDeleteRun.m
More file actions
66 lines (57 loc) · 1.35 KB
/
dbDeleteRun.m
File metadata and controls
66 lines (57 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function dbDeleteRun(run_id,dryrun)
% Deletes run from DB.
%
% DBDELETERUN(RUN_ID) to delete run
% or
% DBDELETERUN(RUN_ID,1) to show SQL statements as dry run.
if nargin<2
dryrun=0;
end
% Check run exists and is owned by user.
user = dbGuessUser();
conn = dbOpen();
sql = sprintf(['SELECT run.name FROM run JOIN user ON user_id=user.id '...
'WHERE initials=' interpString('s') ' AND run.id=%d;'],user, ...
run_id);
results = table2cell(fetch(conn.conn,sql));
if isempty(results)
error('You have no run with id %d',run_id);
end
row = results(1);
run_name = row{1};
% Delete the run.
reply = input(['Really delete run ' run_name '? (y/n): '],'s');
if isempty(reply) || reply(1) ~= 'y'
disp('Aborted.');
return
end
sql = sprintf('DELETE FROM run WHERE id = %d;',run_id);
if dryrun
disp(sql);
else
dbCheck(exec(conn.conn,sql));
end
% Delete logs.
sql = sprintf(['DELETE FROM log USING log JOIN task WHERE task_id=task.id '...
'AND run_id = %d;'],run_id);
if dryrun
disp(sql);
else
dbCheck(exec(conn.conn,sql));
end
% Delete tasks.
sql = sprintf('DELETE FROM task WHERE run_id = %d;',run_id);
if dryrun
disp(sql);
else
dbCheck(exec(conn.conn,sql));
end
% Delete run data.
global dbrunpath;
outpath = [dbrunpath filesep run_name];
cmd = ['rm -rf ' outpath];
if dryrun
disp(cmd);
else
system(cmd);
end