LCOV - code coverage report
Current view: top level - src - backup.c (source / functions) Hit Total Coverage
Test: rapport Lines: 0 43 0.0 %
Date: 2021-12-10 16:22:55 Functions: 0 2 0.0 %
Branches: 0 22 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*-
       2                 :            :  * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
       3                 :            :  * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
       4                 :            :  * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org>
       5                 :            :  * All rights reserved.
       6                 :            :  * 
       7                 :            :  * Redistribution and use in source and binary forms, with or without
       8                 :            :  * modification, are permitted provided that the following conditions
       9                 :            :  * are met:
      10                 :            :  * 1. Redistributions of source code must retain the above copyright
      11                 :            :  *    notice, this list of conditions and the following disclaimer
      12                 :            :  *    in this position and unchanged.
      13                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      14                 :            :  *    notice, this list of conditions and the following disclaimer in the
      15                 :            :  *    documentation and/or other materials provided with the distribution.
      16                 :            :  * 
      17                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      18                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      19                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      20                 :            :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      21                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      22                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      26                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <pkg.h>
      30                 :            : #include <getopt.h>
      31                 :            : #include <unistd.h>
      32                 :            : 
      33                 :            : #include "pkgcli.h"
      34                 :            : 
      35                 :            : void
      36                 :          0 : usage_backup(void)
      37                 :            : {
      38                 :          0 :         fprintf(stderr, "Usage: pkg backup [-q] -d <dest_file>\n");
      39                 :          0 :         fprintf(stderr, "       pkg backup [-q] -r <src_file>\n\n");
      40                 :          0 :         fprintf(stderr, "For more information see 'pkg help backup'.\n");
      41                 :          0 : }
      42                 :            : 
      43                 :            : int
      44                 :          0 : exec_backup(int argc, char **argv)
      45                 :            : {
      46                 :          0 :         struct pkgdb    *db = NULL;
      47                 :          0 :         char            *backup_file = NULL;
      48                 :          0 :         bool             dump = false;
      49                 :          0 :         bool             restore = false;
      50                 :            :         int              ch;
      51                 :            : 
      52                 :          0 :         struct option longopts[] = {
      53                 :            :                 { "dump",     required_argument,      NULL,   'd' },
      54                 :            :                 { "quiet",    no_argument,            NULL,   'q' },
      55                 :            :                 { "restore",  required_argument,      NULL,   'r' },
      56                 :            :                 { NULL,         0,                      NULL,   0   },
      57                 :            :         };
      58                 :            : 
      59         [ #  # ]:          0 :         while ((ch = getopt_long(argc, argv, "+d:qr:", longopts, NULL)) != -1) {
      60   [ #  #  #  # ]:          0 :                 switch (ch) {
      61                 :            :                 case 'd':
      62                 :          0 :                         dump = true;
      63                 :          0 :                         backup_file = optarg;
      64                 :          0 :                         break;
      65                 :            :                 case 'q':
      66                 :          0 :                         quiet = true;
      67                 :          0 :                         break;
      68                 :            :                 case 'r':
      69                 :          0 :                         restore = true;
      70                 :          0 :                         backup_file = optarg;
      71                 :          0 :                         break;
      72                 :            :                 default:
      73                 :          0 :                         usage_backup();
      74                 :          0 :                         return (EXIT_FAILURE);
      75                 :            :                 }
      76                 :            :         }
      77                 :            : 
      78         [ #  # ]:          0 :         if ( dump == restore ) {
      79                 :          0 :                 usage_backup();
      80                 :          0 :                 return (EXIT_FAILURE);
      81                 :            :         }
      82                 :            : 
      83         [ #  # ]:          0 :         if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
      84                 :          0 :                 return (EXIT_FAILURE);
      85                 :            : 
      86         [ #  # ]:          0 :         if (dump) {
      87         [ #  # ]:          0 :                 if (!quiet)
      88                 :          0 :                         printf("Dumping database:\n");
      89         [ #  # ]:          0 :                 if (pkgdb_dump(db, backup_file) == EPKG_FATAL)
      90                 :          0 :                         return (EXIT_FAILURE);
      91                 :          0 :         }
      92                 :            : 
      93         [ #  # ]:          0 :         if (restore) {
      94         [ #  # ]:          0 :                 if (!quiet)
      95                 :          0 :                         printf("Restoring database:\n");
      96         [ #  # ]:          0 :                 if (pkgdb_load(db, backup_file) == EPKG_FATAL)
      97                 :          0 :                         return (EXIT_FAILURE);
      98                 :          0 :         }
      99                 :            : 
     100                 :          0 :         pkgdb_close(db);
     101                 :            : 
     102                 :          0 :         return (EXIT_SUCCESS);
     103                 :          0 : }

Generated by: LCOV version 1.15