import-tar.c revision 0d6e763b48cabe8899a20823b015c9a988e38659
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2015 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "utf8.h"
#include "strv.h"
#include "copy.h"
#include "btrfs-util.h"
#include "util.h"
#include "macro.h"
#include "mkdir.h"
#include "curl-util.h"
#include "import-job.h"
#include "import-util.h"
#include "import-tar.h"
struct TarImport {
char *image_root;
void *userdata;
char *local;
bool force_local;
char *temp_path;
char *final_path;
};
if (!i)
return NULL;
if (i->tar_pid > 0) {
}
import_job_unref(i->tar_job);
curl_glue_unref(i->glue);
sd_event_unref(i->event);
if (i->temp_path) {
(void) btrfs_subvol_remove(i->temp_path);
(void) rm_rf_dangerous(i->temp_path, false, true, false);
}
free(i->final_path);
free(i->image_root);
free(i);
return NULL;
}
int tar_import_new(TarImport **ret, sd_event *event, const char *image_root, TarImportFinished on_finished, void *userdata) {
int r;
if (!i)
return -ENOMEM;
i->on_finished = on_finished;
if (!i->image_root)
return -ENOMEM;
if (event)
else {
r = sd_event_default(&i->event);
if (r < 0)
return r;
}
if (r < 0)
return r;
*ret = i;
i = NULL;
return 0;
}
static int tar_import_make_local_copy(TarImport *i) {
int r;
assert(i);
if (!i->local)
return 0;
if (!i->final_path) {
r = import_make_path(i->tar_job->url, i->tar_job->etag, i->image_root, ".tar-", NULL, &i->final_path);
if (r < 0)
return log_oom();
if (r < 0)
return r;
}
return 0;
}
static void tar_import_job_on_finished(ImportJob *j) {
TarImport *i;
int r;
assert(j);
i = j->userdata;
if (j->error != 0) {
r = j->error;
goto finish;
}
/* This is invoked if either the download completed
* successfully, or the download was skipped because we
* already have the etag. */
if (i->tar_pid > 0) {
i->tar_pid = 0;
if (r < 0)
goto finish;
}
if (i->temp_path) {
r = import_make_read_only(i->temp_path);
if (r < 0)
goto finish;
goto finish;
}
}
r = tar_import_make_local_copy(i);
if (r < 0)
goto finish;
r = 0;
if (i->on_finished)
i->on_finished(i, r, i->userdata);
else
sd_event_exit(i->event, r);
}
static int tar_import_job_on_open_disk(ImportJob *j) {
TarImport *i;
int r;
assert(j);
i = j->userdata;
if (r < 0)
return log_oom();
if (r < 0)
return log_oom();
r = btrfs_subvol_make(i->temp_path);
if (r == -ENOTTY) {
} else if (r < 0)
if (i->tar_pid < 0)
if (i->tar_pid == 0) {
int null_fd;
}
if (pipefd[0] != STDIN_FILENO)
safe_close(pipefd[0]);
if (null_fd < 0) {
}
}
if (null_fd != STDOUT_FILENO)
}
return 0;
}
int r;
assert(i);
if (i->tar_job)
return -EBUSY;
if (!http_url_is_valid(url))
return -EINVAL;
return -EINVAL;
if (r < 0)
return r;
i->force_local = force_local;
if (r < 0)
return r;
if (r < 0)
return r;
return import_job_begin(i->tar_job);
}