|
4 | 4 | #include "../git-compat-util.h"
|
5 | 5 | #include "../config.h"
|
6 | 6 | #include "../dir.h"
|
| 7 | +#include "../fsck.h" |
7 | 8 | #include "../gettext.h"
|
8 | 9 | #include "../hash.h"
|
9 | 10 | #include "../hex.h"
|
@@ -1748,15 +1749,58 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s
|
1748 | 1749 | return empty_ref_iterator_begin();
|
1749 | 1750 | }
|
1750 | 1751 |
|
1751 |
| -static int packed_fsck(struct ref_store *ref_store UNUSED, |
1752 |
| - struct fsck_options *o UNUSED, |
| 1752 | +static int packed_fsck(struct ref_store *ref_store, |
| 1753 | + struct fsck_options *o, |
1753 | 1754 | struct worktree *wt)
|
1754 | 1755 | {
|
| 1756 | + struct packed_ref_store *refs = packed_downcast(ref_store, |
| 1757 | + REF_STORE_READ, "fsck"); |
| 1758 | + struct stat st; |
| 1759 | + int ret = 0; |
| 1760 | + int fd = -1; |
1755 | 1761 |
|
1756 | 1762 | if (!is_main_worktree(wt))
|
1757 |
| - return 0; |
| 1763 | + goto cleanup; |
1758 | 1764 |
|
1759 |
| - return 0; |
| 1765 | + if (o->verbose) |
| 1766 | + fprintf_ln(stderr, "Checking packed-refs file %s", refs->path); |
| 1767 | + |
| 1768 | + fd = open_nofollow(refs->path, O_RDONLY); |
| 1769 | + if (fd < 0) { |
| 1770 | + /* |
| 1771 | + * If the packed-refs file doesn't exist, there's nothing |
| 1772 | + * to check. |
| 1773 | + */ |
| 1774 | + if (errno == ENOENT) |
| 1775 | + goto cleanup; |
| 1776 | + |
| 1777 | + if (errno == ELOOP) { |
| 1778 | + struct fsck_ref_report report = { 0 }; |
| 1779 | + report.path = "packed-refs"; |
| 1780 | + ret = fsck_report_ref(o, &report, |
| 1781 | + FSCK_MSG_BAD_REF_FILETYPE, |
| 1782 | + "not a regular file but a symlink"); |
| 1783 | + goto cleanup; |
| 1784 | + } |
| 1785 | + |
| 1786 | + ret = error_errno(_("unable to open '%s'"), refs->path); |
| 1787 | + goto cleanup; |
| 1788 | + } else if (fstat(fd, &st) < 0) { |
| 1789 | + ret = error_errno(_("unable to stat '%s'"), refs->path); |
| 1790 | + goto cleanup; |
| 1791 | + } else if (!S_ISREG(st.st_mode)) { |
| 1792 | + struct fsck_ref_report report = { 0 }; |
| 1793 | + report.path = "packed-refs"; |
| 1794 | + ret = fsck_report_ref(o, &report, |
| 1795 | + FSCK_MSG_BAD_REF_FILETYPE, |
| 1796 | + "not a regular file"); |
| 1797 | + goto cleanup; |
| 1798 | + } |
| 1799 | + |
| 1800 | +cleanup: |
| 1801 | + if (fd >= 0) |
| 1802 | + close(fd); |
| 1803 | + return ret; |
1760 | 1804 | }
|
1761 | 1805 |
|
1762 | 1806 | struct ref_storage_be refs_be_packed = {
|
|
0 commit comments