/* * Copyright (c) 2005, Junio C Hamano */ #include "git-compat-util.h" #include "abspath.h" #include "gettext.h" #include "lockfile.h" /* * path = absolute or relative path name * * Remove the last path name element from path (leaving the preceding * "/", if any). If path is empty or the root directory ("/"), set * path to the empty string. */ static void trim_last_path_component(struct strbuf *path) { … } /* We allow "recursive" symbolic links. Only within reason, though */ #define MAXDEPTH … /* * path contains a path that might be a symlink. * * If path is a symlink, attempt to overwrite it with a path to the * real file or directory (which may or may not exist), following a * chain of symlinks if necessary. Otherwise, leave path unmodified. * * This is a best-effort routine. If an error occurs, path will * either be left unmodified or will name a different symlink in a * symlink chain that started with the original path. */ static void resolve_symlink(struct strbuf *path) { … } /* Make sure errno contains a meaningful value on error */ static int lock_file(struct lock_file *lk, const char *path, int flags, int mode) { … } /* * Constants defining the gaps between attempts to lock a file. The * first backoff period is approximately INITIAL_BACKOFF_MS * milliseconds. The longest backoff period is approximately * (BACKOFF_MAX_MULTIPLIER * INITIAL_BACKOFF_MS) milliseconds. */ #define INITIAL_BACKOFF_MS … #define BACKOFF_MAX_MULTIPLIER … /* * Try locking path, retrying with quadratic backoff for at least * timeout_ms milliseconds. If timeout_ms is 0, try locking the file * exactly once. If timeout_ms is -1, try indefinitely. */ static int lock_file_timeout(struct lock_file *lk, const char *path, int flags, long timeout_ms, int mode) { … } void unable_to_lock_message(const char *path, int err, struct strbuf *buf) { … } NORETURN void unable_to_lock_die(const char *path, int err) { … } /* This should return a meaningful errno on failure */ int hold_lock_file_for_update_timeout_mode(struct lock_file *lk, const char *path, int flags, long timeout_ms, int mode) { … } char *get_locked_file_path(struct lock_file *lk) { … } int commit_lock_file(struct lock_file *lk) { … }