Line data Source code
1 : #include "../../burp.h"
2 : #include "../../alloc.h"
3 : #include "../../asfd.h"
4 : #include "../../async.h"
5 : #include "../../attribs.h"
6 : #include "../../cmd.h"
7 : #include "../../cntr.h"
8 : #include "../../conf.h"
9 : #include "../../conffile.h"
10 : #include "../../cstat.h"
11 : #include "../../fsops.h"
12 : #include "../../handy.h"
13 : #include "../../iobuf.h"
14 : #include "../../log.h"
15 : #include "../../sbuf.h"
16 : #include "../child.h"
17 : #include "../compress.h"
18 : #include "../resume.h"
19 : #include "blocklen.h"
20 : #include "dpth.h"
21 : #include "backup_phase2.h"
22 : #include "link.h"
23 :
24 : static size_t treepathlen=0;
25 :
26 0 : static int path_length_warn(struct iobuf *path, struct conf **cconfs)
27 : {
28 0 : if(get_int(cconfs[OPT_PATH_LENGTH_WARN]))
29 0 : logw(NULL, get_cntr(cconfs), "Path too long for tree - will save in data structure instead: %s\n", path->buf);
30 0 : return 1;
31 : }
32 :
33 4 : static int path_too_long(struct iobuf *path, struct conf **cconfs)
34 : {
35 : const char *cp;
36 : const char *cp1;
37 : size_t len;
38 :
39 4 : if(treepathlen+path->len+1>fs_full_path_max)
40 : {
41 : // FIX THIS:
42 : // Cannot warn down the asfd to the client, because it can
43 : // arrive after the client has disconnected, which causes
44 : // an error on the server side.
45 : // Would need to change the way that "backupphase2end" works
46 : // to be able to fix it.
47 0 : return path_length_warn(path, cconfs);
48 : }
49 : // We have to check every part in the path to ensure it less then fs_name_max
50 : // minimum windows case is c:/a, nix case is /
51 : // usual: c:/users, /home
52 4 : cp = strchr(path->buf, '/');
53 4 : if( !cp ) // very strange
54 0 : return strlen(path->buf) > fs_name_max ? path_length_warn(path, cconfs):0;
55 14 : while(cp && *cp)
56 : {
57 10 : cp++;
58 10 : cp1 = strchr(cp, '/');
59 10 : len = cp1? cp1-cp : strlen(cp);
60 10 : if( len > fs_name_max )
61 0 : return path_length_warn(path, cconfs);
62 : cp = cp1;
63 : }
64 : return 0;
65 : }
66 :
67 4 : static int treedata(struct sbuf *sb, struct conf **cconfs)
68 : {
69 : // Windows is sending directory data as if it is file data - this
70 : // cannot be saved in a tree structure.
71 4 : if(S_ISDIR(sb->statp.st_mode)) return 0;
72 :
73 8 : if(sb->path.cmd!=CMD_FILE
74 4 : && sb->path.cmd!=CMD_ENC_FILE
75 0 : && sb->path.cmd!=CMD_EFS_FILE)
76 : return 0;
77 :
78 4 : return !path_too_long(&sb->path, cconfs);
79 : }
80 :
81 4 : static char *set_new_datapth(struct sdirs *sdirs, struct conf **cconfs,
82 : struct sbuf *sb, struct dpth *dpth, int *istreedata)
83 : {
84 4 : char *tmp=NULL;
85 4 : char *rpath=NULL;
86 4 : if(get_int(cconfs[OPT_DIRECTORY_TREE]))
87 4 : *istreedata=treedata(sb, cconfs);
88 :
89 4 : if(*istreedata)
90 : {
91 : // We want to place this file in a directory structure like
92 : // the directory structure on the original client.
93 4 : if(!(tmp=prepend_s(TREE_DIR, sb->path.buf)))
94 : {
95 0 : log_out_of_memory(__func__);
96 : return NULL;
97 : }
98 : }
99 : else
100 : {
101 0 : if(!(tmp=strdup_w(dpth_protocol1_mk(dpth, sb->compression,
102 : sb->path.cmd), __func__))) return NULL;
103 : }
104 4 : iobuf_from_str(&sb->protocol1->datapth, CMD_DATAPTH, tmp);
105 4 : if(build_path(sdirs->datadirtmp,
106 4 : sb->protocol1->datapth.buf, &rpath, sdirs->datadirtmp))
107 : {
108 0 : logp("build path failed");
109 : return NULL;
110 : }
111 4 : return rpath;
112 : }
113 :
114 4 : static int start_to_receive_new_file(struct asfd *asfd,
115 : struct sdirs *sdirs, struct conf **cconfs,
116 : struct sbuf *sb, struct dpth *dpth)
117 : {
118 4 : int ret=-1;
119 4 : char *rpath=NULL;
120 4 : int istreedata=0;
121 :
122 : //logp("start to receive: %s\n", sb->path.buf);
123 :
124 4 : if(!(rpath=set_new_datapth(sdirs, cconfs, sb, dpth, &istreedata)))
125 : goto end;
126 :
127 4 : if(!(sb->protocol1->fzp=fzp_open(rpath, "wb")))
128 : {
129 0 : log_and_send(asfd, "make file failed");
130 0 : goto end;
131 : }
132 4 : if(!istreedata) dpth_incr(dpth);
133 : ret=0;
134 : end:
135 4 : free_w(&rpath);
136 4 : return ret;
137 : }
138 :
139 : enum processed_e
140 : {
141 : P_ERROR=-1,
142 : P_DONE_NEW=0,
143 : P_DONE_CHANGED=1,
144 : P_DONE_UNCHANGED=2,
145 : P_DONE_DELETED=3,
146 : P_NEW=4,
147 : P_CHANGED=5
148 : };
149 :
150 : #include <librsync.h>
151 :
152 2 : static enum processed_e process_changed_file(struct asfd *asfd,
153 : struct conf **cconfs,
154 : struct sbuf *cb, struct sbuf *p1b,
155 : const char *adir)
156 : {
157 2 : int ret=P_ERROR;
158 2 : size_t blocklen=0;
159 2 : char *curpath=NULL;
160 : //logp("need to process changed file: %s (%s)\n",
161 : // cb->path, cb->datapth);
162 :
163 : // Move datapth onto p1b.
164 2 : iobuf_move(&p1b->protocol1->datapth, &cb->protocol1->datapth);
165 :
166 2 : if(!(curpath=prepend_s(adir, p1b->protocol1->datapth.buf)))
167 : {
168 0 : log_out_of_memory(__func__);
169 : goto end;
170 : }
171 2 : if(dpth_protocol1_is_compressed(cb->compression, curpath))
172 0 : p1b->protocol1->sigfzp=fzp_gzopen(curpath, "rb");
173 : else
174 2 : p1b->protocol1->sigfzp=fzp_open(curpath, "rb");
175 2 : if(!p1b->protocol1->sigfzp)
176 : {
177 0 : logp("could not open %s: %s\n", curpath, strerror(errno));
178 : goto end;
179 : }
180 :
181 2 : blocklen=get_librsync_block_len(cb->endfile.buf);
182 4 : if(!(p1b->protocol1->sigjob=
183 : #ifdef RS_DEFAULT_STRONG_LEN
184 2 : rs_sig_begin(blocklen, RS_DEFAULT_STRONG_LEN)
185 : #else
186 : // This is for librsync-1.0.0. RS_DEFAULT_STRONG_LEN was 8 in
187 : // librsync-0.9.7.
188 : rs_sig_begin(blocklen, 8,
189 : rshash_to_magic_number(get_e_rshash(cconfs[OPT_RSHASH])))
190 : #endif
191 : ))
192 : {
193 0 : logp("could not start signature job.\n");
194 : goto end;
195 : }
196 : //logp("sig begin: %s\n", p1b->protocol1->datapth.buf);
197 2 : if(!(p1b->protocol1->infb=rs_filebuf_new(NULL,
198 2 : p1b->protocol1->sigfzp,
199 : NULL, blocklen, -1)))
200 : {
201 0 : logp("could not rs_filebuf_new for infb.\n");
202 : goto end;
203 : }
204 2 : if(!(p1b->protocol1->outfb=rs_filebuf_new(NULL, NULL,
205 : asfd, ASYNC_BUF_LEN, -1)))
206 : {
207 0 : logp("could not rs_filebuf_new for in_outfb.\n");
208 : goto end;
209 : }
210 :
211 : // Flag the things that need to be sent (to the client)
212 2 : p1b->flags |= SBUF_SEND_DATAPTH;
213 2 : p1b->flags |= SBUF_SEND_STAT;
214 2 : p1b->flags |= SBUF_SEND_PATH;
215 :
216 : //logp("sending sig for %s\n", p1b->path);
217 : //logp("(%s)\n", p1b->datapth);
218 :
219 2 : ret=P_CHANGED;
220 : end:
221 2 : free_w(&curpath);
222 2 : return ret;
223 : }
224 :
225 68 : static enum processed_e new_non_file(struct sbuf *p1b,
226 : struct manio *ucmanio, struct conf **cconfs)
227 : {
228 : // Is something that does not need more data backed up.
229 : // Like a directory or a link or something like that.
230 : // Goes into the unchanged file, so that it does not end up out of
231 : // order with normal files, which has to wait around for their data
232 : // to turn up.
233 68 : if(manio_write_sbuf(ucmanio, p1b))
234 : return P_ERROR;
235 68 : cntr_add(get_cntr(cconfs), p1b->path.cmd, 0);
236 68 : return P_DONE_NEW;
237 : }
238 :
239 0 : static enum processed_e changed_non_file(struct sbuf *p1b,
240 : struct manio *ucmanio, enum cmd cmd, struct conf **cconfs)
241 : {
242 : // As new_non_file.
243 0 : if(manio_write_sbuf(ucmanio, p1b))
244 : return P_ERROR;
245 0 : cntr_add_changed(get_cntr(cconfs), cmd);
246 0 : return P_DONE_CHANGED;
247 : }
248 :
249 122 : static enum processed_e process_new(struct conf **cconfs,
250 : struct sbuf *p1b, struct manio *ucmanio)
251 : {
252 122 : if(sbuf_is_filedata(p1b)
253 68 : || sbuf_is_vssdata(p1b))
254 : {
255 : //logp("need to process new file: %s\n", p1b->path);
256 : // Flag the things that need to be sent (to the client)
257 54 : p1b->flags |= SBUF_SEND_STAT;
258 54 : p1b->flags |= SBUF_SEND_PATH;
259 54 : return P_NEW;
260 : }
261 68 : return new_non_file(p1b, ucmanio, cconfs);
262 : }
263 :
264 6 : static enum processed_e process_unchanged_file(struct sbuf *p1b, struct sbuf *cb,
265 : struct manio *ucmanio, struct conf **cconfs)
266 : {
267 : // Need to re-encode the p1b attribs to include compression and
268 : // other bits and pieces that are recorded on cb.
269 6 : iobuf_move(&p1b->protocol1->datapth, &cb->protocol1->datapth);
270 6 : iobuf_move(&p1b->endfile, &cb->endfile);
271 6 : p1b->protocol1->salt=cb->protocol1->salt;
272 6 : p1b->compression=cb->compression;
273 6 : p1b->encryption=cb->encryption;
274 : // Why is winattr not getting sent in phase1?
275 6 : p1b->winattr=cb->winattr;
276 : // Need to free attr so that it is reallocated, because it may get
277 : // longer than what the client told us in phase1.
278 6 : iobuf_free_content(&p1b->attr);
279 6 : if(attribs_encode(p1b))
280 : return P_ERROR;
281 6 : if(manio_write_sbuf(ucmanio, p1b))
282 : return P_ERROR;
283 6 : cntr_add_same(get_cntr(cconfs), p1b->path.cmd);
284 6 : if(p1b->endfile.buf) cntr_add_bytes(get_cntr(cconfs),
285 0 : strtoull(p1b->endfile.buf, NULL, 10));
286 : return P_DONE_UNCHANGED;
287 : }
288 :
289 10 : static int open_previous_manifest(struct manio **manio, struct sdirs *sdirs)
290 : {
291 : struct stat statp;
292 20 : if(!lstat(sdirs->cmanifest, &statp)
293 2 : && !(*manio=manio_open(sdirs->cmanifest, "rb", PROTO_1)))
294 : {
295 0 : logp("could not open old manifest %s\n", sdirs->cmanifest);
296 : return -1;
297 : }
298 : return 0;
299 : }
300 :
301 0 : static int get_hardlink_master_from_hmanio(
302 : struct manio **hmanio,
303 : struct sdirs *sdirs,
304 : struct sbuf *cb,
305 : struct sbuf *hb
306 : ) {
307 : int passes=0;
308 : while(1)
309 : {
310 0 : sbuf_free_content(hb);
311 0 : switch(manio_read(*hmanio, hb))
312 : {
313 : case 0: // Keep going.
314 : break;
315 : case 1: // Finished OK.
316 0 : manio_close(hmanio);
317 : // Might have already been part way down the
318 : // manifest when we started. If we get to the
319 : // end, go back to the beginning once.
320 0 : if(!passes)
321 : {
322 0 : if(open_previous_manifest(hmanio,
323 : sdirs)) return -1;
324 0 : passes++;
325 0 : continue;
326 : }
327 : return 0;
328 : default: // Error;
329 : return -1;
330 : }
331 0 : if(hb->path.cmd!=CMD_FILE
332 0 : && hb->path.cmd!=CMD_ENC_FILE)
333 0 : continue;
334 0 : if(!strcmp(hb->path.buf, cb->link.buf)
335 0 : && hb->protocol1->datapth.buf)
336 : return 1; // Found it.
337 : }
338 : return -1;
339 : }
340 :
341 0 : static int relink_deleted_hardlink_master(
342 : struct dpth *dpth,
343 : struct manio **hmanio,
344 : struct sdirs *sdirs,
345 : struct sbuf *p1b,
346 : struct sbuf *cb,
347 : struct conf **cconfs
348 : ) {
349 0 : int ret=-1;
350 0 : char *newdatapth_full=NULL;
351 0 : char *olddatapth_full=NULL;
352 0 : char *newdatapth=NULL;
353 0 : char *relinkpath_full=NULL;
354 : struct stat statp;
355 0 : struct sbuf *hb=NULL;
356 0 : int istreedata=0;
357 :
358 0 : if(!(hb=sbuf_alloc(PROTO_1)))
359 : goto end;
360 :
361 0 : switch(get_hardlink_master_from_hmanio(hmanio, sdirs, cb, hb))
362 : {
363 : case 0: // Did not find it.
364 : return 0;
365 : case 1: // Found it.
366 : break;
367 : default: // Error.
368 : goto end;
369 : }
370 :
371 : // Protect against the old file being encrypted, and the new file not
372 : // being encrypted - and vice versa.
373 0 : if(p1b->path.cmd!=hb->path.cmd)
374 : return 0;
375 :
376 0 : if(!(newdatapth_full=set_new_datapth(sdirs,
377 : cconfs, p1b, dpth, &istreedata)))
378 : goto end;
379 0 : if(!istreedata) dpth_incr(dpth);
380 0 : if(!(relinkpath_full=prepend_s(sdirs->relink,
381 0 : p1b->protocol1->datapth.buf)))
382 : goto end;
383 0 : if(!(newdatapth=strdup_w(p1b->protocol1->datapth.buf, __func__)))
384 : goto end;
385 : /*
386 : printf("newdatapth_full: %s\n", newdatapth_full);
387 : printf("relinkpath_full: %s\n", relinkpath_full);
388 : printf("newdatapth: %s\n", newdatapth);
389 : printf("hbdatapth: %s\n", hb->protocol1->datapth.buf);
390 : printf("sdirs->currentdata: %s\n", sdirs->currentdata);
391 : */
392 :
393 0 : if(!(olddatapth_full=prepend_s(sdirs->currentdata,
394 0 : hb->protocol1->datapth.buf)))
395 : goto end;
396 0 : if(lstat(olddatapth_full, &statp) || !S_ISREG(statp.st_mode))
397 : {
398 0 : logw(NULL, get_cntr(cconfs),
399 : "Did not find path for relink: %s\n", olddatapth_full);
400 0 : ret=0;
401 0 : goto end;
402 : }
403 0 : if(build_path_w(relinkpath_full))
404 : goto end;
405 0 : if(do_link(olddatapth_full, relinkpath_full,
406 : &statp, cconfs, /*overwrite*/0))
407 : goto end;
408 :
409 0 : iobuf_free_content(&cb->protocol1->datapth);
410 :
411 0 : iobuf_from_str(&hb->protocol1->datapth, CMD_DATAPTH,
412 0 : p1b->protocol1->datapth.buf);
413 0 : p1b->protocol1->datapth.buf=NULL;
414 0 : iobuf_from_str(&cb->protocol1->datapth, CMD_DATAPTH, newdatapth);
415 0 : newdatapth=NULL;
416 0 : iobuf_move(&cb->endfile, &hb->endfile);
417 :
418 0 : ret=1;
419 : end:
420 0 : free_w(&newdatapth_full);
421 0 : free_w(&olddatapth_full);
422 0 : free_w(&newdatapth);
423 0 : free_w(&relinkpath_full);
424 0 : sbuf_free(&hb);
425 0 : return ret;
426 : }
427 :
428 4 : static int librsync_enabled(struct sbuf *p1b,
429 : struct sbuf *cb,
430 : struct conf **cconfs)
431 : {
432 : off_t max_size;
433 4 : if(!get_int(cconfs[OPT_LIBRSYNC]))
434 : return 0;
435 4 : max_size=(off_t)get_uint64_t(cconfs[OPT_LIBRSYNC_MAX_SIZE]);
436 4 : if(!max_size)
437 : return 1;
438 0 : return max_size >= cb->statp.st_size && max_size >= p1b->statp.st_size;
439 : }
440 :
441 10 : static enum processed_e maybe_do_delta_stuff(struct asfd *asfd,
442 : struct dpth *dpth,
443 : struct sdirs *sdirs, struct sbuf *cb, struct sbuf *p1b,
444 : struct manio *ucmanio, struct manio **hmanio, struct conf **cconfs)
445 : {
446 10 : int oldcompressed=0;
447 10 : int compression=p1b->compression;
448 :
449 : // If the file type changed, I think it is time to back it up again
450 : // (for example, EFS changing to normal file, or back again).
451 10 : if(cb->path.cmd!=p1b->path.cmd)
452 : {
453 0 : if(hmanio && *hmanio
454 0 : && cb->path.cmd==CMD_HARD_LINK
455 0 : && (p1b->path.cmd==CMD_FILE
456 0 : || p1b->path.cmd==CMD_ENC_FILE))
457 : {
458 0 : struct stat *p1statp=&p1b->statp;
459 0 : struct stat *cstatp=&cb->statp;
460 : // A hardlink changed into a file. It is possible that
461 : // The file that the hardlink was pointing to got
462 : // deleted. Maybe we can reuse the previous file.
463 0 : if(p1statp->st_dev==cstatp->st_dev
464 0 : && p1statp->st_ino==cstatp->st_ino
465 0 : && p1statp->st_mtime==cstatp->st_mtime)
466 : {
467 0 : switch(relink_deleted_hardlink_master(
468 : dpth, hmanio, sdirs,
469 : p1b, cb, cconfs))
470 : {
471 : case 0:
472 : break;
473 : case 1:
474 0 : return process_unchanged_file(
475 : p1b, cb,
476 : ucmanio, cconfs);
477 : default:
478 : return P_ERROR;
479 : }
480 : }
481 : }
482 0 : return process_new(cconfs, p1b, ucmanio);
483 : }
484 :
485 : // mtime is the actual file data.
486 : // ctime is the attributes or meta data.
487 10 : if(cb->statp.st_mtime==p1b->statp.st_mtime
488 6 : && cb->statp.st_ctime==p1b->statp.st_ctime)
489 : {
490 : // got an unchanged file
491 : //logp("got unchanged file: %s %c %c\n",
492 : // cb->path.buf, cb->path.cmd, p1b->path.cmd);
493 6 : return process_unchanged_file(p1b, cb, ucmanio, cconfs);
494 : }
495 :
496 4 : if(cb->statp.st_mtime==p1b->statp.st_mtime
497 0 : && cb->statp.st_ctime!=p1b->statp.st_ctime)
498 : {
499 : // File data stayed the same, but attributes or meta data
500 : // changed. We already have the attributes, but may need to get
501 : // extra meta data.
502 : // FIX THIS horrible mess.
503 0 : if(cb->path.cmd==CMD_ENC_METADATA
504 0 : || p1b->path.cmd==CMD_ENC_METADATA
505 0 : || cb->path.cmd==CMD_EFS_FILE
506 0 : || p1b->path.cmd==CMD_EFS_FILE
507 : // FIX THIS: make unencrypted metadata use the librsync
508 0 : || cb->path.cmd==CMD_METADATA
509 0 : || p1b->path.cmd==CMD_METADATA
510 0 : || sbuf_is_vssdata(cb)
511 0 : || sbuf_is_vssdata(p1b))
512 0 : return process_new(cconfs, p1b, ucmanio);
513 : // On Windows, we have to back up the whole file if ctime
514 : // changed, otherwise things like permission changes do not get
515 : // noticed. So, in that case, fall through to the changed stuff
516 : // below.
517 : // Non-Windows clients finish here.
518 0 : else if(!get_int(cconfs[OPT_CLIENT_IS_WINDOWS]))
519 0 : return process_unchanged_file(p1b,
520 : cb, ucmanio, cconfs);
521 : }
522 :
523 : // Got a changed file.
524 : //logp("got changed file: %s\n", p1b->path.buf);
525 :
526 : // If either old or new is encrypted, or librsync is off, we need to
527 : // get a new file.
528 : // FIX THIS horrible mess.
529 4 : if(!librsync_enabled(p1b, cb, cconfs)
530 : // FIX THIS: make unencrypted metadata use the librsync
531 4 : || cb->path.cmd==CMD_METADATA
532 4 : || p1b->path.cmd==CMD_METADATA
533 4 : || sbuf_is_encrypted(cb)
534 2 : || sbuf_is_encrypted(p1b)
535 2 : || sbuf_is_vssdata(cb)
536 2 : || sbuf_is_vssdata(p1b))
537 2 : return process_new(cconfs, p1b, ucmanio);
538 :
539 : // Get new files if they have switched between compression on or off.
540 2 : if(cb->protocol1->datapth.buf
541 2 : && dpth_protocol1_is_compressed(cb->compression,
542 : cb->protocol1->datapth.buf))
543 0 : oldcompressed=1;
544 2 : if( ( oldcompressed && !compression)
545 2 : || (!oldcompressed && compression))
546 0 : return process_new(cconfs, p1b, ucmanio);
547 :
548 : // Otherwise, do the delta stuff (if possible).
549 2 : if(sbuf_is_filedata(p1b)
550 0 : || sbuf_is_vssdata(p1b))
551 2 : return process_changed_file(asfd, cconfs, cb, p1b,
552 2 : sdirs->currentdata);
553 0 : return changed_non_file(p1b, ucmanio, p1b->path.cmd, cconfs);
554 : }
555 :
556 : static enum processed_e process_deleted_file(struct sbuf *cb,
557 : struct conf **cconfs)
558 : {
559 2 : cntr_add_deleted(get_cntr(cconfs), cb->path.cmd);
560 : return P_DONE_DELETED;
561 : }
562 :
563 : // return 1 to say that a file was processed
564 12 : static enum processed_e maybe_process_file(struct asfd *asfd,
565 : struct dpth *dpth,
566 2 : struct sdirs *sdirs, struct sbuf *cb, struct sbuf *p1b,
567 : struct manio *ucmanio, struct manio **hmanio, struct conf **cconfs)
568 : {
569 : int pcmp;
570 12 : if(p1b)
571 : {
572 11 : if(!(pcmp=sbuf_pathcmp(cb, p1b)))
573 10 : return maybe_do_delta_stuff(asfd, dpth,sdirs, cb, p1b,
574 : ucmanio, hmanio, cconfs);
575 1 : else if(pcmp>0)
576 : {
577 : //logp("ahead: %s\n", p1b->path.buf);
578 : // ahead - need to get the whole file
579 0 : return process_new(cconfs, p1b, ucmanio);
580 : }
581 : }
582 : //logp("behind: %s\n", p1b->path.buf);
583 : // Behind - need to read more from the old manifest.
584 : // Count a deleted file - it was in the old manifest
585 : // but not the new.
586 4 : return process_deleted_file(cb, cconfs);
587 : }
588 :
589 : enum sts_e
590 : {
591 : STS_ERROR=-1,
592 : STS_OK=0,
593 : STS_BLOCKED=1
594 : };
595 :
596 : // Return 1 if there is still stuff needing to be sent.
597 : // FIX THIS: lots of repeated code.
598 63 : static enum sts_e do_stuff_to_send(struct asfd *asfd,
599 : struct sbuf *p1b, char **last_requested)
600 : {
601 : static struct iobuf wbuf;
602 63 : if(p1b->flags & SBUF_SEND_DATAPTH)
603 : {
604 2 : iobuf_copy(&wbuf, &p1b->protocol1->datapth);
605 2 : switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
606 : {
607 : case APPEND_OK: break;
608 : case APPEND_BLOCKED: return STS_BLOCKED;
609 0 : default: return STS_ERROR;
610 : }
611 2 : p1b->flags &= ~SBUF_SEND_DATAPTH;
612 : }
613 63 : if(p1b->flags & SBUF_SEND_STAT)
614 : {
615 56 : iobuf_copy(&wbuf, &p1b->attr);
616 56 : switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
617 : {
618 : case APPEND_OK: break;
619 : case APPEND_BLOCKED: return STS_BLOCKED;
620 0 : default: return STS_ERROR;
621 : }
622 56 : p1b->flags &= ~SBUF_SEND_STAT;
623 : }
624 63 : if(p1b->flags & SBUF_SEND_PATH)
625 : {
626 56 : iobuf_copy(&wbuf, &p1b->path);
627 56 : switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
628 : {
629 : case APPEND_OK: break;
630 : case APPEND_BLOCKED: return STS_BLOCKED;
631 0 : default: return STS_ERROR;
632 : }
633 56 : p1b->flags &= ~SBUF_SEND_PATH;
634 56 : free_w(last_requested);
635 56 : if(!(*last_requested=strdup_w(p1b->path.buf, __func__)))
636 : return STS_ERROR;
637 : }
638 63 : if(p1b->protocol1->sigjob && !(p1b->flags & SBUF_SEND_ENDOFSIG))
639 : {
640 : rs_result sigresult;
641 :
642 4 : switch((sigresult=rs_async(p1b->protocol1->sigjob,
643 : &(p1b->protocol1->rsbuf),
644 : p1b->protocol1->infb, p1b->protocol1->outfb)))
645 : {
646 : case RS_DONE:
647 2 : p1b->flags |= SBUF_SEND_ENDOFSIG;
648 2 : break;
649 : case RS_BLOCKED:
650 : case RS_RUNNING:
651 : // keep going round the loop.
652 : return STS_BLOCKED;
653 : default:
654 0 : logp("error in rs_async: %d\n", sigresult);
655 0 : return STS_ERROR;
656 : }
657 : }
658 61 : if(p1b->flags & SBUF_SEND_ENDOFSIG)
659 : {
660 2 : iobuf_from_str(&wbuf, CMD_END_FILE, (char *)"endfile");
661 2 : switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
662 : {
663 : case APPEND_OK: break;
664 : case APPEND_BLOCKED: return STS_BLOCKED;
665 0 : default: return STS_ERROR;
666 : }
667 2 : p1b->flags &= ~SBUF_SEND_ENDOFSIG;
668 : }
669 : return STS_OK;
670 : }
671 :
672 4 : static int start_to_receive_delta(struct sdirs *sdirs, struct sbuf *rb)
673 : {
674 4 : if(rb->compression)
675 : {
676 0 : if(!(rb->protocol1->fzp=fzp_gzopen(sdirs->deltmppath,
677 0 : comp_level(rb->compression))))
678 : return -1;
679 : }
680 : else
681 : {
682 4 : if(!(rb->protocol1->fzp=fzp_open(sdirs->deltmppath, "wb")))
683 : return -1;
684 : }
685 4 : rb->flags |= SBUF_RECV_DELTA;
686 :
687 : return 0;
688 : }
689 :
690 4 : static int finish_delta(struct sdirs *sdirs, struct sbuf *rb)
691 : {
692 4 : int ret=0;
693 4 : char *deltmp=NULL;
694 4 : char *delpath=NULL;
695 4 : if(!(deltmp=prepend_s("deltas.forward", rb->protocol1->datapth.buf))
696 4 : || !(delpath=prepend_s(sdirs->working, deltmp))
697 4 : || mkpath(&delpath, sdirs->working)
698 : // Rename race condition is of no consequence here, as delpath will
699 : // just get recreated.
700 4 : || do_rename(sdirs->deltmppath, delpath))
701 : ret=-1;
702 4 : free_w(&delpath);
703 4 : free_w(&deltmp);
704 4 : return ret;
705 : }
706 :
707 8 : static int deal_with_receive_end_file(struct asfd *asfd, struct sdirs *sdirs,
708 4 : struct sbuf *rb, struct manio *chmanio, struct conf **cconfs,
709 : char **last_requested)
710 : {
711 8 : int ret=-1;
712 : static char *cp=NULL;
713 : static struct iobuf *rbuf;
714 8 : struct cntr *cntr=get_cntr(cconfs);
715 8 : rbuf=asfd->rbuf;
716 : // Finished the file.
717 : // Write it to the phase2 file, and free the buffers.
718 :
719 8 : if(fzp_close(&(rb->protocol1->fzp)))
720 : {
721 0 : logp("error closing delta for %s in receive\n", rb->path.buf);
722 : goto end;
723 : }
724 8 : iobuf_move(&rb->endfile, rbuf);
725 12 : if(rb->flags & SBUF_RECV_DELTA && finish_delta(sdirs, rb))
726 : goto end;
727 :
728 8 : if(manio_write_sbuf(chmanio, rb))
729 : goto end;
730 :
731 8 : if(rb->flags & SBUF_RECV_DELTA)
732 4 : cntr_add_changed(cntr, rb->path.cmd);
733 : else
734 4 : cntr_add(cntr, rb->path.cmd, 0);
735 :
736 8 : if(*last_requested && !strcmp(rb->path.buf, *last_requested))
737 2 : free_w(last_requested);
738 :
739 8 : cp=strchr(rb->endfile.buf, ':');
740 8 : if(rb->endfile.buf)
741 8 : cntr_add_bytes(cntr, strtoull(rb->endfile.buf, NULL, 10));
742 : if(cp)
743 : {
744 : // checksum stuff goes here
745 : }
746 :
747 : ret=0;
748 : end:
749 8 : sbuf_free_content(rb);
750 8 : return ret;
751 : }
752 :
753 8 : static int deal_with_receive_append(struct asfd *asfd, struct sbuf *rb)
754 : {
755 8 : int app=0;
756 : static struct iobuf *rbuf;
757 8 : rbuf=asfd->rbuf;
758 : //logp("rbuf->len: %d\n", rbuf->len);
759 :
760 8 : if(rb->protocol1->fzp)
761 8 : app=fzp_write(rb->protocol1->fzp, rbuf->buf, rbuf->len);
762 :
763 8 : if(app>0) return 0;
764 0 : logp("error when appending: %d\n", app);
765 0 : asfd->write_str(asfd, CMD_ERROR, "write failed");
766 : return -1;
767 : }
768 :
769 8 : static int deal_with_filedata(struct asfd *asfd,
770 : struct sdirs *sdirs, struct sbuf *rb,
771 : struct iobuf *rbuf, struct dpth *dpth, struct conf **cconfs)
772 : {
773 8 : iobuf_move(&rb->path, rbuf);
774 :
775 8 : if(rb->protocol1->datapth.buf)
776 : {
777 : // Receiving a delta.
778 4 : if(start_to_receive_delta(sdirs, rb))
779 : {
780 0 : logp("error in start_to_receive_delta\n");
781 0 : return -1;
782 : }
783 : return 0;
784 : }
785 :
786 : // Receiving a whole new file.
787 4 : if(start_to_receive_new_file(asfd, sdirs, cconfs, rb, dpth))
788 : {
789 0 : logp("error in start_to_receive_new_file\n");
790 0 : return -1;
791 : }
792 : return 0;
793 : }
794 :
795 : enum str_e
796 : {
797 : STR_ERROR=-1,
798 : STR_OK=0,
799 : STR_FINISHED=1
800 : };
801 :
802 : // returns 1 for finished ok.
803 85 : static enum str_e do_stuff_to_receive(struct asfd *asfd,
804 : struct sdirs *sdirs, struct conf **cconfs,
805 : struct sbuf *rb, struct manio *chmanio,
806 : struct dpth *dpth, char **last_requested)
807 : {
808 85 : struct iobuf *rbuf=asfd->rbuf;
809 :
810 170 : if(rbuf->cmd==CMD_MESSAGE
811 85 : || rbuf->cmd==CMD_WARNING)
812 : {
813 0 : struct cntr *cntr=NULL;
814 0 : if(cconfs) cntr=get_cntr(cconfs);
815 0 : log_recvd(rbuf, cntr, 0);
816 0 : return STR_OK;
817 : }
818 :
819 85 : if(rb->protocol1->fzp)
820 : {
821 : // Currently writing a file (or meta data)
822 16 : switch(rbuf->cmd)
823 : {
824 : case CMD_APPEND:
825 8 : if(deal_with_receive_append(asfd, rb))
826 : goto error;
827 : return STR_OK;
828 : case CMD_END_FILE:
829 8 : if(deal_with_receive_end_file(asfd, sdirs, rb,
830 : chmanio, cconfs, last_requested))
831 : goto error;
832 : return STR_OK;
833 : default:
834 0 : iobuf_log_unexpected(rbuf, __func__);
835 0 : goto error;
836 : }
837 : }
838 :
839 : // Otherwise, expecting to be told of a file to save.
840 69 : switch(rbuf->cmd)
841 : {
842 : case CMD_DATAPTH:
843 4 : iobuf_move(&rb->protocol1->datapth, rbuf);
844 4 : return STR_OK;
845 : case CMD_ATTRIBS:
846 8 : iobuf_move(&rb->attr, rbuf);
847 8 : attribs_decode(rb);
848 8 : return STR_OK;
849 : case CMD_GEN:
850 5 : if(!strcmp(rbuf->buf, "okbackupphase2end"))
851 : goto end_phase2;
852 0 : iobuf_log_unexpected(rbuf, __func__);
853 0 : goto error;
854 : case CMD_INTERRUPT:
855 : // Interrupt - forget about the last requested
856 : // file if it matches. Otherwise, we can get
857 : // stuck on the select in the async stuff,
858 : // waiting for something that will never arrive.
859 44 : if(*last_requested
860 44 : && !strcmp(rbuf->buf, *last_requested))
861 1 : free_w(last_requested);
862 : return STR_OK;
863 : default:
864 : break;
865 : }
866 8 : if(iobuf_is_filedata(rbuf)
867 0 : || iobuf_is_vssdata(rbuf))
868 : {
869 8 : if(deal_with_filedata(asfd, sdirs, rb, rbuf, dpth, cconfs))
870 : goto error;
871 : return STR_OK;
872 : }
873 0 : iobuf_log_unexpected(rbuf, __func__);
874 :
875 : error:
876 : return STR_ERROR;
877 : end_phase2:
878 : return STR_FINISHED;
879 : }
880 :
881 5 : static int vss_opts_changed(struct sdirs *sdirs, struct conf **cconfs,
882 : const char *incexc)
883 : {
884 5 : int ret=-1;
885 : struct conf **oldconfs;
886 : struct conf **newconfs;
887 5 : if(!(oldconfs=confs_alloc())
888 5 : || !(newconfs=confs_alloc()))
889 : goto end;
890 5 : confs_init(oldconfs);
891 5 : confs_init(newconfs);
892 :
893 : // Figure out the old config, which is in the incexc file left
894 : // in the current backup directory on the server.
895 5 : if(conf_parse_incexcs_path(oldconfs, sdirs->cincexc))
896 : {
897 : // Assume that the file did not exist, and therefore
898 : // the old split_vss setting is 0.
899 4 : set_int(oldconfs[OPT_SPLIT_VSS], 0);
900 4 : set_int(oldconfs[OPT_STRIP_VSS], 0);
901 : }
902 :
903 : // Figure out the new config, which is either in the incexc file from
904 : // the client, or in the cconf on the server.
905 5 : if(incexc)
906 : {
907 0 : if(conf_parse_incexcs_buf(newconfs, incexc))
908 : {
909 : // Should probably not got here.
910 0 : set_int(newconfs[OPT_SPLIT_VSS], 0);
911 0 : set_int(newconfs[OPT_STRIP_VSS], 0);
912 : }
913 : }
914 : else
915 : {
916 5 : set_int(newconfs[OPT_SPLIT_VSS],
917 5 : get_int(cconfs[OPT_SPLIT_VSS]));
918 5 : set_int(newconfs[OPT_STRIP_VSS],
919 5 : get_int(cconfs[OPT_STRIP_VSS]));
920 : }
921 :
922 5 : if(get_int(newconfs[OPT_SPLIT_VSS])!=get_int(oldconfs[OPT_SPLIT_VSS]))
923 : {
924 0 : logp("split_vss=%d (changed since last backup)\n",
925 0 : get_int(newconfs[OPT_SPLIT_VSS]));
926 0 : ret=1; goto end;
927 : }
928 5 : if(get_int(newconfs[OPT_STRIP_VSS])!=get_int(oldconfs[OPT_STRIP_VSS]))
929 : {
930 0 : logp("strip_vss=%d (changed since last backup)\n",
931 0 : get_int(newconfs[OPT_STRIP_VSS]));
932 0 : ret=1; goto end;
933 : }
934 : ret=0;
935 : end:
936 5 : if(ret==1) logp("All files will be treated as new\n");
937 5 : confs_free(&oldconfs);
938 5 : confs_free(&newconfs);
939 5 : return ret;
940 : }
941 :
942 : // Maybe open the previous (current) manifest.
943 : // If the split_vss setting changed between the previous backup and the new
944 : // backup, do not open the previous manifest. This will have the effect of
945 : // making the client back up everything fresh. Need to do this, otherwise
946 : // toggling split_vss on and off will result in backups that do not work.
947 5 : static int maybe_open_previous_manifest(struct manio **manio,
948 : struct sdirs *sdirs, const char *incexc, struct conf **cconfs)
949 : {
950 5 : if(vss_opts_changed(sdirs, cconfs, incexc))
951 : return 0;
952 5 : return open_previous_manifest(manio, sdirs);
953 : }
954 :
955 135 : static int process_next_file_from_manios(struct asfd *asfd,
956 : struct dpth *dpth,
957 : struct sdirs *sdirs,
958 : struct manio **p1manio,
959 : struct manio **cmanio,
960 : struct manio *ucmanio,
961 : struct manio **hmanio,
962 : struct sbuf **p1b,
963 : struct sbuf *cb,
964 : struct conf **cconfs)
965 : {
966 135 : if(!(*p1b=sbuf_alloc(PROTO_1)))
967 : goto error;
968 135 : switch(manio_read(*p1manio, *p1b))
969 : {
970 : case 0:
971 : break;
972 : case 1:
973 5 : manio_close(p1manio);
974 5 : if(asfd->write_str(asfd, CMD_GEN, "backupphase2end"))
975 : goto error;
976 5 : sbuf_free(p1b);
977 5 : break;
978 : case -1:
979 : goto error;
980 : }
981 :
982 135 : if(!*cmanio)
983 : {
984 124 : if(!*p1b) return 0;
985 : // No old manifest, need to ask for a new file.
986 120 : switch(process_new(cconfs, *p1b, ucmanio))
987 : {
988 : case P_NEW:
989 : return 0;
990 : case P_DONE_NEW:
991 : goto p1b_done;
992 : default:
993 : goto error;
994 : }
995 : }
996 :
997 : // Have an old manifest, look for it there.
998 :
999 : // Might already have it, or be ahead in the old
1000 : // manifest.
1001 11 : if(cb->path.buf)
1002 : {
1003 2 : switch(maybe_process_file(asfd, dpth,
1004 : sdirs, cb, *p1b, ucmanio, hmanio, cconfs))
1005 : {
1006 : case P_NEW:
1007 : return 0;
1008 : case P_CHANGED:
1009 : // Free cb content for things like encrypted
1010 : // files, which we only pretend are new.
1011 0 : sbuf_free_content(cb);
1012 0 : return 0;
1013 : case P_DONE_NEW:
1014 : goto p1b_done;
1015 : case P_DONE_CHANGED:
1016 : case P_DONE_UNCHANGED:
1017 0 : sbuf_free_content(cb);
1018 0 : goto p1b_done;
1019 : case P_DONE_DELETED:
1020 2 : sbuf_free_content(cb);
1021 2 : break;
1022 : case P_ERROR:
1023 : goto error;
1024 : }
1025 : }
1026 :
1027 : while(1)
1028 : {
1029 11 : sbuf_free_content(cb);
1030 11 : switch(manio_read(*cmanio, cb))
1031 : {
1032 : case 0: break;
1033 1 : case 1: manio_close(cmanio);
1034 1 : if(*p1b) switch(process_new(cconfs,
1035 : *p1b, ucmanio))
1036 : {
1037 : case P_NEW:
1038 : return 0;
1039 : case P_DONE_NEW:
1040 : goto p1b_done;
1041 : default:
1042 : goto error;
1043 : }
1044 : return 0;
1045 : case -1: goto error;
1046 : }
1047 10 : switch(maybe_process_file(asfd, dpth, sdirs,
1048 : cb, *p1b, ucmanio, hmanio, cconfs))
1049 : {
1050 : case P_NEW:
1051 : return 0;
1052 : case P_CHANGED:
1053 : // Free cb content for things like encrypted
1054 : // files, which we only pretend are new.
1055 2 : sbuf_free_content(cb);
1056 2 : return 0;
1057 : case P_DONE_NEW:
1058 : goto p1b_done;
1059 : case P_DONE_CHANGED:
1060 : case P_DONE_UNCHANGED:
1061 6 : sbuf_free_content(cb);
1062 6 : goto p1b_done;
1063 : case P_DONE_DELETED:
1064 0 : sbuf_free_content(cb);
1065 0 : continue;
1066 : case P_ERROR:
1067 : goto error;
1068 : }
1069 : }
1070 : error:
1071 : return -1;
1072 : p1b_done:
1073 74 : sbuf_free(p1b);
1074 74 : return 0;
1075 : }
1076 :
1077 10 : int backup_phase2_server_protocol1(struct async *as, struct sdirs *sdirs,
1078 : const char *incexc, int resume, struct conf **cconfs)
1079 : {
1080 10 : int ret=0;
1081 10 : man_off_t *p1pos=NULL;
1082 10 : struct manio *p1manio=NULL;
1083 10 : struct dpth *dpth=NULL;
1084 10 : char *deltmppath=NULL;
1085 10 : char *last_requested=NULL;
1086 10 : struct manio *chmanio=NULL; // changed data
1087 10 : struct manio *ucmanio=NULL; // unchanged data
1088 10 : struct manio *cmanio=NULL; // previous (current) manifest
1089 10 : struct manio *hmanio=NULL; // to look up deleted hardlinks
1090 10 : struct sbuf *cb=NULL; // file list in current manifest
1091 10 : struct sbuf *p1b=NULL; // file list from client
1092 10 : struct sbuf *rb=NULL; // receiving file from client
1093 10 : struct asfd *asfd=NULL;
1094 10 : int breaking=0;
1095 10 : int breakcount=0;
1096 10 : struct cntr *cntr=NULL;
1097 :
1098 10 : if(!as)
1099 : {
1100 1 : logp("async not provided to %s()\n", __func__);
1101 1 : goto error;
1102 : }
1103 9 : if(!sdirs)
1104 : {
1105 2 : logp("sdirs not provided to %s()\n", __func__);
1106 2 : goto error;
1107 : }
1108 7 : if(!cconfs)
1109 : {
1110 1 : logp("cconfs not provided to %s()\n", __func__);
1111 1 : goto error;
1112 : }
1113 6 : asfd=as->asfd;
1114 6 : if(!asfd)
1115 : {
1116 1 : logp("asfd not provided to %s()\n", __func__);
1117 1 : goto error;
1118 : }
1119 5 : cntr=get_cntr(cconfs);
1120 :
1121 5 : if(get_int(cconfs[OPT_BREAKPOINT])>=2000
1122 0 : && get_int(cconfs[OPT_BREAKPOINT])<3000)
1123 : {
1124 0 : breaking=get_int(cconfs[OPT_BREAKPOINT]);
1125 0 : breakcount=breaking-2000;
1126 : }
1127 :
1128 5 : logp("Begin phase2 (receive file data)\n");
1129 :
1130 5 : if(!(dpth=dpth_alloc())
1131 5 : || dpth_protocol1_init(dpth, sdirs->currentdata,
1132 : get_int(cconfs[OPT_MAX_STORAGE_SUBDIRS])))
1133 : goto error;
1134 :
1135 5 : if(maybe_open_previous_manifest(&cmanio, sdirs, incexc, cconfs))
1136 : goto error;
1137 : // If the first file that others hardlink to has been deleted, we will
1138 : // need to look through the previous manifest to find the information
1139 : // for that original file, in order to not have to copy all the data
1140 : // across again.
1141 5 : if(open_previous_manifest(&hmanio, sdirs))
1142 : goto error;
1143 :
1144 5 : if(get_int(cconfs[OPT_DIRECTORY_TREE]))
1145 : {
1146 : // Need to make sure we do not try to create a path that is
1147 : // too long.
1148 5 : if(build_path_w(sdirs->treepath)) goto error;
1149 5 : mkdir(sdirs->treepath, 0777);
1150 5 : treepathlen=strlen(sdirs->treepath);
1151 5 : if(init_fs_max(sdirs->treepath))
1152 : goto error;
1153 : }
1154 :
1155 5 : if(resume)
1156 : {
1157 0 : if(!(p1pos=do_resume(sdirs, dpth, cconfs)))
1158 : goto error;
1159 0 : if(cntr_send_sdirs(asfd, sdirs, cconfs, CNTR_STATUS_BACKUP))
1160 : goto error;
1161 : }
1162 :
1163 5 : if(!(p1manio=manio_open_phase1(sdirs->phase1data, "rb", PROTO_1))
1164 5 : || (resume && manio_seek(p1manio, p1pos)))
1165 : goto error;
1166 5 : if(!(cb=sbuf_alloc(PROTO_1))
1167 5 : || !(p1b=sbuf_alloc(PROTO_1))
1168 5 : || !(rb=sbuf_alloc(PROTO_1)))
1169 : goto error;
1170 :
1171 : // Unchanged and changed should now be truncated correctly, we just
1172 : // have to open them for appending.
1173 : // Data is not getting written to a compressed file.
1174 : // This is important for recovery if the power goes.
1175 5 : if(!(ucmanio=manio_open_phase2(sdirs->unchanged, "ab", PROTO_1))
1176 5 : || !(chmanio=manio_open_phase2(sdirs->changed, "ab", PROTO_1)))
1177 : goto error;
1178 :
1179 : while(1)
1180 : {
1181 921 : if(breaking && breakcount--==0)
1182 0 : return breakpoint(breaking, __func__);
1183 :
1184 921 : if(write_status(CNTR_STATUS_BACKUP,
1185 921 : rb->path.buf?rb->path.buf:"", cntr))
1186 : goto error;
1187 1842 : if(last_requested
1188 921 : || !p1manio
1189 16 : || asfd->writebuflen)
1190 : {
1191 905 : iobuf_free_content(asfd->rbuf);
1192 905 : if(asfd->as->read_write(asfd->as))
1193 : {
1194 0 : logp("error in %s\n", __func__);
1195 0 : goto error;
1196 : }
1197 :
1198 905 : if(asfd->rbuf->buf)
1199 85 : switch(do_stuff_to_receive(asfd, sdirs,
1200 : cconfs, rb, chmanio, dpth, &last_requested))
1201 : {
1202 : case STR_OK:
1203 : break;
1204 : case STR_FINISHED:
1205 : goto end;
1206 : case STR_ERROR:
1207 : goto error;
1208 : }
1209 : }
1210 :
1211 916 : if(p1b) switch(do_stuff_to_send(asfd, p1b, &last_requested))
1212 : {
1213 : case STS_OK:
1214 61 : sbuf_free(&p1b);
1215 61 : break;
1216 : case STS_BLOCKED:
1217 2 : continue;
1218 : case STS_ERROR:
1219 : goto error;
1220 : }
1221 :
1222 914 : if(p1manio
1223 135 : && process_next_file_from_manios(asfd, dpth, sdirs,
1224 : &p1manio, &cmanio, ucmanio, &hmanio, &p1b, cb, cconfs))
1225 : goto error;
1226 : }
1227 :
1228 : error:
1229 : ret=-1;
1230 : end:
1231 10 : if(manio_close(&chmanio))
1232 : {
1233 0 : logp("error closing %s in %s\n", sdirs->changed, __func__);
1234 0 : ret=-1;
1235 : }
1236 10 : if(manio_close(&ucmanio))
1237 : {
1238 0 : logp("error closing %s in %s\n", sdirs->unchanged, __func__);
1239 0 : ret=-1;
1240 : }
1241 10 : free_w(&deltmppath);
1242 10 : free_w(&last_requested);
1243 10 : sbuf_free(&cb);
1244 10 : sbuf_free(&p1b);
1245 10 : sbuf_free(&rb);
1246 10 : manio_close(&p1manio);
1247 10 : manio_close(&cmanio);
1248 10 : manio_close(&hmanio);
1249 10 : dpth_free(&dpth);
1250 10 : man_off_t_free(&p1pos);
1251 10 : if(!ret && sdirs)
1252 5 : unlink(sdirs->phase1data);
1253 :
1254 10 : logp("End phase2 (receive file data)\n");
1255 :
1256 10 : return ret;
1257 : }
|