LCOV - code coverage report
Current view: top level - libpkg - pkg_old.c (source / functions) Hit Total Coverage
Test: cov.info Lines: 0 40 0.0 %
Date: 2015-08-15 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*-
       2             :  * Copyright (c) 2012-2013 Baptiste Daroussin <bapt@FreeBSD.org>
       3             :  * Copyright (c) 2013 Bryan Drewery <bdrewery@FreeBSD.org>
       4             :  * All rights reserved.
       5             :  * 
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions
       8             :  * are met:
       9             :  * 1. Redistributions of source code must retain the above copyright
      10             :  *    notice, this list of conditions and the following disclaimer
      11             :  *    in this position and unchanged.
      12             :  * 2. Redistributions in binary form must reproduce the above copyright
      13             :  *    notice, this list of conditions and the following disclaimer in the
      14             :  *    documentation and/or other materials provided with the distribution.
      15             :  * 
      16             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      17             :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      18             :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      19             :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      20             :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      21             :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      22             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      23             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      24             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      25             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      26             :  */
      27             : 
      28             : #include <regex.h>
      29             : 
      30             : #include <pkg.h>
      31             : #include <private/pkg.h>
      32             : 
      33             : static const char * const scripts[] = {
      34             :         "+INSTALL",
      35             :         "+PRE_INSTALL",
      36             :         "+POST_INSTALL",
      37             :         "+POST_INSTALL",
      38             :         "+DEINSTALL",
      39             :         "+PRE_DEINSTALL",
      40             :         "+POST_DEINSTALL",
      41             :         "+UPGRADE",
      42             :         "+PRE_UPGRADE",
      43             :         "+POST_UPGRADE",
      44             :         "pkg-install",
      45             :         "pkg-pre-install",
      46             :         "pkg-post-install",
      47             :         "pkg-deinstall",
      48             :         "pkg-pre-deinstall",
      49             :         "pkg-post-deinstall",
      50             :         "pkg-upgrade",
      51             :         "pkg-pre-upgrade",
      52             :         "pkg-post-upgrade",
      53             :         NULL
      54             : };
      55             : 
      56             : int
      57           0 : pkg_old_load_from_path(struct pkg *pkg, const char *path)
      58             : {
      59             :         char fpath[MAXPATHLEN];
      60             :         regex_t preg;
      61             :         regmatch_t pmatch[2];
      62             :         int i;
      63             :         size_t size;
      64             :         char myarch[BUFSIZ];
      65             : 
      66           0 :         if (!is_dir(path))
      67           0 :                 return (EPKG_FATAL);
      68             : 
      69           0 :         snprintf(fpath, sizeof(fpath), "%s/+CONTENTS", path);
      70           0 :         if (ports_parse_plist(pkg, fpath, NULL) != EPKG_OK)
      71           0 :                 return (EPKG_FATAL);
      72             : 
      73           0 :         snprintf(fpath, sizeof(fpath), "%s/+COMMENT", path);
      74           0 :         if (access(fpath, F_OK) == 0)
      75           0 :                 pkg_set_from_file(pkg, PKG_COMMENT, fpath, true);
      76             : 
      77           0 :         snprintf(fpath, sizeof(fpath), "%s/+DESC", path);
      78           0 :         if (access(fpath, F_OK) == 0)
      79           0 :                 pkg_set_from_file(pkg, PKG_DESC, fpath, false);
      80             : 
      81           0 :         snprintf(fpath, sizeof(fpath), "%s/+DISPLAY", path);
      82           0 :         if (access(fpath, F_OK) == 0)
      83           0 :                 pkg_set_from_file(pkg, PKG_MESSAGE, fpath, false);
      84             : 
      85           0 :         snprintf(fpath, sizeof(fpath), "%s/+MTREE_DIRS", path);
      86           0 :         if (access(fpath, F_OK) == 0)
      87           0 :                 pkg_set_from_file(pkg, PKG_MTREE, fpath, false);
      88             : 
      89           0 :         for (i = 0; scripts[i] != NULL; i++) {
      90           0 :                 snprintf(fpath, sizeof(fpath), "%s/%s", path, scripts[i]);
      91           0 :                 if (access(fpath, F_OK) == 0)
      92           0 :                         pkg_addscript_file(pkg, fpath);
      93             :         }
      94             : 
      95           0 :         pkg_get_myarch(myarch, BUFSIZ);
      96           0 :         pkg->arch = strdup(myarch);
      97           0 :         pkg->maintainer = strdup("unknown");
      98           0 :         regcomp(&preg, "^WWW:[[:space:]]*(.*)$", REG_EXTENDED|REG_ICASE|REG_NEWLINE);
      99           0 :         if (regexec(&preg, pkg->desc, 2, pmatch, 0) == 0) {
     100           0 :                 size = pmatch[1].rm_eo - pmatch[1].rm_so;
     101           0 :                 pkg->www = strndup(&pkg->desc[pmatch[1].rm_so], size);
     102             :         } else {
     103           0 :                 pkg->www = strdup("UNKNOWN");
     104             :         }
     105           0 :         regfree(&preg);
     106             : 
     107           0 :         return (EPKG_OK);
     108             : }
     109             : 
     110             : int
     111           0 : pkg_from_old(struct pkg *p)
     112             : {
     113           0 :         struct pkg_file *f = NULL;
     114             : 
     115           0 :         p->type = PKG_INSTALLED;
     116           0 :         while (pkg_files(p, &f) == EPKG_OK) {
     117           0 :                 if (f->sum == NULL)
     118           0 :                         continue;
     119           0 :                 f->sum = pkg_checksum_generate_file(f->path, PKG_HASH_TYPE_SHA256_HEX);
     120             :         }
     121             : 
     122           0 :         return (EPKG_OK);
     123             : }

Generated by: LCOV version 1.10