// Are we using a snapshot?
if (self->flags & PAKFIRE_ROOT_USE_SNAPSHOT) {
// Find the most recent snapshot
- r = pakfire_snapshot_find(&self->snapshot, self);
+ r = pakfire_snapshot_find(&self->snapshot, self->ctx, self);
if (r < 0) {
ERROR(self->ctx, "Could not find a snapshot: %s\n", strerror(-r));
goto ERROR;
return r;
// Clean all snapshots
- r = pakfire_snapshot_clean(self);
+ r = pakfire_snapshot_clean(self->ctx, self);
if (r < 0)
return r;
int r;
// Make a new snapshot
- r = pakfire_snapshot_make(&snapshot, self);
+ r = pakfire_snapshot_make(&snapshot, self->ctx, self);
if (r < 0)
goto ERROR;
/*
Finds and returns the latest snapshot
*/
-int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_root* root) {
+int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_ctx* ctx, pakfire_root* root) {
struct dirent** paths = NULL;
int num_paths = 0;
char path[PATH_MAX];
int fd = -EBADF;
int r;
- pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
// Make the path
r = pakfire_root_cache_path(root, path, "%s", "snapshots");
if (r < 0)
switch (errno) {
// If the directory does not exist, we will make a new snapshot
case ENOENT:
- r = pakfire_snapshot_make(snapshot, root);
+ r = pakfire_snapshot_make(snapshot, ctx, root);
if (r < 0)
goto ERROR;
// Create a new snapshot if none was found
} else if (num_paths == 0) {
- r = pakfire_snapshot_make(snapshot, root);
+ r = pakfire_snapshot_make(snapshot, ctx, root);
if (r < 0)
goto ERROR;
}
if (fd >= 0)
close(fd);
- if (ctx)
- pakfire_ctx_unref(ctx);
return r;
}
/*
Creates a new snapshot
*/
-int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_root* root) {
+int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_ctx* ctx, pakfire_root* root) {
pakfire_config* config = NULL;
pakfire_root* p = NULL;
char snapshot_path[PATH_MAX];
NULL,
};
- pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
// Fetch the configuration
config = pakfire_root_get_config(root);
goto ERROR;
// Cleanup any older snapshots (and ignore if something goes wrong)
- pakfire_snapshot_clean(root);
+ pakfire_snapshot_clean(ctx, root);
ERROR:
if (config)
pakfire_config_unref(config);
- if (ctx)
- pakfire_ctx_unref(ctx);
if (p)
pakfire_root_unref(p);
/*
Cleans up any unused snapshots
*/
-int pakfire_snapshot_clean(pakfire_root* root) {
+int pakfire_snapshot_clean(pakfire_ctx* ctx, pakfire_root* root) {
pakfire_snapshot* snapshot = NULL;
char path[PATH_MAX];
FTS* f = NULL;
int r;
- pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
DEBUG(ctx, "Cleaning up snapshots...\n");
// Make the path
ERROR:
if (snapshot)
pakfire_snapshot_unref(snapshot);
- if (ctx)
- pakfire_ctx_unref(ctx);
if (f)
fts_close(f);
pakfire_snapshot* pakfire_snapshot_ref(pakfire_snapshot* self);
pakfire_snapshot* pakfire_snapshot_unref(pakfire_snapshot* self);
-int pakfire_snapshot_find(pakfire_snapshot** snapshot, pakfire_root* root);
+int pakfire_snapshot_find(pakfire_snapshot** snapshot,
+ pakfire_ctx* ctx, pakfire_root* root);
const char* pakfire_snapshot_path(pakfire_snapshot* self);
int pakfire_snapshot_mount(pakfire_snapshot* self, const char* path);
int pakfire_snapshot_umount(pakfire_snapshot* self);
-int pakfire_snapshot_make(pakfire_snapshot** snapshot, pakfire_root* root);
+int pakfire_snapshot_make(pakfire_snapshot** snapshot,
+ pakfire_ctx* ctx, pakfire_root* root);
-int pakfire_snapshot_clean(pakfire_root* root);
+int pakfire_snapshot_clean(pakfire_ctx* ctx, pakfire_root* root);
#endif /* PAKFIRE_SNAPSHOT_H */