// Set path
path = archive_entry_pathname(entry);
if (path) {
- // Strip any leading dots from paths
- if (pakfire_string_startswith(path, "./"))
- path++;
-
r = pakfire_file_set_path(file, path);
if (r) {
ERROR(file->pakfire, "Could not set path: %m\n");
PAKFIRE_EXPORT int pakfire_file_set_path(struct pakfire_file* file, const char* path) {
int r = 1;
- // Check if path is set and absolute
- if (!path || *path != '/') {
+ // Check if path is set
+ if (!path) {
errno = EINVAL;
goto ERROR;
}
- // Store path
- r = pakfire_string_set(file->path, path);
- if (r)
- goto ERROR;
+ // Strip any leading dots from paths
+ if (pakfire_string_startswith(path, "./"))
+ path++;
+
+ switch (*path) {
+ // Just store the path if it is absolute
+ case '/':
+ r = pakfire_string_set(file->path, path);
+ if (r)
+ goto ERROR;
+ break;
+
+ // Handle relative paths
+ default:
+ r = pakfire_string_format(file->path, "/%s", path);
+ if (r)
+ goto ERROR;
+ break;
+ }
// Set abspath if it isn't set, yet
if (!*file->abspath) {
- r = pakfire_file_set_abspath(file, path);
+ r = pakfire_file_set_abspath(file, file->path);
if (r)
goto ERROR;
}