publish_video.c 924 Bytes
Newer Older
Julian Rother's avatar
Julian Rother committed
1 2 3 4 5 6 7 8 9 10 11 12
#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();
13
	umask(S_IWOTH);
Julian Rother's avatar
Julian Rother committed
14 15 16
	init_env();
	init_avlogbuf();
	jobid = atoi(argv[1]);
17
	ping_job(jobid, "running", 0);
Julian Rother's avatar
Julian Rother committed
18
	src = buildpath(getenv(WORKER_TMP), jstr(jlookup(argv[4], "source"), 0));
19
	destdir = buildpath(getenv(WORKER_RELEASED), dirname(jstr(jlookup(argv[4], "path"), 0)));
20
	if (access(destdir, F_OK) && mkdir(destdir, 02775))
Julian Rother's avatar
Julian Rother committed
21
		job_failed("Could not create target directory \"%s\": %s", destdir, strerror(errno));
22 23
	dest = buildpath(getenv(WORKER_RELEASED), jstr(jlookup(argv[4], "path"), 0));
	overwrite_check(dest, 0, 0);
Julian Rother's avatar
Julian Rother committed
24 25 26 27 28 29
	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;
}