1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2005, 2006, 2008 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/errno.h>
21 #include <common/ac/stddef.h>
22 #include <common/ac/sys/types.h>
23 #include <common/ac/sys/stat.h>
24
25 #include <libaegis/dir/functor/rmdir_bg.h>
26 #include <common/nstring.h>
27 #include <libaegis/sub.h>
28
29
~dir_functor_rmdir_bg()30 dir_functor_rmdir_bg::~dir_functor_rmdir_bg()
31 {
32 }
33
34
dir_functor_rmdir_bg()35 dir_functor_rmdir_bg::dir_functor_rmdir_bg()
36 {
37 }
38
39
40 void
operator ()(msg_t msg,const nstring & path,const struct stat & st)41 dir_functor_rmdir_bg::operator()(msg_t msg, const nstring &path,
42 const struct stat &st)
43 {
44 switch (msg)
45 {
46 case msg_dir_before:
47 if (!(st.st_mode & 0200))
48 chmod(path.c_str(), ((st.st_mode & 07777) | 0200));
49 break;
50
51 case msg_dir_after:
52 if (rmdir(path.c_str()))
53 {
54 int errno_old = errno;
55 if (errno_old == ENOENT)
56 break;
57 sub_context_ty sc;
58 sc.errno_setx(errno_old);
59 sc.var_set_string("File_Name", path);
60 sc.error_intl(i18n("warning: rmdir $filename: $errno"));
61 }
62 break;
63
64 case msg_file:
65 case msg_special:
66 case msg_symlink:
67 if (unlink(path.c_str()))
68 {
69 int errno_old = errno;
70 if (errno_old == ENOENT)
71 break;
72 sub_context_ty sc;
73 sc.errno_setx(errno_old);
74 sc.var_set_string("File_Name", path);
75 sc.error_intl(i18n("warning: unlink $filename: $errno"));
76 }
77 break;
78 }
79 }
80