libxbps: file including in xbps.conf supports relative paths.
This commit is contained in:
parent
4070255529
commit
152ec0354f
@ -37,6 +37,7 @@
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <glob.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
@ -179,6 +180,8 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested, bool vpkgconf
|
||||
size_t len, nlines = 0;
|
||||
ssize_t read;
|
||||
char *line = NULL;
|
||||
char ocwd[XBPS_MAXPATH], tmppath[XBPS_MAXPATH];
|
||||
char *cwd;
|
||||
int rv = 0;
|
||||
|
||||
if ((fp = fopen(path, "r")) == NULL) {
|
||||
@ -191,6 +194,20 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested, bool vpkgconf
|
||||
xbps_dbg_printf(xhp, "Parsing configuration file: %s\n", path);
|
||||
}
|
||||
|
||||
/* cwd to the dir containing the config file */
|
||||
strncpy(tmppath, path, sizeof(tmppath));
|
||||
cwd = dirname(tmppath);
|
||||
if(getcwd(ocwd, sizeof(ocwd)) == NULL) {
|
||||
rv = errno;
|
||||
xbps_dbg_printf(xhp, "cannot get cwd: %s\n", strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
if(chdir(cwd)) {
|
||||
rv = errno;
|
||||
xbps_dbg_printf(xhp, "cannot chdir to %s: %s\n", cwd, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
|
||||
while ((read = getline(&line, &len, fp)) != -1) {
|
||||
char *p, *k, *v;
|
||||
|
||||
@ -244,6 +261,13 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested, bool vpkgconf
|
||||
free(line);
|
||||
fclose(fp);
|
||||
|
||||
/* Going back to old working directory */
|
||||
if(chdir(ocwd)) {
|
||||
rv = errno;
|
||||
xbps_dbg_printf(xhp, "cannot chdir to %s: %s\n", ocwd, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ SUBDIRS += util
|
||||
SUBDIRS += find_pkg_obsoletes
|
||||
SUBDIRS += find_pkg_orphans
|
||||
SUBDIRS += pkgdb
|
||||
SUBDIRS += config
|
||||
SUBDIRS += shell
|
||||
|
||||
include ../../../mk/subdir.mk
|
||||
|
@ -19,6 +19,7 @@ atf_test_program{name="installmode_test"}
|
||||
atf_test_program{name="obsoletefiles_test"}
|
||||
atf_test_program{name="scripts_test"}
|
||||
atf_test_program{name="incorrect_deps_test"}
|
||||
atf_test_program{name="config_test"}
|
||||
|
||||
include('find_pkg_orphans/Kyuafile')
|
||||
include('pkgdb/Kyuafile')
|
||||
|
1
tests/xbps/libxbps/config/1.include.conf
Normal file
1
tests/xbps/libxbps/config/1.include.conf
Normal file
@ -0,0 +1 @@
|
||||
repository=1
|
1
tests/xbps/libxbps/config/2.include.conf
Normal file
1
tests/xbps/libxbps/config/2.include.conf
Normal file
@ -0,0 +1 @@
|
||||
repository=2
|
5
tests/xbps/libxbps/config/Kyuafile
Normal file
5
tests/xbps/libxbps/config/Kyuafile
Normal file
@ -0,0 +1,5 @@
|
||||
syntax("kyuafile", 1)
|
||||
|
||||
test_suite("libxbps")
|
||||
|
||||
atf_test_program{name="xbps_conf_test"}
|
8
tests/xbps/libxbps/config/Makefile
Normal file
8
tests/xbps/libxbps/config/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
TOPDIR = ../../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TESTSSUBDIR = xbps/libxbps/config
|
||||
TEST = config_test
|
||||
EXTRA_FILES = Kyuafile xbps.conf 1.include.conf 2.include.conf
|
||||
|
||||
include $(TOPDIR)/mk/test.mk
|
64
tests/xbps/libxbps/config/main.c
Normal file
64
tests/xbps/libxbps/config/main.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*-
|
||||
* Copyright (c) 2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps.h>
|
||||
|
||||
ATF_TC(xbps_conf_include_test);
|
||||
ATF_TC_HEAD(xbps_conf_include_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test including files by file globbing");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(xbps_conf_include_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
const char *tcsdir;
|
||||
char conffile[XBPS_MAXPATH-1];
|
||||
|
||||
/* get test source dir */
|
||||
tcsdir = atf_tc_get_config_var(tc, "srcdir");
|
||||
|
||||
/* change dir to make sure relative paths won't match */
|
||||
ATF_REQUIRE_EQ(chdir("/"), 0);
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
strncpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
|
||||
strncpy(xh.metadir, tcsdir, sizeof(xh.metadir));
|
||||
strncpy(conffile, tcsdir, sizeof(conffile));
|
||||
strncat(conffile, "/xbps.conf", sizeof(conffile));
|
||||
xh.conffile = conffile;
|
||||
xh.flags = XBPS_FLAG_DEBUG;
|
||||
ATF_REQUIRE_EQ(xbps_init(&xh), 0);
|
||||
|
||||
/* should contain both repositories defined in [12].include.conf */
|
||||
ATF_REQUIRE_EQ(xbps_array_count(xh.repositories), 2);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, xbps_conf_include_test);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
2
tests/xbps/libxbps/config/xbps.conf
Normal file
2
tests/xbps/libxbps/config/xbps.conf
Normal file
@ -0,0 +1,2 @@
|
||||
# relative path
|
||||
include=*.include.conf
|
16
tests/xbps/libxbps/shell/xbps_conf_test.sh
Normal file
16
tests/xbps/libxbps/shell/xbps_conf_test.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env atf-sh
|
||||
|
||||
# Tests to verify that xbps.conf features work
|
||||
|
||||
atf_test_case tc1
|
||||
|
||||
tc1_head() {
|
||||
atf_set "descr" "Tests for xbps.conf: include "
|
||||
}
|
||||
|
||||
tc1_body() {
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case tc1
|
||||
}
|
Loading…
Reference in New Issue
Block a user