LCOV - code coverage report
Current view: top level - src - repo.c (source / functions) Hit Total Coverage
Test: plop Lines: 26 49 53.1 %
Date: 2024-12-28 18:40:32 Functions: 1 2 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 18 55.6 %

           Branch data     Line data    Source code
       1                 :            : /*-
       2                 :            :  * Copyright (c) 2011-2024 Baptiste Daroussin <bapt@FreeBSD.org>
       3                 :            :  * 
       4                 :            :  * Redistribution and use in source and binary forms, with or without
       5                 :            :  * modification, are permitted provided that the following conditions
       6                 :            :  * are met:
       7                 :            :  * 1. Redistributions of source code must retain the above copyright
       8                 :            :  *    notice, this list of conditions and the following disclaimer
       9                 :            :  *    in this position and unchanged.
      10                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      11                 :            :  *    notice, this list of conditions and the following disclaimer in the
      12                 :            :  *    documentation and/or other materials provided with the distribution.
      13                 :            :  * 
      14                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      15                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      16                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      17                 :            :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      18                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      19                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      20                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      21                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      22                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      23                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      24                 :            :  */
      25                 :            : 
      26                 :            : #ifdef HAVE_CONFIG_H
      27                 :            : #include "pkg_config.h"
      28                 :            : #endif
      29                 :            : 
      30                 :            : #include <bsd_compat.h>
      31                 :            : #include <getopt.h>
      32                 :            : #include <signal.h>
      33                 :            : #include <stdio.h>
      34                 :            : #include <string.h>
      35                 :            : 
      36                 :            : #ifdef HAVE_READPASSPHRASE_H
      37                 :            : #include <readpassphrase.h>
      38                 :            : #elif defined(HAVE_BSD_READPASSPHRASE_H)
      39                 :            : #include <bsd/readpassphrase.h>
      40                 :            : #else
      41                 :            : #include "readpassphrase_compat.h"
      42                 :            : #endif
      43                 :            : 
      44                 :            : #include <unistd.h>
      45                 :            : 
      46                 :            : #include <pkg.h>
      47                 :            : #include "pkgcli.h"
      48                 :            : 
      49                 :            : void
      50                 :          0 : usage_repo(void)
      51                 :            : {
      52                 :          0 :         fprintf(stderr, "Usage: pkg repo [-hlqs] [-m metafile] [-o output-dir] <repo-path> "
      53                 :            :             "[rsa:<rsa-key>|signing_command: <the command>]\n\n");
      54                 :          0 :         fprintf(stderr, "For more information see 'pkg help repo'.\n");
      55                 :          0 : }
      56                 :            : 
      57                 :            : int
      58                 :         75 : exec_repo(int argc, char **argv)
      59                 :            : {
      60                 :            :         int      ch;
      61                 :         75 :         bool     hash = false;
      62                 :         75 :         bool     hash_symlink = false;
      63                 :         75 :         struct pkg_repo_create *prc = pkg_repo_create_new();
      64                 :            : 
      65                 :         75 :         hash = (getenv("PKG_REPO_HASH") != NULL);
      66                 :         75 :         hash_symlink = (getenv("PKG_REPO_SYMLINK") != NULL);
      67                 :            : 
      68                 :         75 :         struct option longopts[] = {
      69                 :            :                 { "groups",   required_argument,      NULL,   'g' },
      70                 :            :                 { "hash",     no_argument,            NULL,   'h' },
      71                 :            :                 { "list-files", no_argument,          NULL,   'l' },
      72                 :            :                 { "meta-file",        required_argument,      NULL,   'm' },
      73                 :            :                 { "output-dir", required_argument,    NULL,   'o' },
      74                 :            :                 { "quiet",    no_argument,            NULL,   'q' },
      75                 :            :                 { "symlink",  no_argument,            NULL,   's' },
      76                 :            :                 { NULL,         0,                      NULL,   0   },
      77                 :            :         };
      78                 :            : 
      79         [ +  + ]:         85 :         while ((ch = getopt_long(argc, argv, "+hg:lo:qm:s", longopts, NULL)) != -1) {
      80   [ -  +  +  -  :         10 :                 switch (ch) {
             +  -  -  - ]
      81                 :            :                 case 'g':
      82                 :          0 :                         pkg_repo_create_set_groups(prc, optarg);
      83                 :          0 :                         break;
      84                 :            :                 case 'h':
      85                 :          0 :                         hash = true;
      86                 :          0 :                         break;
      87                 :            :                 case 'l':
      88                 :          1 :                         pkg_repo_create_set_create_filelist(prc, true);
      89                 :          1 :                         break;
      90                 :            :                 case 'o':
      91                 :          7 :                         pkg_repo_create_set_output_dir(prc, optarg);
      92                 :          7 :                         break;
      93                 :            :                 case 'q':
      94                 :          0 :                         quiet = true;
      95                 :          0 :                         break;
      96                 :            :                 case 'm':
      97                 :          2 :                         pkg_repo_create_set_metafile(prc, optarg);
      98                 :          2 :                         break;
      99                 :            :                 case 's':
     100                 :          0 :                         hash_symlink = true;
     101                 :          0 :                         break;
     102                 :            :                 default:
     103                 :          0 :                         usage_repo();
     104                 :          0 :                         return (EXIT_FAILURE);
     105                 :            :                 }
     106                 :            :         }
     107                 :         75 :         argc -= optind;
     108                 :         75 :         argv += optind;
     109                 :            : 
     110                 :         75 :         pkg_repo_create_set_hash(prc, hash);
     111                 :         75 :         pkg_repo_create_set_hash_symlink(prc, hash_symlink);
     112                 :         75 :         pkg_repo_create_set_sign(prc, argv + 1, argc - 1, password_cb);
     113                 :            : 
     114         [ +  - ]:         75 :         if (argc < 1) {
     115                 :          0 :                 pkg_repo_create_free(prc);
     116                 :          0 :                 usage_repo();
     117                 :          0 :                 return (EXIT_FAILURE);
     118                 :            :         }
     119                 :            : 
     120   [ +  +  +  - ]:         75 :         if (argc > 2 && !STREQ(argv[1], "signing_command:")) {
     121                 :          0 :                 pkg_repo_create_free(prc);
     122                 :          0 :                 usage_repo();
     123                 :          0 :                 return (EXIT_FAILURE);
     124                 :            :         }
     125                 :            : 
     126         [ -  + ]:         75 :         if (pkg_repo_create(prc, argv[0]) != EPKG_OK) {
     127                 :          0 :                 printf("Cannot create repository catalogue\n");
     128                 :          0 :                 pkg_repo_create_free(prc);
     129                 :          0 :                 return (EXIT_FAILURE);
     130                 :            :         }
     131                 :            : 
     132                 :         75 :         pkg_repo_create_free(prc);
     133                 :         75 :         return (EXIT_SUCCESS);
     134                 :         75 : }

Generated by: LCOV version 1.15