2 * Copyright (c) 2005, Junio C Hamano
7 static struct cache_file *cache_file_list;
9 static void remove_lock_file(void)
11 while (cache_file_list) {
12 if (cache_file_list->lockfile[0])
13 unlink(cache_file_list->lockfile);
14 cache_file_list = cache_file_list->next;
18 static void remove_lock_file_on_signal(int signo)
23 int hold_index_file_for_update(struct cache_file *cf, const char *path)
26 sprintf(cf->lockfile, "%s.lock", path);
27 fd = open(cf->lockfile, O_RDWR | O_CREAT | O_EXCL, 0666);
28 if (fd >=0 && !cf->next) {
29 cf->next = cache_file_list;
31 signal(SIGINT, remove_lock_file_on_signal);
32 atexit(remove_lock_file);
37 int commit_index_file(struct cache_file *cf)
39 char indexfile[PATH_MAX];
41 strcpy(indexfile, cf->lockfile);
42 i = strlen(indexfile) - 5; /* .lock */
44 i = rename(cf->lockfile, indexfile);
49 void rollback_index_file(struct cache_file *cf)