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 : 4 : metalog_open(const char *metalog)
38 : : {
39 : 4 : metalogfp = fopen(metalog, "ae");
40 [ - + ]: 4 : if (metalogfp == NULL) {
41 : 0 : pkg_fatal_errno("Unable to open metalog '%s'", metalog);
42 : 0 : }
43 : :
44 : 4 : return EPKG_OK;
45 : 4 : }
46 : :
47 : : void
48 : 527 : metalog_add(int type, const char *path, const char *uname, const char *gname,
49 : : int mode, unsigned long fflags, const char *link)
50 : : {
51 : 527 : char *fflags_buffer = NULL;
52 : :
53 [ + + ]: 527 : if (metalogfp == NULL) {
54 : 503 : return;
55 : : }
56 : :
57 : : #ifdef HAVE_FFLAGSTOSTR
58 [ + - ]: 24 : if (fflags) {
59 : 0 : fflags_buffer = fflagstostr(fflags);
60 : 0 : }
61 : : #endif
62 : :
63 : : // directory
64 [ - + + + ]: 24 : switch (type) {
65 : : case PKG_METALOG_DIR:
66 [ + - + - ]: 24 : if (fprintf(metalogfp,
67 : : "./%s type=dir uname=%s gname=%s mode=%3o%s%s\n",
68 : 8 : path, uname, gname, mode,
69 : 8 : fflags ? " flags=" : "",
70 [ - + ]: 8 : fflags_buffer ? fflags_buffer : "") < 0) {
71 : 0 : pkg_errno("%s", "Unable to write to the metalog");
72 : 0 : }
73 : 8 : break;
74 : : case PKG_METALOG_FILE:
75 [ - + - + ]: 36 : if (fprintf(metalogfp,
76 : : "./%s type=file uname=%s gname=%s mode=%3o%s%s\n",
77 : 12 : path, uname, gname, mode,
78 : 12 : fflags ? " flags=" : "",
79 [ + - ]: 12 : fflags_buffer ? fflags_buffer : "") < 0) {
80 : 0 : pkg_errno("%s", "Unable to write to the metalog");
81 : 0 : }
82 : 12 : break;
83 : : case PKG_METALOG_LINK:
84 [ - + - + ]: 12 : if (fprintf(metalogfp,
85 : : "./%s type=link uname=%s gname=%s mode=%3o link=%s%s%s\n",
86 : 4 : path, uname, gname, mode, link,
87 : 4 : fflags ? " flags=" : "",
88 [ + - ]: 4 : fflags_buffer ? fflags_buffer : "") < 0) {
89 : 0 : pkg_errno("%s", "Unable to write to the metalog");
90 : 0 : }
91 : 4 : break;
92 : : }
93 : :
94 : 24 : free(fflags_buffer);
95 : 527 : }
96 : :
97 : : void
98 : 3501 : metalog_close()
99 : : {
100 [ + + ]: 3501 : if (metalogfp != NULL) {
101 : 4 : fclose(metalogfp);
102 : 4 : }
103 : 3501 : }
|