pull-tar.c revision 25300b5a1fcf54674a69d0f4ab08925be00b0227
/*-*- 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 "sd-daemon.h"
#include "utf8.h"
#include "strv.h"
#include "copy.h"
#include "btrfs-util.h"
#include "util.h"
#include "macro.h"
#include "mkdir.h"
#include "rm-rf.h"
#include "path-util.h"
#include "process-util.h"
#include "hostname-util.h"
#include "import-util.h"
#include "import-common.h"
#include "curl-util.h"
#include "pull-job.h"
#include "pull-common.h"
#include "pull-tar.h"
typedef enum TarProgress {
} TarProgress;
struct TarPull {
char *image_root;
void *userdata;
char *local;
bool force_local;
bool grow_machine_directory;
char *temp_path;
char *final_path;
};
if (!i)
return NULL;
if (i->tar_pid > 1) {
}
pull_job_unref(i->tar_job);
curl_glue_unref(i->glue);
sd_event_unref(i->event);
if (i->temp_path) {
}
free(i->final_path);
free(i->image_root);
free(i);
return NULL;
}
int tar_pull_new(
const char *image_root,
void *userdata) {
int r;
if (!i)
return -ENOMEM;
i->on_finished = on_finished;
if (!i->image_root)
return -ENOMEM;
if (r < 0)
return r;
*ret = i;
i = NULL;
return 0;
}
unsigned percent;
assert(i);
switch (p) {
case TAR_DOWNLOADING: {
unsigned remain = 85;
percent = 0;
if (i->checksum_job) {
remain -= 5;
}
if (i->signature_job) {
remain -= 5;
}
if (i->tar_job)
break;
}
case TAR_VERIFYING:
percent = 85;
break;
case TAR_FINALIZING:
percent = 90;
break;
case TAR_COPYING:
percent = 95;
break;
default:
assert_not_reached("Unknown progress state");
}
}
static int tar_pull_make_local_copy(TarPull *i) {
int r;
assert(i);
if (!i->local)
return 0;
if (!i->final_path) {
r = pull_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 bool tar_pull_is_done(TarPull *i) {
assert(i);
return false;
return false;
return false;
return true;
}
static void tar_pull_job_on_finished(PullJob *j) {
TarPull *i;
int r;
assert(j);
i = j->userdata;
if (j->error != 0) {
if (j == i->checksum_job)
else if (j == i->signature_job)
else
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 (!tar_pull_is_done(i))
return;
if (i->tar_pid > 0) {
i->tar_pid = 0;
if (r < 0)
goto finish;
}
if (!i->tar_job->etag_exists) {
/* This is a new download, verify it, and move it into place */
if (r < 0)
goto finish;
r = import_make_read_only(i->temp_path);
if (r < 0)
goto finish;
if (r < 0) {
log_error_errno(r, "Failed to rename to final image name: %m");
goto finish;
}
}
r = tar_pull_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_pull_job_on_open_disk(PullJob *j) {
TarPull *i;
int r;
assert(j);
i = j->userdata;
assert(!i->final_path);
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 (j->disk_fd < 0)
return j->disk_fd;
return 0;
}
static void tar_pull_job_on_progress(PullJob *j) {
TarPull *i;
assert(j);
i = j->userdata;
}
int tar_pull_start(TarPull *i, const char *url, const char *local, bool force_local, ImportVerify verify) {
int r;
assert(i);
if (!http_url_is_valid(url))
return -EINVAL;
return -EINVAL;
if (i->tar_job)
return -EBUSY;
if (r < 0)
return r;
i->force_local = force_local;
if (r < 0)
return r;
if (r < 0)
return r;
r = pull_make_verification_jobs(&i->checksum_job, &i->signature_job, verify, url, i->glue, tar_pull_job_on_finished, i);
if (r < 0)
return r;
r = pull_job_begin(i->tar_job);
if (r < 0)
return r;
if (i->checksum_job) {
r = pull_job_begin(i->checksum_job);
if (r < 0)
return r;
}
if (i->signature_job) {
r = pull_job_begin(i->signature_job);
if (r < 0)
return r;
}
return 0;
}