| 1808 | } |
| 1809 | |
| 1810 | static int commit_ref(struct ref_lock *lock) |
| 1811 | { |
| 1812 | char *path = get_locked_file_path(&lock->lk); |
| 1813 | struct stat st; |
| 1814 | |
| 1815 | if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { |
| 1816 | /* |
| 1817 | * There is a directory at the path we want to rename |
| 1818 | * the lockfile to. Hopefully it is empty; try to |
| 1819 | * delete it. |
| 1820 | */ |
| 1821 | size_t len = strlen(path); |
| 1822 | struct strbuf sb_path = STRBUF_INIT; |
| 1823 | |
| 1824 | strbuf_attach(&sb_path, path, len, len + 1); |
| 1825 | |
| 1826 | /* |
| 1827 | * If this fails, commit_lock_file() will also fail |
| 1828 | * and will report the problem. |
| 1829 | */ |
| 1830 | remove_empty_directories(&sb_path); |
| 1831 | strbuf_release(&sb_path); |
| 1832 | } else { |
| 1833 | free(path); |
| 1834 | } |
| 1835 | |
| 1836 | if (commit_lock_file(&lock->lk)) |
| 1837 | return -1; |
| 1838 | return 0; |
| 1839 | } |
| 1840 | |
| 1841 | static int open_or_create_logfile(const char *path, void *cb) |
| 1842 | { |
no test coverage detected