1/* 2 * check-files.c 3 * 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. 6 * 7 * Copyright (C) 2005 Linus Torvalds 8 */ 9#include"cache.h" 10 11static voidcheck_file(const char*path) 12{ 13int fd =open(path, O_RDONLY); 14struct cache_entry *ce; 15struct stat st; 16int pos, changed; 17 18/* Nonexistent is fine */ 19if(fd <0) { 20if(errno != ENOENT) 21die("%s:%s", path,strerror(errno)); 22return; 23} 24 25/* Exists but is not in the cache is not fine */ 26 pos =cache_name_pos(path,strlen(path)); 27if(pos <0) 28die("preparing to update existing file '%s' not in cache", path); 29 ce = active_cache[pos]; 30 31if(lstat(path, &st) <0) 32die("lstat(%s):%s", path,strerror(errno)); 33 34 changed =ce_match_stat(ce, &st); 35if(changed) 36die("preparing to update file '%s' not uptodate in cache", path); 37} 38 39intmain(int argc,char**argv) 40{ 41int i; 42 43read_cache(); 44for(i =1; i < argc ; i++) 45check_file(argv[i]); 46return0; 47}