LCOV - code coverage report
Current view: top level - src/server - backup_phase1.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 25 41 61.0 %
Date: 2018-12-11 11:12:16 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../alloc.h"
       3             : #include "../asfd.h"
       4             : #include "../async.h"
       5             : #include "../cmd.h"
       6             : #include "../cntr.h"
       7             : #include "../cstat.h"
       8             : #include "../fsops.h"
       9             : #include "../handy.h"
      10             : #include "../log.h"
      11             : #include "../msg.h"
      12             : #include "../sbuf.h"
      13             : #include "child.h"
      14             : #include "compress.h"
      15             : #include "manio.h"
      16             : #include "quota.h"
      17             : #include "sdirs.h"
      18             : #include "backup_phase1.h"
      19             : 
      20           1 : int backup_phase1_server_all(struct async *as,
      21             :         struct sdirs *sdirs, struct conf **confs)
      22             : {
      23           1 :         int ret=-1;
      24           1 :         struct sbuf *sb=NULL;
      25           1 :         char *phase1tmp=NULL;
      26           1 :         struct asfd *asfd=as->asfd;
      27           1 :         struct manio *manio=NULL;
      28           1 :         enum protocol protocol=get_protocol(confs);
      29             :         struct cntr *cntr;
      30           1 :         int fail_on_warning=0;
      31           1 :         struct cntr_ent *warn_ent=NULL;
      32             : 
      33           1 :         cntr=get_cntr(confs);
      34           1 :         fail_on_warning=get_int(confs[OPT_FAIL_ON_WARNING]);
      35           1 :         if(cntr)
      36           1 :                 warn_ent=cntr->ent[CMD_WARNING];
      37             : 
      38           1 :         logp("Begin phase1 (file system scan)\n");
      39             : 
      40           1 :         if(!(phase1tmp=get_tmp_filename(sdirs->phase1data))
      41           1 :           || !(manio=manio_open_phase1(phase1tmp,
      42           1 :                 comp_level(get_int(confs[OPT_COMPRESSION])), protocol))
      43           1 :           || !(sb=sbuf_alloc(protocol)))
      44             :                 goto error;
      45             : 
      46             :         while(1)
      47             :         {
      48           1 :                 sbuf_free_content(sb);
      49             : 
      50           1 :                 if(check_fail_on_warning(fail_on_warning, warn_ent))
      51             :                         goto error;
      52             : 
      53           1 :                 switch(sbuf_fill_from_net(sb, asfd, NULL, cntr))
      54             :                 {
      55             :                         case 0: break;
      56             :                         case 1: // Last thing the client sends is
      57             :                                 // 'backupphase2', and it wants an 'ok' reply.
      58           0 :                                 if(asfd->write_str(asfd, CMD_GEN, "ok")
      59           0 :                                   || send_msg_fzp(manio->fzp, CMD_GEN,
      60             :                                         "phase1end", strlen("phase1end")))
      61             :                                                 goto error;
      62             :                                 goto end;
      63             :                         case -1:
      64             :                         default: goto error;
      65             :                 }
      66           0 :                 if(write_status(CNTR_STATUS_SCANNING, sb->path.buf, cntr)
      67           0 :                   || manio_write_sbuf(manio, sb))
      68             :                         goto error;
      69           0 :                 cntr_add_phase1(cntr, sb->path.cmd, 0);
      70             : 
      71           0 :                 if(sbuf_is_estimatable(sb))
      72             :                 {
      73           0 :                         cntr_add_val(cntr, CMD_BYTES_ESTIMATED,
      74           0 :                                 (uint64_t)sb->statp.st_size);
      75             :                 }
      76             :         }
      77             : 
      78             : end:
      79           0 :         if(check_fail_on_warning(fail_on_warning, warn_ent))
      80             :                 goto error;
      81             : 
      82           0 :         if(manio_close(&manio))
      83             :         {
      84           0 :                 logp("error closing %s in backup_phase1_server\n", phase1tmp);
      85           0 :                 goto error;
      86             :         }
      87             : 
      88           0 :         if(check_quota(as, cntr,
      89             :                 get_uint64_t(confs[OPT_HARD_QUOTA]),
      90             :                 get_uint64_t(confs[OPT_SOFT_QUOTA])))
      91             :                         goto error;
      92             : 
      93             :         // Possible rename race condition is of no consequence here, because
      94             :         // the working directory will always get deleted if phase1 is not
      95             :         // complete.
      96           0 :         if(do_rename(phase1tmp, sdirs->phase1data))
      97             :                 goto error;
      98             : 
      99             :         //cntr_print(p1cntr, cntr, ACTION_BACKUP);
     100             : 
     101           0 :         logp("End phase1 (file system scan)\n");
     102           0 :         ret=0;
     103             : error:
     104           1 :         free_w(&phase1tmp);
     105           1 :         manio_close(&manio);
     106           1 :         sbuf_free(&sb);
     107           1 :         return ret;
     108             : }

Generated by: LCOV version 1.13