Branch data Line data Source code
1 : : /*-
2 : : * Copyright (c) 2016 Brad Davis <brd@FreeBSD.org>
3 : : * All rights reserved.
4 : : *
5 : : * Redistribution and use in source and binary forms, with or without
6 : : * modification, are permitted provided that the following conditions
7 : : * are met:
8 : : * 1. Redistributions of source code must retain the above copyright
9 : : * notice, this list of conditions and the following disclaimer
10 : : * in this position and unchanged.
11 : : * 2. Redistributions in binary form must reproduce the above copyright
12 : : * notice, this list of conditions and the following disclaimer in the
13 : : * documentation and/or other materials provided with the distribution.
14 : : *
15 : : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 : : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 : : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 : : * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 : : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 : : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 : : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 : : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 : : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 : : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 : : */
26 : :
27 : :
28 : :
29 : : #include <errno.h>
30 : : #include "pkg.h"
31 : : #include "private/pkg.h"
32 : : #include "private/event.h"
33 : :
34 : : FILE *metalogfp = NULL;
35 : :
36 : : int
37 : 3 : metalog_open(const char *metalog)
38 : : {
39 : 3 : metalogfp = fopen(metalog, "ae");
40 [ + + ]: 3 : if (metalogfp == NULL) {
41 : 1 : pkg_fatal_errno("Unable to open metalog '%s'", metalog);
42 : 0 : }
43 : :
44 : 2 : return EPKG_OK;
45 : 3 : }
46 : :
47 : : int
48 : 141 : metalog_add(int type, const char *path, const char *uname, const char *gname,
49 : : int mode, unsigned long fflags, const char *link)
50 : : {
51 : 141 : char *fflags_buffer = NULL;
52 : 141 : int ret = EPKG_FATAL;
53 : :
54 [ + + ]: 141 : if (metalogfp == NULL)
55 : 132 : goto out;
56 : :
57 : : #ifdef HAVE_FFLAGSTOSTR
58 [ + + ]: 9 : if (fflags) {
59 : 2 : fflags_buffer = fflagstostr(fflags);
60 : 2 : }
61 : : #endif
62 : :
63 : : // directory
64 [ - + + + ]: 9 : switch (type) {
65 : : case PKG_METALOG_DIR:
66 [ + - + - ]: 9 : if (fprintf(metalogfp,
67 : : "./%s type=dir uname=%s gname=%s mode=%3o%s%s\n",
68 : 3 : path, uname, gname, mode,
69 : 3 : fflags ? " flags=" : "",
70 [ + + ]: 3 : fflags_buffer ? fflags_buffer : "") < 0) {
71 : 0 : pkg_errno("%s", "Unable to write to the metalog");
72 : 0 : goto out;
73 : : }
74 : 3 : break;
75 : : case PKG_METALOG_FILE:
76 [ + - + - ]: 12 : if (fprintf(metalogfp,
77 : : "./%s type=file uname=%s gname=%s mode=%3o%s%s\n",
78 : 4 : path, uname, gname, mode,
79 : 4 : fflags ? " flags=" : "",
80 [ + + ]: 4 : fflags_buffer ? fflags_buffer : "") < 0) {
81 : 0 : pkg_errno("%s", "Unable to write to the metalog");
82 : 0 : goto out;
83 : : }
84 : 4 : break;
85 : : case PKG_METALOG_LINK:
86 [ + - + - ]: 6 : if (fprintf(metalogfp,
87 : : "./%s type=link uname=%s gname=%s mode=%3o link=%s%s%s\n",
88 : 2 : path, uname, gname, mode, link,
89 : 2 : fflags ? " flags=" : "",
90 [ - + ]: 2 : fflags_buffer ? fflags_buffer : "") < 0) {
91 : 0 : pkg_errno("%s", "Unable to write to the metalog");
92 : 0 : goto out;
93 : : }
94 : 2 : break;
95 : : }
96 : 9 : ret = EPKG_OK;
97 : :
98 : : out:
99 : 141 : free(fflags_buffer);
100 : 141 : return (ret);
101 : : }
102 : :
103 : : void
104 : 922 : metalog_close()
105 : : {
106 [ + + ]: 922 : if (metalogfp != NULL) {
107 : 2 : fclose(metalogfp);
108 : 2 : }
109 : 922 : }
|