overwrite_check.c 511 Bytes
Newer Older
Julian Rother's avatar
Julian Rother committed
1
2
3
4
5
#include <unistd.h>
#include <sys/stat.h>

#include "../util.h"

6
void overwrite_check(char *path, char *srcpath, char *srchash)
Julian Rother's avatar
Julian Rother committed
7
8
9
10
{
	struct stat s;
	if (stat(path, &s) || !s.st_size)
		return; /* We can overwrite non-existing or empty files */
11
12
	if (srcpath && strcmp(hashfile(srcpath), srchash))
		job_failed("Refusing to overwrite output file \"%s\": Source file hash mismatch", path);
Julian Rother's avatar
Julian Rother committed
13
	if (s.st_uid != getuid())
Julian Rother's avatar
Julian Rother committed
14
		job_failed("Refusing to overwrite output file \"%s\": File was not created by worker", path);
Julian Rother's avatar
Julian Rother committed
15
16
}