/*-1* Copyright (c) 2016 Brad Davis <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer9* in this position and unchanged.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* 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, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/25262728#include <errno.h>29#include "pkg.h"30#include "private/pkg.h"31#include "private/event.h"3233FILE *metalogfp = NULL;3435int36metalog_open(const char *metalog)37{38metalogfp = fopen(metalog, "ae");39if (metalogfp == NULL) {40pkg_fatal_errno("Unable to open metalog '%s'", metalog);41}4243return EPKG_OK;44}4546int47metalog_add(int type, const char *path, const char *uname, const char *gname,48int mode, unsigned long fflags, const char *link)49{50char *fflags_buffer = NULL;51int ret = EPKG_FATAL;5253if (metalogfp == NULL)54goto out;5556#ifdef HAVE_FFLAGSTOSTR57if (fflags) {58fflags_buffer = fflagstostr(fflags);59}60#endif6162// directory63switch (type) {64case PKG_METALOG_DIR:65if (fprintf(metalogfp,66"./%s type=dir uname=%s gname=%s mode=%3o%s%s\n",67path, uname, gname, mode,68fflags ? " flags=" : "",69fflags_buffer ? fflags_buffer : "") < 0) {70pkg_errno("%s", "Unable to write to the metalog");71goto out;72}73break;74case PKG_METALOG_FILE:75if (fprintf(metalogfp,76"./%s type=file uname=%s gname=%s mode=%3o%s%s\n",77path, uname, gname, mode,78fflags ? " flags=" : "",79fflags_buffer ? fflags_buffer : "") < 0) {80pkg_errno("%s", "Unable to write to the metalog");81goto out;82}83break;84case PKG_METALOG_LINK:85if (fprintf(metalogfp,86"./%s type=link uname=%s gname=%s mode=%3o link=%s%s%s\n",87path, uname, gname, mode, link,88fflags ? " flags=" : "",89fflags_buffer ? fflags_buffer : "") < 0) {90pkg_errno("%s", "Unable to write to the metalog");91goto out;92}93break;94}95ret = EPKG_OK;9697out:98free(fflags_buffer);99return (ret);100}101102void103metalog_close()104{105if (metalogfp != NULL) {106fclose(metalogfp);107}108}109110111