1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2002-2008, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see
17 // <http://www.gnu.org/licenses/>.
18 //
19
20 #include <common/ac/assert.h>
21
22 #include <common/str_list.h>
23 #include <common/trace.h>
24 #include <libaegis/change.h>
25 #include <libaegis/change/env_set.h>
26 #include <libaegis/lock.h>
27 #include <libaegis/os.h>
28 #include <libaegis/sub.h>
29 #include <libaegis/user.h>
30
31
32 void
run_new_file_undo_command(string_list_ty * wlp,const user_ty::pointer & up)33 change::run_new_file_undo_command(string_list_ty *wlp,
34 const user_ty::pointer &up)
35 {
36 trace(("change::run_change_file_command(this = %p)\n{\n", this));
37
38 assert(!lock_active());
39 assert(reference_count >= 1);
40 pconf_ty *pcp = change_pconf_get(this, 0);
41 string_ty *the_command = pcp->new_file_undo_command;
42 if (!the_command)
43 the_command = pcp->change_file_undo_command;
44 if (!the_command)
45 the_command = pcp->change_file_command;
46 if (!the_command || !the_command->str_length)
47 {
48 trace(("}\n"));
49 return;
50 }
51
52 sub_context_ty sc;
53 string_ty *the_files = wlp->unsplit();
54 sc.var_set_string("File_List", the_files);
55 sc.var_optional("File_List");
56 str_free(the_files);
57 the_command = sc.substitute(this, the_command);
58
59 string_ty *dd = change_development_directory_get(this, 0);
60 change_env_set(this, 0);
61 user_ty::become scoped(up);
62 os_execute(the_command, OS_EXEC_FLAG_NO_INPUT | OS_EXEC_FLAG_ERROK, dd);
63 str_free(the_command);
64 trace(("}\n"));
65 }
66
67
68 // vim: set ts=8 sw=4 et :
69