-static int write_entry(struct cache_entry *ce, const char *path)
-{
- int fd;
- void *new;
- unsigned long size;
- long wrote;
- char type[20];
-
- new = read_sha1_file(ce->sha1, type, &size);
- if (!new || strcmp(type, "blob")) {
- return error("checkout-cache: unable to read sha1 file of %s (%s)",
- path, sha1_to_hex(ce->sha1));
- }
- fd = create_file(path, ntohl(ce->ce_mode));
- if (fd < 0) {
- free(new);
- return error("checkout-cache: unable to create %s (%s)",
- path, strerror(errno));
- }
- wrote = write(fd, new, size);
- close(fd);
- free(new);
- if (wrote != size)
- return error("checkout-cache: unable to write %s", path);
- return 0;
-}
-
-static int checkout_entry(struct cache_entry *ce, const char *base_dir)
-{
- struct stat st;
- static char path[MAXPATHLEN+1];
- int len = strlen(base_dir);
-
- memcpy(path, base_dir, len);
- strcpy(path + len, ce->name);
-
- if (!stat(path, &st)) {
- unsigned changed = cache_match_stat(ce, &st);
- if (!changed)
- return 0;
- if (!force) {
- if (!quiet)
- fprintf(stderr, "checkout-cache: %s already exists\n", path);
- return 0;
- }
-
- /*
- * We unlink the old file, to get the new one with the
- * right permissions (including umask, which is nasty
- * to emulate by hand - much easier to let the system
- * just do the right thing)
- */
- unlink(path);
- }
- return write_entry(ce, path);
-}
-
-static int checkout_file(const char *name, const char *base_dir)