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: 2020-08-31 23:02:24 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(timed_operation(CNTR_STATUS_SCANNING, sb->path.buf,
      67             :                         asfd, sdirs, confs)
      68           0 :                   || manio_write_sbuf(manio, sb))
      69             :                         goto error;
      70           0 :                 cntr_add_phase1(cntr, sb->path.cmd, 0);
      71             : 
      72           0 :                 if(sbuf_is_estimatable(sb))
      73             :                 {
      74           0 :                         cntr_add_val(cntr, CMD_BYTES_ESTIMATED,
      75           0 :                                 (uint64_t)sb->statp.st_size);
      76             :                 }
      77             :         }
      78             : 
      79             : end:
      80           0 :         if(check_fail_on_warning(fail_on_warning, warn_ent))
      81             :                 goto error;
      82             : 
      83           0 :         if(manio_close(&manio))
      84             :         {
      85           0 :                 logp("error closing %s in backup_phase1_server\n", phase1tmp);
      86           0 :                 goto error;
      87             :         }
      88             : 
      89           0 :         if(check_quota(as, cntr,
      90             :                 get_uint64_t(confs[OPT_HARD_QUOTA]),
      91             :                 get_uint64_t(confs[OPT_SOFT_QUOTA])))
      92             :                         goto error;
      93             : 
      94             :         // Possible rename race condition is of no consequence here, because
      95             :         // the working directory will always get deleted if phase1 is not
      96             :         // complete.
      97           0 :         if(do_rename(phase1tmp, sdirs->phase1data))
      98             :                 goto error;
      99             : 
     100           0 :         logp("End phase1 (file system scan)\n");
     101           0 :         ret=0;
     102             : error:
     103           1 :         free_w(&phase1tmp);
     104           1 :         manio_close(&manio);
     105           1 :         sbuf_free(&sb);
     106           1 :         return ret;
     107             : }

Generated by: LCOV version 1.13