return __pakfire_cache_path(repo->pakfire, path, length, "%s/%s", name, buffer);
}
-static const char* pakfire_repo_relpath(struct pakfire_repo* self, const char* path) {
+#define pakfire_repo_relpath(repo, result, path) \
+ __pakfire_repo_relpath(repo, result, sizeof(result), path);
+
+static int __pakfire_repo_relpath(struct pakfire_repo* self, char* result, size_t length, const char* path) {
// Fetch the repo's base path
const char* basepath = pakfire_repo_get_path(self);
- return pakfire_path_relpath(basepath, path);
+ return __pakfire_path_relative(result, length, basepath, path);
}
static int pakfire_repo_xfer_create(struct pakfire_xfer** xfer, struct pakfire_repo* repo,
int pakfire_repo_import_archive(struct pakfire_repo* self, struct pakfire_archive* archive) {
struct pakfire_package* pkg = NULL;
const char* uuid = NULL;
+ char relpath[PATH_MAX];
char path[PATH_MAX];
int r;
break;
}
+ r = pakfire_repo_relpath(self, relpath, path);
+ if (r < 0)
+ goto ERROR;
+
// Copy (or link) the archive
r = pakfire_archive_link_or_copy(archive, path);
if (r < 0)
goto ERROR;
// Reset the path
- r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, pakfire_repo_relpath(self, path));
+ r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, relpath);
if (r < 0)
goto ERROR;
return NULL;
}
- // Return NULL if path does not start with root
- if (!pakfire_string_startswith(path, root))
- return NULL;
-
- // Skip the root
- path += strlen(root);
-
- // Skip any leading slashes
- while (path && *path == '/')
- path++;
+ if (pakfire_string_startswith(path, root))
+ return path + strlen(root);
- return path;
+ return NULL;
}
int pakfire_file_write(struct pakfire* pakfire, const char* path,