Py_RETURN_FALSE;
}
-static PyObject* Archive_extract(ArchiveObject* self) {
+static PyObject* Archive_extract(ArchiveObject* self, PyObject* args, PyObject* kwargs) {
+ char* kwlist[] = { "path", NULL };
+ const char* path = NULL;
+ const int flags = 0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|z", kwlist, &path))
+ return NULL;
+
// Extract payload
- int r = pakfire_archive_extract(self->archive);
+ int r = pakfire_archive_extract(self->archive, path, flags);
if (r) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
{
"extract",
(PyCFunction)Archive_extract,
- METH_NOARGS,
+ METH_VARARGS|METH_KEYWORDS,
NULL
},
{
return r;
}
-static int __pakfire_archive_extract(struct pakfire_archive* archive, int flags) {
+static int __pakfire_archive_extract(struct pakfire_archive* archive,
+ const char* path, int flags) {
struct pakfire_filelist* filelist = NULL;
struct pakfire_package* pkg = NULL;
struct archive* a = NULL;
DEBUG(archive->pakfire, "Extracting %s\n", archive->path);
+ // Copy everything to path if set
+ if (path) {
+ r = pakfire_string_set(prefix, path);
+ if (r)
+ goto ERROR;
+
// Set prefix for source packages
- if (pakfire_package_is_source(pkg)) {
- r = pakfire_string_format(prefix, "/usr/src/packages/%s", nevra);
+ } else if (pakfire_package_is_source(pkg)) {
+ r = pakfire_path(archive->pakfire, prefix, "/usr/src/packages/%s", nevra);
+ if (r)
+ goto ERROR;
+
+ // Otherwise extract relative to the pakfire root
+ } else {
+ r = pakfire_path(archive->pakfire, prefix, "%s", "/");
if (r)
goto ERROR;
}
return r;
}
-PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive) {
- return __pakfire_archive_extract(archive, 0);
+PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive,
+ const char* path, const int flags) {
+ return __pakfire_archive_extract(archive, path, flags);
}
PAKFIRE_EXPORT const char* pakfire_archive_get_path(struct pakfire_archive* archive) {
static int pakfire_archive_load_filelist(struct pakfire_archive* archive) {
// Perform a dry-run extraction
- return __pakfire_archive_extract(archive,
+ return __pakfire_archive_extract(archive, NULL,
PAKFIRE_EXTRACT_DRY_RUN|PAKFIRE_EXTRACT_NO_PROGRESS);
}
struct pakfire_filelist* filelist;
// Prepend this prefix
- char prefix[PATH_MAX];
+ const char* prefix;
// The writer
struct archive* writer;
pakfire_walk_filter_callback filter_callback, int flags) {
int r = 1;
- // Use an empty string if no prefix set
+ // Use / if no prefix is set
if (!prefix)
- prefix = "";
+ prefix = "/";
struct pakfire_extract data = {
.pakfire = pakfire,
.archive = archive,
.filelist = filelist,
+ .prefix = prefix,
.flags = flags,
.writer = NULL,
};
// Should we show a progress bar?
const int no_progress = flags & PAKFIRE_EXTRACT_NO_PROGRESS;
- // Set prefix (including pakfire path)
- r = pakfire_path(pakfire, data.prefix, "%s", prefix);
- if (r)
- goto ERROR;
-
// Allocate writer
if (!dry_run) {
data.writer = pakfire_make_archive_disk_writer(pakfire, 1);
struct pakfire_archive* pakfire_archive_unref(struct pakfire_archive* archive);
FILE* pakfire_archive_read(struct pakfire_archive* archive, const char* filename);
-int pakfire_archive_extract(struct pakfire_archive* archive);
+int pakfire_archive_extract(struct pakfire_archive* archive,
+ const char* path, const int flags);
const char* pakfire_archive_get_path(struct pakfire_archive* archive);
return 1;
}
+ const char* path = pakfire_get_path(pakfire);
+
struct archive* archive = archive_read_new();
if (!archive)
return 1;
}
// Extract snapshot
- r = pakfire_extract(pakfire, archive, st.st_size, NULL, NULL,
+ r = pakfire_extract(pakfire, archive, st.st_size, NULL, path,
_("Restoring Snapshot"), NULL, PAKFIRE_EXTRACT_SHOW_THROUGHPUT);
if (r)
goto ERROR;
pakfire_transaction_status(transaction, _("Installing %s..."), nevra);
// Extract payload
- int r = pakfire_archive_extract(archive);
+ int r = pakfire_archive_extract(archive, NULL, 0);
if (r) {
ERROR(transaction->pakfire, "Could not extract package %s: %m\n",
nevra);
dist.add_argument("--resultdir", nargs="?",
help=_("Path were the output files should be copied to"))
+ # extract
+ extract = subparsers.add_parser("extract", help=_("Extract an archive"))
+ extract.add_argument("archive", nargs=1, help=_("The path to the archive"))
+ extract.add_argument("--path", help=_("Extract the archive into this path"))
+ extract.set_defaults(func=self._extract)
+
# info
info = subparsers.add_parser("info",
help=_("Print some information about the given package(s)"))
for pkg in pkgs:
p.dist(pkg, resultdir)
+ def _extract(self, ns):
+ # Launch Pakfire
+ p = self.pakfire(ns)
+
+ # Open the archive
+ archive = p.open(ns.archive[0])
+
+ # Extract the payload
+ archive.extract(path=ns.path)
+
# Some common functions
def _print_packages(self, packages, unique=True, long=True, **kwargs):