LCOV - code coverage report
Current view: top level - src/server - backup_phase1.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 19 34 55.9 %
Date: 2018-03-30 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           1 :         struct cntr *cntr=get_cntr(confs);
      30             : 
      31           1 :         logp("Begin phase1 (file system scan)\n");
      32             : 
      33           1 :         if(!(phase1tmp=get_tmp_filename(sdirs->phase1data))
      34           1 :           || !(manio=manio_open_phase1(phase1tmp,
      35           1 :                 comp_level(get_int(confs[OPT_COMPRESSION])), protocol))
      36           1 :           || !(sb=sbuf_alloc(protocol)))
      37             :                 goto error;
      38             : 
      39             :         while(1)
      40             :         {
      41           1 :                 sbuf_free_content(sb);
      42           1 :                 switch(sbuf_fill_from_net(sb, asfd, NULL, cntr))
      43             :                 {
      44             :                         case 0: break;
      45             :                         case 1: // Last thing the client sends is
      46             :                                 // 'backupphase2', and it wants an 'ok' reply.
      47           0 :                                 if(asfd->write_str(asfd, CMD_GEN, "ok")
      48           0 :                                   || send_msg_fzp(manio->fzp, CMD_GEN,
      49             :                                         "phase1end", strlen("phase1end")))
      50             :                                                 goto error;
      51             :                                 goto end;
      52             :                         case -1:
      53             :                         default: goto error;
      54             :                 }
      55           0 :                 if(write_status(CNTR_STATUS_SCANNING, sb->path.buf, cntr)
      56           0 :                   || manio_write_sbuf(manio, sb))
      57             :                         goto error;
      58           0 :                 cntr_add_phase1(cntr, sb->path.cmd, 0);
      59             : 
      60           0 :                 if(sbuf_is_estimatable(sb))
      61             :                 {
      62           0 :                         cntr_add_val(cntr, CMD_BYTES_ESTIMATED,
      63           0 :                                 (uint64_t)sb->statp.st_size);
      64             :                 }
      65             :         }
      66             : 
      67             : end:
      68           0 :         if(manio_close(&manio))
      69             :         {
      70           0 :                 logp("error closing %s in backup_phase1_server\n", phase1tmp);
      71           0 :                 goto error;
      72             :         }
      73             : 
      74           0 :         if(check_quota(as, cntr,
      75             :                 get_uint64_t(confs[OPT_HARD_QUOTA]),
      76             :                 get_uint64_t(confs[OPT_SOFT_QUOTA])))
      77             :                         goto error;
      78             : 
      79             :         // Possible rename race condition is of no consequence here, because
      80             :         // the working directory will always get deleted if phase1 is not
      81             :         // complete.
      82           0 :         if(do_rename(phase1tmp, sdirs->phase1data))
      83             :                 goto error;
      84             : 
      85             :         //cntr_print(p1cntr, cntr, ACTION_BACKUP);
      86             : 
      87           0 :         logp("End phase1 (file system scan)\n");
      88           0 :         ret=0;
      89             : error:
      90           1 :         free_w(&phase1tmp);
      91           1 :         manio_close(&manio);
      92           1 :         sbuf_free(&sb);
      93           1 :         return ret;
      94             : }

Generated by: LCOV version 1.10