return ret;
}
-static PyObject* Pakfire_copy_in(PakfireObject* self, PyObject* args) {
- const char* src = NULL;
- const char* dst = NULL;
-
- if (!PyArg_ParseTuple(args, "ss", &src, &dst))
- return NULL;
-
- Py_BEGIN_ALLOW_THREADS
-
- int r = pakfire_copy_in(self->pakfire, src, dst);
- if (r) {
- Py_BLOCK_THREADS
- PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
- }
-
- Py_END_ALLOW_THREADS
-
- Py_RETURN_NONE;
-}
-
-static PyObject* Pakfire_copy_out(PakfireObject* self, PyObject* args) {
- const char* src = NULL;
- const char* dst = NULL;
-
- if (!PyArg_ParseTuple(args, "ss", &src, &dst))
- return NULL;
-
- Py_BEGIN_ALLOW_THREADS
-
- int r = pakfire_copy_out(self->pakfire, src, dst);
- if (r) {
- Py_BLOCK_THREADS
- PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
- }
-
- Py_END_ALLOW_THREADS
-
- Py_RETURN_NONE;
-}
-
static PyObject* Pakfire_get_repos(PakfireObject* self) {
struct pakfire_repolist* repos = pakfire_get_repos(self->pakfire);
if (!repos) {
METH_NOARGS,
NULL,
},
- {
- "copy_in",
- (PyCFunction)Pakfire_copy_in,
- METH_VARARGS,
- NULL,
- },
- {
- "copy_out",
- (PyCFunction)Pakfire_copy_out,
- METH_VARARGS,
- NULL,
- },
{
"dist",
(PyCFunction)Pakfire_dist,
return pakfire_repo_walk(pakfire, __pakfire_repo_refresh, &flags);
}
-enum pakfire_copy_direction {
- PAKFIRE_COPY_IN,
- PAKFIRE_COPY_OUT,
-};
-
-static int __pakfire_copy(struct pakfire* pakfire, const char* src, const char* dst,
- enum pakfire_copy_direction direction) {
- struct archive* reader = NULL;
- struct archive* writer = NULL;
- struct archive_entry* entry = NULL;
- FILE* f = NULL;
- int r = 1;
-
- DEBUG(pakfire, "Copying %s to %s\n", src, dst);
-
- // Open the source file
- f = fopen(src, "r");
- if (!f) {
- ERROR(pakfire, "Could not open %s: %m\n", src);
- goto ERROR;
- }
-
- // Allocate reader
- reader = pakfire_make_archive_disk_reader(pakfire, (direction == PAKFIRE_COPY_OUT));
- if (!reader)
- goto ERROR;
-
- // Allocate writer
- writer = pakfire_make_archive_disk_writer(pakfire, (direction == PAKFIRE_COPY_IN));
- if (!writer)
- goto ERROR;
-
- // Create a new entry
- entry = archive_entry_new();
- if (!entry)
- goto ERROR;
-
- // Set the source path
- archive_entry_copy_sourcepath(entry, src);
-
- // Set the destination path
- archive_entry_set_pathname(entry, dst);
-
- // Read everything from source file
- r = archive_read_disk_entry_from_file(reader, entry, fileno(f), NULL);
- if (r) {
- ERROR(pakfire, "Could not read from %s: %m\n", src);
- goto ERROR;
- }
-
- // Write file to destination
- r = archive_write_header(writer, entry);
- if (r) {
- ERROR(pakfire, "Could not write %s: %m\n", dst);
- goto ERROR;
- }
-
- // Copy payload
- if (archive_entry_filetype(entry) == AE_IFREG) {
- r = pakfire_archive_copy_data_from_file(pakfire, writer, f);
- if (r)
- goto ERROR;
- }
-
-ERROR:
- if (f)
- fclose(f);
- if (entry)
- archive_entry_free(entry);
- if (reader)
- archive_read_free(reader);
- if (writer)
- archive_write_free(writer);
-
- return r;
-}
-
-PAKFIRE_EXPORT int pakfire_copy_in(struct pakfire* pakfire, const char* src, const char* dst) {
- char path[PATH_MAX];
- int r;
-
- if (pakfire_on_root(pakfire)) {
- errno = ENOTSUP;
- return 1;
- }
-
- r = pakfire_path(pakfire, path, "%s", dst);
- if (r)
- return r;
-
- return __pakfire_copy(pakfire, src, path, PAKFIRE_COPY_IN);
-}
-
-PAKFIRE_EXPORT int pakfire_copy_out(struct pakfire* pakfire, const char* src, const char* dst) {
- char path[PATH_MAX];
- int r;
-
- if (pakfire_on_root(pakfire)) {
- errno = ENOTSUP;
- return 1;
- }
-
- r = pakfire_path(pakfire, path, "%s", src);
- if (r)
- return r;
-
- return __pakfire_copy(pakfire, path, dst, PAKFIRE_COPY_OUT);
-}
-
PAKFIRE_EXPORT const char* pakfire_get_arch(struct pakfire* pakfire) {
return pakfire->arches.nominal;
}