}
// Make path for configuration file
- r = pakfire_make_path(build->pakfire, repopath,
- PAKFIRE_CONFIG_DIR "/repos/" PAKFIRE_REPO_LOCAL ".repo");
- if (r < 0)
+ r = pakfire_path(build->pakfire, repopath,
+ "%s", PAKFIRE_CONFIG_DIR "/repos/" PAKFIRE_REPO_LOCAL ".repo");
+ if (r)
goto ERROR;
// Write repository configuration
char path[PATH_MAX];
// Allocate path to write the filelist to
- int r = pakfire_make_path(build->pakfire, path, "/var/tmp/.pakfire-filelist.XXXXXX");
- if (r < 0)
+ int r = pakfire_path(build->pakfire, path, "%s", "/var/tmp/.pakfire-filelist.XXXXXX");
+ if (r)
return 1;
// Create a temporary file
struct pakfire_parser* makefile, const char* buildroot, const char* namespace,
struct pakfire_package* pkg, struct pakfire_packager* packager) {
struct pakfire_filelist* filelist = NULL;
- char path[PATH_MAX];
int r = 1;
char** files = NULL;
if (!files)
return 0;
- // Convert to absolute path
- pakfire_make_path(build->pakfire, path, buildroot);
-
// Split into includes and excludes
for (char** file = files; *file; file++) {
if (**file == '!')
goto ERROR;
// Scan for files
- r = pakfire_filelist_scan(filelist, path, includes, excludes);
+ r = pakfire_filelist_scan(filelist, build->buildroot, includes, excludes);
if (r)
goto ERROR;
const char* root = pakfire_get_path(build->pakfire);
// Make filename
- r = pakfire_make_path(build->pakfire, path, "/var/tmp/.pakfire-scriptlet.XXXXXX");
- if (r < 0)
+ r = pakfire_path(build->pakfire, path, "%s", "/var/tmp/.pakfire-scriptlet.XXXXXX");
+ if (r)
return r;
// Fetch scriptlet payload
static int pakfire_build_read_makefile(struct pakfire_build* build,
struct pakfire_parser** parser, struct pakfire_package* package) {
- char makefile[PATH_MAX];
char path[PATH_MAX];
int r;
const char* name = pakfire_package_get_name(package);
// Compose path to makefile
- r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", nevra, name);
- if (r)
- return r;
-
- // Make it absolute
- r = pakfire_make_path(build->pakfire, path, makefile);
+ r = pakfire_path(build->pakfire, path, "/usr/src/packages/%s/%s.nm", nevra, name);
if (r < 0)
return 1;
int r;
// Set buildroot
- pakfire_make_path(build->pakfire, build->buildroot, "/var/tmp/.pakfire-buildroot.XXXXXX");
+ r = pakfire_path(build->pakfire, build->buildroot, "%s", "/var/tmp/.pakfire-buildroot.XXXXXX");
+ if (r)
+ goto ERROR;
// Open source archive
r = pakfire_archive_open(&archive, build->pakfire, path);
};
// Set prefix (including pakfire path)
- pakfire_make_path(pakfire, data.prefix, prefix);
+ r = pakfire_path(pakfire, data.prefix, "%s", prefix);
+ if (r)
+ goto ERROR;
// Allocate writer
data.writer = pakfire_make_archive_disk_writer(pakfire, 1);
if (!data.writer) {
ERROR(pakfire, "Could not create disk writer: %m\n");
+ r = 1;
goto ERROR;
}
}
// Make the filename
- r = pakfire_make_path(o->pakfire, o->path, DATABASE_PATH);
- if (r < 0)
+ r = pakfire_path(o->pakfire, o->path, "%s", DATABASE_PATH);
+ if (r)
goto END;
// Try to open the sqlite3 database file
pakfire_file_set_path(file, path);
// Abspath
- r = pakfire_make_path(db->pakfire, abspath, path);
- if (r < 0)
+ r = pakfire_path(db->pakfire, abspath, "%s", path);
+ if (r)
goto ERROR;
pakfire_file_set_abspath(file, abspath);
const char* pakfire_get_keystore_path(struct pakfire* pakfire);
-#define pakfire_make_path(pakfire, dst, path) \
- __pakfire_make_path(pakfire, dst, sizeof(dst) - 1, path)
-int __pakfire_make_path(struct pakfire* pakfire, char* dst, size_t length, const char* path);
+#define pakfire_path(pakfire, path, format, ...) \
+ __pakfire_path(pakfire, path, sizeof(path), format, __VA_ARGS__)
+int __pakfire_path(struct pakfire* pakfire, char* path, const size_t length,
+ const char* format, ...) __attribute__((format(printf, 4, 5)));
const char* pakfire_relpath(struct pakfire* pakfire, const char* path);
#ifdef PAKFIRE_PRIVATE
+#include <stdarg.h>
+
/*
Formats a string and stores it in the given buffer.
*/
const char* ldconfig = "/sbin/ldconfig";
// Check if ldconfig exists before calling it to avoid overhead
- int r = pakfire_make_path(pakfire, path, ldconfig);
- if (r < 0)
- return 1;
+ int r = pakfire_path(pakfire, path, "%s", ldconfig);
+ if (r)
+ return r;
// Check if ldconfig is executable
r = access(path, X_OK);
char path[PATH_MAX];
// Make path
- int r = pakfire_make_path(pakfire, path, "/etc/pakfire/trusted.keys.d");
- if (r < 0)
+ int r = pakfire_path(pakfire, path, "%s", "/etc/pakfire/trusted.keys.d");
+ if (r)
return r;
DEBUG(pakfire, "Loading keys from %s\n", path);
for (const struct pakfire_devnode* devnode = devnodes; devnode->path; devnode++) {
DEBUG(pakfire, "Creating device node %s\n", devnode->path);
- int r = pakfire_make_path(pakfire, path, devnode->path);
- if (r < 0)
- return 1;
+ int r = pakfire_path(pakfire, path, "%s", devnode->path);
+ if (r)
+ return r;
dev_t dev = makedev(devnode->major, devnode->minor);
for (const struct pakfire_symlink* s = symlinks; s->target; s++) {
DEBUG(pakfire, "Creating symlink %s -> %s\n", s->path, s->target);
- int r = pakfire_make_path(pakfire, path, s->path);
- if (r < 0)
- return 1;
+ int r = pakfire_path(pakfire, path, "%s", s->path);
+ if (r)
+ return r;
r = symlink(s->target, path);
if (r) {
DEBUG(pakfire, "Mounting interpreter %s for %s\n", interpreter, arch);
// Where to mount this?
- int r = pakfire_make_path(pakfire, target, interpreter);
- if (r < 0)
+ int r = pakfire_path(pakfire, target, "%s", interpreter);
+ if (r)
return r;
// Create directory
if (!dst)
dst = src;
- int r = pakfire_make_path(pakfire, mountpoint, dst);
- if (r < 0)
- return 1;
+ int r = pakfire_path(pakfire, mountpoint, "%s", dst);
+ if (r)
+ return r;
DEBUG(pakfire, "Bind-mounting %s to %s\n", src, mountpoint);
static int pakfire_read_repo_config(struct pakfire* pakfire) {
char path[PATH_MAX];
+ int r;
- int r = pakfire_make_path(pakfire, path, PAKFIRE_CONFIG_DIR "/repos");
- if (r < 0)
- return 1;
+ // Make path absolute
+ r = pakfire_path(pakfire, path, "%s", PAKFIRE_CONFIG_DIR "/repos");
+ if (r)
+ return r;
DEBUG(pakfire, "Reading repository configuration from %s\n", path);
static int pakfire_read_config(struct pakfire* pakfire, const char* path) {
char default_path[PATH_MAX];
+ int r;
// Use default path if none set
if (!path) {
- int r = pakfire_make_path(pakfire, default_path, PAKFIRE_CONFIG_DIR "/general.conf");
- if (r < 0)
- return 1;
+ r = pakfire_path(pakfire, default_path, "%s", PAKFIRE_CONFIG_DIR "/general.conf");
+ if (r)
+ return r;
path = default_path;
}
}
// Read configuration from file
- int r = pakfire_config_read(pakfire->config, f);
+ r = pakfire_config_read(pakfire->config, f);
if (r) {
ERROR(pakfire, "Could not parse configuration file %s: %m\n", path);
goto ERROR;
char* line = NULL;
size_t l = 0;
- int r = pakfire_make_path(pakfire, path, "/etc/os-release");
- if (r < 0)
- return 1;
+ int r = pakfire_path(pakfire, path, "%s", "/etc/os-release");
+ if (r)
+ return r;
r = 1;
const char* arch, const char* conf, int flags,
int loglevel, pakfire_log_callback log_callback, void* log_data) {
char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
+ char private_dir[PATH_MAX];
int r = 1;
// Reset pakfire pointer
DEBUG(p, " slogan = %s\n", p->distro.slogan);
// Set lock path
- r = pakfire_make_path(p, p->lock_path, LOCK_PATH);
- if (r < 0) {
+ r = pakfire_path(p, p->lock_path, "%s", LOCK_PATH);
+ if (r) {
ERROR(p, "Could not set lock path: %m\n");
goto ERROR;
}
}
// Set keystore path
- r = pakfire_make_path(p, p->keystore_path, KEYSTORE_DIR);
- if (r < 0) {
+ r = pakfire_path(p, p->keystore_path, "%s", KEYSTORE_DIR);
+ if (r) {
ERROR(p, "Could not set keystore path: %m\n");
goto ERROR;
}
// Make path for private files
- char private_dir[PATH_MAX];
- r = pakfire_make_path(p, private_dir, PAKFIRE_PRIVATE_DIR);
- if (r < 0) {
- r = 1;
+ r = pakfire_path(p, private_dir, "%s", PAKFIRE_PRIVATE_DIR);
+ if (r)
goto ERROR;
- }
// Make sure that our private directory exists
r = pakfire_mkdir(private_dir, 0755);
return pakfire->keystore_path;
}
-int __pakfire_make_path(struct pakfire* pakfire, char* dst, size_t length, const char* path) {
- // Make sure that path never starts with /
- while (path && *path == '/')
- path++;
+int __pakfire_path(struct pakfire* pakfire, char* path, const size_t length,
+ const char* format, ...) {
+ char buffer[PATH_MAX];
+ va_list args;
+ int r;
+
+ // Format input into buffer
+ va_start(args, format);
+ r = __pakfire_string_vformat(buffer, sizeof(buffer), format, args);
+ va_end(args);
+
+ // Break on any errors
+ if (r)
+ return r;
- return __pakfire_path_join(dst, length, pakfire->path, path);
+ // Join paths together
+ return __pakfire_path_join(path, length, pakfire->path, buffer);
}
const char* pakfire_relpath(struct pakfire* pakfire, const char* path) {
}
PAKFIRE_EXPORT int pakfire_copy_in(struct pakfire* pakfire, const char* src, const char* dst) {
+ char path[PATH_MAX];
+ int r;
+
if (pakfire_on_root(pakfire)) {
errno = ENOTSUP;
return 1;
}
- char path[PATH_MAX];
- int r = pakfire_make_path(pakfire, path, dst);
- if (r < 0)
- return 1;
+ r = pakfire_path(pakfire, path, "%s", dst);
+ if (r)
+ return r;
return pakfire_copy(pakfire, src, path, PAKFIRE_COPY_IN);
}
PAKFIRE_EXPORT int pakfire_copy_out(struct pakfire* pakfire, const char* src, const char* dst) {
+ char path[PATH_MAX];
+ int r;
+
if (pakfire_on_root(pakfire)) {
errno = ENOTSUP;
return 1;
}
- char path[PATH_MAX];
- int r = pakfire_make_path(pakfire, path, src);
- if (r < 0)
- return 1;
+ r = pakfire_path(pakfire, path, "%s", src);
+ if (r)
+ return r;
return pakfire_copy(pakfire, path, dst, PAKFIRE_COPY_OUT);
}
int(*cmp)(struct passwd* entry, const void* value), const void* value) {
struct passwd* entry = NULL;
char path[PATH_MAX];
+ int r;
// Get path to /etc/passwd
- int r = pakfire_make_path(pakfire, path, "/etc/passwd");
- if (r < 0)
+ r = pakfire_path(pakfire, path, "%s", "/etc/passwd");
+ if (r)
return NULL;
FILE* f = fopen(path, "r");
int(*cmp)(struct group* entry, const void* value), const void* value) {
struct group* entry = NULL;
char path[PATH_MAX];
+ int r;
// Get path to /etc/group
- int r = pakfire_make_path(pakfire, path, "/etc/group");
- if (r < 0)
+ r = pakfire_path(pakfire, path, "%s", "/etc/group");
+ if (r)
return NULL;
FILE* f = fopen(path, "r");
ASSERT_SUCCESS(pakfire_archive_extract(archive));
// Check if test file from the archive exists
- pakfire_make_path(t->pakfire, path, "/usr/bin/beep");
+ pakfire_path(t->pakfire, path, "%s", "/usr/bin/beep");
ASSERT_SUCCESS(access(path, F_OK));
r = EXIT_SUCCESS;