Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/libpkg/metalog.c
2065 views
1
/*-
2
* Copyright (c) 2016 Brad Davis <[email protected]>
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
metalog_open(const char *metalog)
38
{
39
metalogfp = fopen(metalog, "ae");
40
if (metalogfp == NULL) {
41
pkg_fatal_errno("Unable to open metalog '%s'", metalog);
42
}
43
44
return EPKG_OK;
45
}
46
47
int
48
metalog_add(int type, const char *path, const char *uname, const char *gname,
49
int mode, unsigned long fflags, const char *link)
50
{
51
char *fflags_buffer = NULL;
52
int ret = EPKG_FATAL;
53
54
if (metalogfp == NULL)
55
goto out;
56
57
#ifdef HAVE_FFLAGSTOSTR
58
if (fflags) {
59
fflags_buffer = fflagstostr(fflags);
60
}
61
#endif
62
63
// directory
64
switch (type) {
65
case PKG_METALOG_DIR:
66
if (fprintf(metalogfp,
67
"./%s type=dir uname=%s gname=%s mode=%3o%s%s\n",
68
path, uname, gname, mode,
69
fflags ? " flags=" : "",
70
fflags_buffer ? fflags_buffer : "") < 0) {
71
pkg_errno("%s", "Unable to write to the metalog");
72
goto out;
73
}
74
break;
75
case PKG_METALOG_FILE:
76
if (fprintf(metalogfp,
77
"./%s type=file uname=%s gname=%s mode=%3o%s%s\n",
78
path, uname, gname, mode,
79
fflags ? " flags=" : "",
80
fflags_buffer ? fflags_buffer : "") < 0) {
81
pkg_errno("%s", "Unable to write to the metalog");
82
goto out;
83
}
84
break;
85
case PKG_METALOG_LINK:
86
if (fprintf(metalogfp,
87
"./%s type=link uname=%s gname=%s mode=%3o link=%s%s%s\n",
88
path, uname, gname, mode, link,
89
fflags ? " flags=" : "",
90
fflags_buffer ? fflags_buffer : "") < 0) {
91
pkg_errno("%s", "Unable to write to the metalog");
92
goto out;
93
}
94
break;
95
}
96
ret = EPKG_OK;
97
98
out:
99
free(fflags_buffer);
100
return (ret);
101
}
102
103
void
104
metalog_close()
105
{
106
if (metalogfp != NULL) {
107
fclose(metalogfp);
108
}
109
}
110
111