static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist* filelist,
sqlite3_stmt* stmt) {
struct pakfire_file* file = NULL;
- char abspath[PATH_MAX];
int r;
- // Create a new file object
- r = pakfire_file_create(&file, db->pakfire);
- if (r)
- goto ERROR;
-
// Path
const char* path = (const char*)sqlite3_column_text(stmt, 0);
// Abort if no path is set
if (!path) {
CTX_ERROR(db->ctx, "File has no path\n");
- r = 1;
- goto ERROR;
- }
-
- // Set path
- r = pakfire_file_set_path(file, path);
- if (r) {
- CTX_ERROR(db->ctx, "%s: Could not set path '%s': %m\n", path, path);
+ r = -errno;
goto ERROR;
}
- // Make the absolute path
- r = pakfire_path(db->pakfire, abspath, "%s", path);
- if (r) {
- CTX_ERROR(db->ctx, "%s: Could not make absolute path: %m\n", path);
- goto ERROR;
- }
-
- // Set the absolute path
- r = pakfire_file_set_abspath(file, abspath);
- if (r) {
- CTX_ERROR(db->ctx, "%s: Could not set absolute path %s: %m\n", path, abspath);
+ // Create a new file object
+ r = pakfire_file_create(&file, db->pakfire, path);
+ if (r < 0)
goto ERROR;
- }
// Size
size_t size = sqlite3_column_int64(stmt, 1);
#include <pakfire/file.h>
#include <pakfire/logging.h>
#include <pakfire/pakfire.h>
+#include <pakfire/path.h>
#include <pakfire/private.h>
#include <pakfire/string.h>
#include <pakfire/util.h>
return r;
}
-PAKFIRE_EXPORT int pakfire_file_create(struct pakfire_file** file, struct pakfire* pakfire) {
+PAKFIRE_EXPORT int pakfire_file_create(struct pakfire_file** file,
+ struct pakfire* pakfire, const char* path) {
struct pakfire_file* f = NULL;
int r = 0;
goto ERROR;
}
+ // Store path
+ if (path) {
+ r = pakfire_file_set_path(f, path);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Return the pointer
*file = pakfire_file_ref(f);
return -EINVAL;
// Set abspath
- r = pakfire_file_set_abspath(file, path);
- if (r)
- return r;
+ archive_entry_copy_sourcepath(file->entry, path);
// Read everything
r = archive_read_disk_entry_from_file(reader, file->entry, -1, NULL);
struct pakfire_file* f = NULL;
int r;
- r = pakfire_file_create(&f, pakfire);
+ r = pakfire_file_create(&f, pakfire, NULL);
if (r < 0)
goto ERROR;
return archive_entry_sourcepath(file->entry);
}
-int pakfire_file_set_abspath(struct pakfire_file* file, const char* path) {
- // Check if path is set and absolute
- if (!path || *path != '/')
- return -EINVAL;
-
- // Store the abspath
- archive_entry_copy_sourcepath(file->entry, path);
-
- return 0;
-}
-
PAKFIRE_EXPORT const char* pakfire_file_get_path(struct pakfire_file* file) {
return archive_entry_pathname(file->entry);
}
if (pakfire_string_startswith(path, "./"))
path++;
- switch (*path) {
- // Just store the path if it is absolute
- case '/':
- archive_entry_set_pathname(file->entry, path);
- break;
+ // Make the path absolute
+ r = pakfire_path_absolute(buffer, path);
+ if (r < 0)
+ return r;
- // Handle relative paths
- default:
- r = pakfire_string_format(buffer, "/%s", path);
- if (r)
- goto ERROR;
+ // Store the path
+ archive_entry_set_pathname(file->entry, buffer);
- archive_entry_set_pathname(file->entry, buffer);
- break;
- }
+ // Make the absolute path
+ r = pakfire_path(file->pakfire, buffer, "%s", buffer);
+ if (r < 0)
+ return r;
- return r;
+ // Store the abspath
+ archive_entry_copy_sourcepath(file->entry, buffer);
-ERROR:
- CTX_ERROR(file->ctx, "Could not set path '%s': %m\n", path);
- return r;
+ printf("PATH = %s, %s\n", archive_entry_pathname(file->entry), archive_entry_sourcepath(file->entry));
+
+ return 0;
}
PAKFIRE_EXPORT const char* pakfire_file_get_hardlink(struct pakfire_file* file) {
#include <pakfire/i18n.h>
#include <pakfire/logging.h>
#include <pakfire/pakfire.h>
+#include <pakfire/path.h>
#include <pakfire/private.h>
#include <pakfire/progress.h>
#include <pakfire/string.h>
PAKFIRE_FILE_CONFIG = (1 << 0),
};
-int pakfire_file_create(struct pakfire_file** file, struct pakfire* pakfire);
+int pakfire_file_create(struct pakfire_file** file, struct pakfire* pakfire, const char* path);
struct pakfire_file* pakfire_file_ref(struct pakfire_file* file);
struct pakfire_file* pakfire_file_unref(struct pakfire_file* file);
char* pakfire_file_dump(struct pakfire_file* file, int flags);
const char* pakfire_file_get_abspath(struct pakfire_file* file);
-int pakfire_file_set_abspath(struct pakfire_file* file, const char* path);
FILE* pakfire_file_open(struct pakfire_file* file);
}
// Create a new file entry
- r = pakfire_file_create(&file, search->pakfire);
- if (r)
- goto ERROR;
-
- // Set path
- r = pakfire_file_set_path(file, path);
- if (r)
+ r = pakfire_file_create(&file, search->pakfire, path);
+ if (r < 0)
goto ERROR;
// Append the file to the filelist
r = pakfire_filelist_add(search->filelist, file);
- if (r)
+ if (r < 0)
goto ERROR;
ERROR:
struct pakfire_file* file = NULL;
int r;
+ if (!path)
+ path = sourcepath;
+
// Create a new file object
- r = pakfire_file_create(&file, packager->pakfire);
- if (r)
+ r = pakfire_file_create(&file, packager->pakfire, path);
+ if (r < 0)
goto ERROR;
// Read the meta information
r = pakfire_file_read(file, packager->reader, sourcepath);
- if (r)
+ if (r < 0)
goto ERROR;
- if (!path)
- path = sourcepath;
-
// Assign a new path for inside the archive
r = pakfire_file_set_path(file, path);
- if (r)
+ if (r < 0)
goto ERROR;
// Call the main function
// Create a new file
struct pakfire_file* file;
- r = pakfire_file_create(&file, pakfire);
+ r = pakfire_file_create(&file, pakfire, path);
if (r) {
errno = -r;
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
- // Set the path
- pakfire_file_set_path(file, path);
-
// Append the file to the filelist
pakfire_filelist_add(filelist, file);
pakfire_file_unref(file);
struct pakfire_file* file = NULL;
// Create a new file
- ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire));
+ ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire, NULL));
// Set path & check
ASSERT_SUCCESS(pakfire_file_set_path(file, "/abc"));
struct pakfire_file* file = NULL;
// Create a new file
- ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire));
+ ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire, NULL));
// Set path
ASSERT(pakfire_file_set_path(file, NULL) == -EINVAL);
- // It should not be possible to set relative absolute paths
- ASSERT(pakfire_file_set_abspath(file, "abc/abc") == -EINVAL);
-
// Destroy it
ASSERT_NULL(pakfire_file_unref(file));
ASSERT_SUCCESS(pakfire_filelist_create(&list, t->pakfire));
// Create some files
- ASSERT_SUCCESS(pakfire_file_create(&file1, t->pakfire));
- ASSERT_SUCCESS(pakfire_file_create(&file2, t->pakfire));
- ASSERT_SUCCESS(pakfire_file_create(&file3, t->pakfire));
-
- // Set some paths
- ASSERT_SUCCESS(pakfire_file_set_path(file1, "/1"));
- ASSERT_SUCCESS(pakfire_file_set_path(file2, "/2"));
- ASSERT_SUCCESS(pakfire_file_set_path(file3, "/3"));
+ ASSERT_SUCCESS(pakfire_file_create(&file1, t->pakfire, "/1"));
+ ASSERT_SUCCESS(pakfire_file_create(&file2, t->pakfire, "/2"));
+ ASSERT_SUCCESS(pakfire_file_create(&file3, t->pakfire, "/3"));
// Add the files to the list
ASSERT_SUCCESS(pakfire_filelist_add(list, file1));
ASSERT_SUCCESS(pakfire_filelist_create(&filelist, t->pakfire));
// Create a file
- ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire));
-
- // Store some path
- ASSERT_SUCCESS(pakfire_file_set_path(file, "/bin/bash"));
+ ASSERT_SUCCESS(pakfire_file_create(&file, t->pakfire, "/bin/bash"));
// Append the file to the filelist
ASSERT_SUCCESS(pakfire_filelist_add(filelist, file));