Make sure errno contains a meaningful value on error */
| 163 | |
| 164 | /* Make sure errno contains a meaningful value on error */ |
| 165 | static int lock_file(struct lock_file *lk, const char *path, int flags, |
| 166 | int mode) |
| 167 | { |
| 168 | struct strbuf base_path = STRBUF_INIT; |
| 169 | struct strbuf lock_path = STRBUF_INIT; |
| 170 | struct strbuf pid_path = STRBUF_INIT; |
| 171 | |
| 172 | strbuf_addstr(&base_path, path); |
| 173 | if (!(flags & LOCK_NO_DEREF)) |
| 174 | resolve_symlink(&base_path); |
| 175 | |
| 176 | get_lock_path(&lock_path, base_path.buf); |
| 177 | get_pid_path(&pid_path, base_path.buf); |
| 178 | |
| 179 | lk->tempfile = create_tempfile_mode(lock_path.buf, mode); |
| 180 | if (lk->tempfile) |
| 181 | lk->pid_tempfile = create_lock_pid_file(pid_path.buf, mode); |
| 182 | |
| 183 | strbuf_release(&base_path); |
| 184 | strbuf_release(&lock_path); |
| 185 | strbuf_release(&pid_path); |
| 186 | return lk->tempfile ? lk->tempfile->fd : -1; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Constants defining the gaps between attempts to lock a file. The |
no test coverage detected