LCOV - code coverage report
Current view: top level - src/server - backup_phase3.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 60 70 85.7 %
Date: 2022-08-30 22:36:43 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../alloc.h"
       3             : #include "../cntr.h"
       4             : #include "../conf.h"
       5             : #include "../cstat.h"
       6             : #include "../fsops.h"
       7             : #include "../handy.h"
       8             : #include "../log.h"
       9             : #include "../sbuf.h"
      10             : #include "compress.h"
      11             : #include "manio.h"
      12             : #include "sdirs.h"
      13             : #include "child.h"
      14             : #include "backup_phase3.h"
      15             : 
      16             : // Combine the phase1 and phase2 files into a new manifest.
      17           2 : int backup_phase3_server_all(struct sdirs *sdirs, struct conf **confs)
      18             : {
      19           2 :         int ret=-1;
      20           2 :         int pcmp=0;
      21           2 :         struct sbuf *usb=NULL;
      22           2 :         struct sbuf *csb=NULL;
      23           2 :         char *manifesttmp=NULL;
      24           2 :         struct manio *newmanio=NULL;
      25           2 :         struct manio *chmanio=NULL;
      26           2 :         struct manio *unmanio=NULL;
      27           2 :         const char *rmanifest_relative=NULL;
      28           2 :         char *seed_src=get_string(confs[OPT_SEED_SRC]);
      29           2 :         char *seed_dst=get_string(confs[OPT_SEED_DST]);
      30             : 
      31           2 :         logp("Begin phase3 (merge manifests)\n");
      32             : 
      33           2 :         if(!(manifesttmp=get_tmp_filename(sdirs->manifest))
      34           2 :           || !(newmanio=manio_open_phase3(manifesttmp,
      35           2 :                 comp_level(get_int(confs[OPT_COMPRESSION])),
      36             :                 rmanifest_relative))
      37           2 :           || !(chmanio=manio_open_phase2(sdirs->changed, "rb"))
      38           2 :           || !(unmanio=manio_open_phase2(sdirs->unchanged, "rb"))
      39           2 :           || !(usb=sbuf_alloc())
      40           2 :           || !(csb=sbuf_alloc()))
      41             :                 goto end;
      42             : 
      43          12 :         while(chmanio || unmanio)
      44             :         {
      45          10 :                 if(unmanio
      46           9 :                   && !usb->path.buf)
      47             :                 {
      48           6 :                         switch(manio_read(unmanio, usb))
      49             :                         {
      50             :                                 case -1:
      51             :                                         goto end;
      52             :                                 case 1:
      53           2 :                                         manio_close(&unmanio);
      54           2 :                                         break;
      55             :                         }
      56             :                 }
      57             : 
      58          10 :                 if(chmanio
      59           9 :                   && !csb->path.buf)
      60             :                 {
      61           6 :                         switch(manio_read(chmanio, csb))
      62             :                         {
      63             :                                 case -1:
      64             :                                         goto end;
      65             :                                 case 1:
      66           2 :                                         manio_close(&chmanio);
      67           2 :                                         break;
      68             :                         }
      69             :                 }
      70             : 
      71          10 :                 if(usb->path.buf && !csb->path.buf)
      72             :                 {
      73           1 :                         if(timed_operation_status_only(CNTR_STATUS_MERGING,
      74             :                                 usb->path.buf, confs)) goto end;
      75           1 :                         switch(manio_copy_entry(usb, usb, unmanio, newmanio,
      76             :                                 seed_src, seed_dst))
      77             :                         {
      78             :                                 case -1: goto end;
      79           0 :                                 case 1: manio_close(&unmanio);
      80             :                         }
      81             :                 }
      82           9 :                 else if(!usb->path.buf && csb->path.buf)
      83             :                 {
      84           1 :                         if(timed_operation_status_only(CNTR_STATUS_MERGING,
      85             :                                 csb->path.buf, confs)) goto end;
      86           1 :                         switch(manio_copy_entry(csb, csb, chmanio, newmanio,
      87             :                                 seed_src, seed_dst))
      88             :                         {
      89             :                                 case -1: goto end;
      90           0 :                                 case 1: manio_close(&chmanio);
      91             :                         }
      92             :                 }
      93           8 :                 else if(!usb->path.buf && !csb->path.buf)
      94             :                 {
      95           2 :                         continue;
      96             :                 }
      97           6 :                 else if(!(pcmp=sbuf_pathcmp(usb, csb)))
      98             :                 {
      99             :                         // They were the same - write one.
     100           0 :                         if(timed_operation_status_only(CNTR_STATUS_MERGING,
     101           0 :                                 csb->path.buf, confs)) goto end;
     102           0 :                         switch(manio_copy_entry(csb, csb, chmanio, newmanio,
     103             :                                 seed_src, seed_dst))
     104             :                         {
     105             :                                 case -1: goto end;
     106           0 :                                 case 1: manio_close(&chmanio);
     107             :                         }
     108             :                 }
     109           6 :                 else if(pcmp<0)
     110             :                 {
     111           3 :                         if(timed_operation_status_only(CNTR_STATUS_MERGING,
     112           3 :                                 usb->path.buf, confs)) goto end;
     113           3 :                         switch(manio_copy_entry(usb, usb, unmanio, newmanio,
     114             :                                 seed_src, seed_dst))
     115             :                         {
     116             :                                 case -1: goto end;
     117           0 :                                 case 1: manio_close(&unmanio);
     118             :                         }
     119             :                 }
     120             :                 else
     121             :                 {
     122           3 :                         if(timed_operation_status_only(CNTR_STATUS_MERGING,
     123           3 :                                 csb->path.buf, confs)) goto end;
     124           3 :                         switch(manio_copy_entry(csb, csb, chmanio, newmanio,
     125             :                                 seed_src, seed_dst))
     126             :                         {
     127             :                                 case -1: goto end;
     128           0 :                                 case 1: manio_close(&chmanio);
     129             :                         }
     130             :                 }
     131             :         }
     132             : 
     133             :         // Flush to disk.
     134           2 :         if(manio_close(&newmanio))
     135             :         {
     136           0 :                 logp("error gzclosing %s in backup_phase3_server\n",
     137             :                         manifesttmp);
     138           0 :                 goto end;
     139             :         }
     140             : 
     141             :         // Rename race condition should be of no consequence here, as the
     142             :         // manifest should just get recreated automatically.
     143           2 :         if(do_rename(manifesttmp, sdirs->manifest))
     144             :                 goto end;
     145             :         else
     146             :         {
     147           2 :                 recursive_delete(sdirs->changed);
     148           2 :                 recursive_delete(sdirs->unchanged);
     149             :         }
     150             : 
     151           2 :         logp("End phase3 (merge manifests)\n");
     152           2 :         ret=0;
     153             : end:
     154           2 :         manio_close(&newmanio);
     155           2 :         manio_close(&chmanio);
     156           2 :         manio_close(&unmanio);
     157           2 :         sbuf_free(&csb);
     158           2 :         sbuf_free(&usb);
     159           2 :         free_w(&manifesttmp);
     160           2 :         return ret;
     161             : }

Generated by: LCOV version 1.13