]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/filed/plugins/root_node.c
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / filed / plugins / root_node.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2008-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation, which is 
11    listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /* 
29  *  Written by James Harper, October 2008
30  */
31
32 #include "exchange-fd.h"
33
34 root_node_t::root_node_t(char *name) : node_t(name, NODE_TYPE_ROOT)
35 {
36    service_node = NULL;
37 }
38
39 root_node_t::~root_node_t()
40 {
41 }
42
43 bRC
44 root_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
45 {
46    bRC retval = bRC_OK;
47    time_t now;
48
49    _DebugMessage(100, "startBackupNode_ROOT state = %d\n", state);
50    switch(state)
51    {
52    case 0:
53       if (strcmp(PLUGIN_PATH_PREFIX_BASE, name) != 0)
54       {
55          _JobMessage(M_FATAL, "Invalid backup path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/'\n");
56          state = 999;
57          return bRC_Error;
58       }
59       // check that service_node == NULL
60       service_node = new service_node_t(bstrdup(context->path_bits[level + 1]), this);
61       state = 1;
62       // fall through
63    case 1:
64       context->current_node = service_node;
65       break;
66    case 2:
67       now = time(NULL);
68       sp->fname = full_path;
69       sp->link = full_path;
70       sp->statp.st_mode = 0700 | S_IFDIR;
71       sp->statp.st_ctime = now;
72       sp->statp.st_mtime = now;
73       sp->statp.st_atime = now;
74       sp->statp.st_size = 0;
75       sp->type = FT_DIREND;
76       break;
77    case 999:
78       return bRC_Error;
79    default:
80       _JobMessage(M_FATAL, "startBackupFile: invalid internal state %d", state);
81       state = 999;
82    }
83    return retval;
84 }
85
86 bRC
87 root_node_t::endBackupFile(exchange_fd_context_t *context)
88 {
89    bRC retval = bRC_OK;
90
91    _DebugMessage(100, "endBackupNode_ROOT state = %d\n", state);
92    switch(state)
93    {
94    case 1:
95       state = 2;
96       retval = bRC_More;
97       // free service_node here?
98       break;
99    case 2:
100       retval = bRC_OK;
101       break;
102    case 999:
103       retval = bRC_Error;
104    default:
105       _JobMessage(M_FATAL, "endBackupFile: invalid internal state %d", state);
106       state = 999;
107       return bRC_Error;
108    }
109    return retval;
110 }
111
112 bRC
113 root_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
114 {
115    _DebugMessage(100, "createFile_ROOT state = %d\n", state);
116    switch (state) {
117    case 0:
118       if (strcmp(name, PLUGIN_PATH_PREFIX_BASE) != 0) {
119          _JobMessage(M_FATAL, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/'\n");
120          state = 999;
121          return bRC_Error;
122       }
123       service_node = new service_node_t(bstrdup(context->path_bits[level + 1]), this);
124       context->current_node = service_node;
125       return bRC_OK;
126    case 1:
127       rp->create_status = CF_CREATED;
128       return bRC_OK;
129
130    /* Skip this file */
131    case 900:
132       rp->create_status = CF_SKIP;
133       return bRC_OK;
134    /* Error */
135    case 999:
136       return bRC_Error;
137    default:
138       _JobMessage(M_FATAL, "createFile: invalid internal state %d", state);
139       state = 999;
140    }
141    return bRC_Error;
142 }
143
144 bRC
145 root_node_t::endRestoreFile(exchange_fd_context_t *context)
146 {
147    _DebugMessage(100, "endRestoreFile_ROOT state = %d\n", state);
148    switch (state) {
149    case 0:
150       delete service_node;
151       state = 1;
152       return bRC_OK;
153    case 1:
154       return bRC_OK;
155    case 900:
156       return bRC_OK;
157    default:
158       _JobMessage(M_FATAL, "endRestore: invalid internal state %d", state);
159       state = 999;
160    }
161    return bRC_Error;
162 }