publish_video.c 909 Bytes
Newer Older
Julian Rother's avatar
Julian Rother committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <unistd.h>
#include <libgen.h>
#include <sys/stat.h>

#include "util.h"

int main(int argc, char *argv[])
{
	char *src, *dest, *destdir;
	if (argc != 5)
		return 1;
	av_register_all();
	init_env();
	init_avlogbuf();
	jobid = atoi(argv[1]);
Julian Rother's avatar
Julian Rother committed
16 17
	src = buildpath(getenv(WORKER_TMP), jstr(jlookup(argv[4], "source"), 0));
	dest = buildpath(getenv(WORKER_RELEASED), jstr(jlookup(argv[4], "path"), 0));
Julian Rother's avatar
Julian Rother committed
18 19 20 21 22 23 24 25 26 27 28
	destdir = dirname(mprintf("%s/%s", getenv(WORKER_RELEASED), jstr(jlookup(argv[4], "path"), "")));
	ping_job(jobid, "running", 0);
	overwrite_check(dest, 0, 0);
	if (mkdir(destdir, 02775) && errno != EEXIST)
		job_failed("Could not create target directory \"%s\": %s", destdir, strerror(errno));
	if (rename(src, dest))
		job_failed("Overwriting target file failed: %s", strerror(errno));
	ping_job(jobid, "finished", "{%s, \"log\": \"%s\"}",
			json_fileinfo(dest), jescape(get_avlogbuf()));
	return 0;
}