]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/filed/plugins/exch_root_node.c
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / filed / plugins / exch_root_node.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2018 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /* 
20  *  Written by James Harper, July 2010
21  *  
22  *  Used only in "old Exchange plugin" now deprecated.
23  */
24
25 #include "exchange-fd.h"
26
27 root_node_t::root_node_t(char *name) : node_t(name, NODE_TYPE_ROOT)
28 {
29    service_node = NULL;
30 }
31
32 root_node_t::~root_node_t()
33 {
34 }
35
36 bRC
37 root_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
38 {
39    bRC retval = bRC_OK;
40    time_t now;
41
42    _DebugMessage(100, "startBackupNode_ROOT state = %d\n", state);
43    switch(state)
44    {
45    case 0:
46       if (strcmp(PLUGIN_PATH_PREFIX_BASE, name) != 0)
47       {
48          _JobMessage(M_FATAL, "Invalid backup path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/'\n");
49          state = 999;
50          return bRC_Error;
51       }
52       // check that service_node == NULL
53       service_node = new service_node_t(bstrdup(context->path_bits[level + 1]), this);
54       state = 1;
55       // fall through
56    case 1:
57       context->current_node = service_node;
58       break;
59    case 2:
60       now = time(NULL);
61       sp->fname = full_path;
62       sp->link = full_path;
63       sp->statp.st_mode = 0700 | S_IFDIR;
64       sp->statp.st_ctime = now;
65       sp->statp.st_mtime = now;
66       sp->statp.st_atime = now;
67       sp->statp.st_size = 0;
68       sp->type = FT_DIREND;
69       break;
70    case 999:
71       return bRC_Error;
72    default:
73       _JobMessage(M_FATAL, "startBackupFile: invalid internal state %d", state);
74       state = 999;
75    }
76    return retval;
77 }
78
79 bRC
80 root_node_t::endBackupFile(exchange_fd_context_t *context)
81 {
82    bRC retval = bRC_OK;
83
84    _DebugMessage(100, "endBackupNode_ROOT state = %d\n", state);
85    switch(state)
86    {
87    case 1:
88       state = 2;
89       retval = bRC_More;
90       // free service_node here?
91       break;
92    case 2:
93       retval = bRC_OK;
94       break;
95    case 999:
96       retval = bRC_Error;
97    default:
98       _JobMessage(M_FATAL, "endBackupFile: invalid internal state %d", state);
99       state = 999;
100       return bRC_Error;
101    }
102    return retval;
103 }
104
105 bRC
106 root_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
107 {
108    _DebugMessage(0, "createFile_ROOT state = %d\n", state);
109    switch (state) {
110    case 0:
111       if (strcmp(name, PLUGIN_PATH_PREFIX_BASE) != 0) {
112          _JobMessage(M_FATAL, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/'\n");
113          state = 999;
114          return bRC_Error;
115       }
116       service_node = new service_node_t(bstrdup(context->path_bits[level + 1]), this);
117       context->current_node = service_node;
118       return bRC_OK;
119    case 1:
120       rp->create_status = CF_CREATED;
121       return bRC_OK;
122
123    /* Skip this file */
124    case 900:
125       rp->create_status = CF_SKIP;
126       return bRC_OK;
127    /* Error */
128    case 999:
129       return bRC_Error;
130    default:
131       _JobMessage(M_FATAL, "createFile: invalid internal state %d", state);
132       state = 999;
133    }
134    return bRC_Error;
135 }
136
137 bRC
138 root_node_t::endRestoreFile(exchange_fd_context_t *context)
139 {
140    _DebugMessage(0, "endRestoreFile_ROOT state = %d\n", state);
141    switch (state) {
142    case 0:
143       safe_delete(service_node);
144       state = 1;
145       return bRC_OK;
146    case 1:
147       return bRC_OK;
148    case 900:
149       return bRC_OK;
150    default:
151       _JobMessage(M_FATAL, "endRestore: invalid internal state %d", state);
152       state = 999;
153    }
154    return bRC_Error;
155 }