[PATCH] Various transport programs
[alt-git.git] / check-files.c
blob7d16691aa9d51b5b4670d5837b3527ee7c7da79c
1 /*
2 * check-files.c
4 * Check that a set of files are up-to-date in the filesystem or
5 * do not exist. Used to verify a patch target before doing a patch.
7 * Copyright (C) 2005 Linus Torvalds
8 */
9 #include "cache.h"
11 static void check_file(const char *path)
13 int fd = open(path, O_RDONLY);
14 struct cache_entry *ce;
15 struct stat st;
16 int pos, changed;
18 /* Nonexistent is fine */
19 if (fd < 0) {
20 if (errno != ENOENT)
21 die("%s: %s", path, strerror(errno));
22 return;
25 /* Exists but is not in the cache is not fine */
26 pos = cache_name_pos(path, strlen(path));
27 if (pos < 0)
28 die("preparing to update existing file '%s' not in cache", path);
29 ce = active_cache[pos];
31 if (fstat(fd, &st) < 0)
32 die("fstat(%s): %s", path, strerror(errno));
34 changed = cache_match_stat(ce, &st);
35 if (changed)
36 die("preparing to update file '%s' not uptodate in cache", path);
39 int main(int argc, char **argv)
41 int i;
43 read_cache();
44 for (i = 1; i < argc ; i++)
45 check_file(argv[i]);
46 return 0;