const char* pakfire_path_abspath(const char* path);
const char* pakfire_path_relpath(const char* root, const char* path);
+#define pakfire_path_realpath(dest, path) \
+ __pakfire_path_realpath(dest, sizeof(dest), path)
+int __pakfire_path_realpath(char* dest, const size_t length, const char* path);
+
// File stuff
int pakfire_file_write(struct pakfire* pakfire, const char* path,
PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* path,
int flags, const char** files) {
struct pakfire_repo* repo = NULL;
- const char* abspath = NULL;
+ char realpath[PATH_MAX];
char baseurl[PATH_MAX];
int r;
}
// Make path absolute
- abspath = pakfire_path_abspath(path);
- if (!abspath)
- return 1;
+ r = pakfire_path_realpath(realpath, path);
+ if (r)
+ return r;
// Prefix path with file:// to form baseurl
- r = pakfire_string_format(baseurl, "file://%s", abspath);
+ r = pakfire_string_format(baseurl, "file://%s", realpath);
if (r)
return 1;
const char* filename = pakfire_package_get_string(package, PAKFIRE_PKG_FILENAME);
// Make new path
- r = pakfire_path_join(destination_path, abspath, filename);
+ r = pakfire_path_join(destination_path, realpath, filename);
if (r)
goto OUT;
return NULL;
}
+int __pakfire_path_realpath(char* dest, const size_t length, const char* path) {
+ char buffer[PATH_MAX];
+
+ // Resolve path to its absolute path and store it in buffer
+ char* p = realpath(path, buffer);
+ if (!p)
+ return 1;
+
+ return __pakfire_string_set(dest, length, buffer);
+}
+
int pakfire_path_exists(const char* path) {
return !access(path, F_OK);
}