#endif
// Set filename
- const char* filename = pakfire_basename(archive->path);
+ char* filename = pakfire_basename(archive->path);
if (filename) {
pakfire_package_set_filename(pkg, filename);
+ pakfire_free(filename);
}
// Set UUID
char* pakfire_path_join(const char* first, const char* second);
-const char* pakfire_basename(const char* path);
-const char* pakfire_dirname(const char* path);
+char* pakfire_basename(const char* path);
+char* pakfire_dirname(const char* path);
int pakfire_access(Pakfire pakfire, const char* dir, const char* file, int mode);
int pakfire_mkdir(Pakfire pakfire, const char* path, mode_t mode);
Id handle = pakfire_package_get_handle(pkg);
- const char* dirname = pakfire_dirname(filename);
- const char* basename = pakfire_basename(filename);
+ char* dirname = pakfire_dirname(filename);
+ char* basename = pakfire_basename(filename);
Id did = repodata_str2dir(repodata, dirname, 1);
if (!did)
SOLVABLE_FILELIST, did, basename);
pakfire_repo_unref(repo);
+ pakfire_free(dirname);
+ pakfire_free(basename);
return NULL;
}
char* cache_path = pakfire_get_cache_path(pakfire, path);
// Ensure that the parent directory exists
- const char* cache_dirname = pakfire_dirname(cache_path);
+ char* cache_dirname = pakfire_dirname(cache_path);
int r = pakfire_mkdir(pakfire, cache_dirname, S_IRUSR|S_IWUSR|S_IXUSR);
if (r)
FAIL:
pakfire_free(cache_path);
+ pakfire_free(cache_dirname);
return f;
}
return buffer;
}
-const char* pakfire_basename(const char* path) {
+PAKFIRE_EXPORT char* pakfire_basename(const char* path) {
char* name = pakfire_strdup(path);
const char* r = basename(name);
+ if (r)
+ r = pakfire_strdup(r);
+
pakfire_free(name);
return r;
}
-const char* pakfire_dirname(const char* path) {
+PAKFIRE_EXPORT char* pakfire_dirname(const char* path) {
char* parent = pakfire_strdup(path);
const char* r = dirname(parent);
+ if (r)
+ r = pakfire_strdup(r);
+
pakfire_free(parent);
return r;
return 0;
// If parent does not exists, we try to create it.
- const char* parent = pakfire_dirname(path);
+ char* parent = pakfire_dirname(path);
r = pakfire_access(pakfire, parent, NULL, F_OK);
if (r)
r = pakfire_mkdir(pakfire, parent, 0);
+ pakfire_free(parent);
+
+ // Exit if parent directory could not be created
if (r)
return r;
+ DEBUG(pakfire, "Creating directory %s\n", path);
+
// Finally, create the directory we want.
r = mkdir(path, mode);
if (r) {