* Given the member, write the TAR header & send the file. * * If 'missing_ok' is true, will not throw an error if the file is not found. * * If dboid is anything other than InvalidOid then any checksum failures detected * will get reported to the stats collector. * * Returns true if the file was successfully sent, false if 'missing_ok', * and the file did not exist. */
| 1773 | * and the file did not exist. |
| 1774 | */ |
| 1775 | static bool |
| 1776 | sendFile(const char *readfilename, const char *tarfilename, |
| 1777 | struct stat *statbuf, bool missing_ok, Oid dboid, |
| 1778 | backup_manifest_info *manifest, const char *spcoid) |
| 1779 | { |
| 1780 | int fd; |
| 1781 | BlockNumber blkno = 0; |
| 1782 | bool block_retry = false; |
| 1783 | char buf[TAR_SEND_SIZE]; |
| 1784 | uint16 checksum; |
| 1785 | int checksum_failures = 0; |
| 1786 | off_t cnt; |
| 1787 | int i; |
| 1788 | pgoff_t len = 0; |
| 1789 | char *page; |
| 1790 | size_t pad; |
| 1791 | PageHeader phdr; |
| 1792 | int segmentno = 0; |
| 1793 | char *segmentpath; |
| 1794 | bool verify_checksum = false; |
| 1795 | pg_checksum_context checksum_ctx; |
| 1796 | |
| 1797 | if (pg_checksum_init(&checksum_ctx, manifest->checksum_type) < 0) |
| 1798 | elog(ERROR, "could not initialize checksum of file \"%s\"", |
| 1799 | readfilename); |
| 1800 | |
| 1801 | fd = OpenTransientFile(readfilename, O_RDONLY | PG_BINARY); |
| 1802 | if (fd < 0) |
| 1803 | { |
| 1804 | if (errno == ENOENT && missing_ok) |
| 1805 | return false; |
| 1806 | ereport(ERROR, |
| 1807 | (errcode_for_file_access(), |
| 1808 | errmsg("could not open file \"%s\": %m", readfilename))); |
| 1809 | } |
| 1810 | |
| 1811 | _tarWriteHeader(tarfilename, NULL, statbuf, false); |
| 1812 | |
| 1813 | if (!noverify_checksums && DataChecksumsEnabled()) |
| 1814 | { |
| 1815 | char *filename; |
| 1816 | |
| 1817 | /* |
| 1818 | * Get the filename (excluding path). As last_dir_separator() |
| 1819 | * includes the last directory separator, we chop that off by |
| 1820 | * incrementing the pointer. |
| 1821 | */ |
| 1822 | filename = last_dir_separator(readfilename) + 1; |
| 1823 | |
| 1824 | if (is_checksummed_file(readfilename, filename)) |
| 1825 | { |
| 1826 | verify_checksum = true; |
| 1827 | |
| 1828 | /* |
| 1829 | * Cut off at the segment boundary (".") to get the segment number |
| 1830 | * in order to mix it into the checksum. |
| 1831 | */ |
| 1832 | segmentpath = strstr(filename, "."); |
no test coverage detected