MCPcopy Create free account
hub / github.com/apache/cloudberry / tar_close

Function tar_close

src/bin/pg_basebackup/walmethods.c:836–1005  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834}
835
836static int
837tar_close(Walfile f, WalCloseMethod method)
838{
839 ssize_t filesize;
840 int padding;
841 TarMethodFile *tf = (TarMethodFile *) f;
842
843 Assert(f != NULL);
844 tar_clear_error();
845
846 if (method == CLOSE_UNLINK)
847 {
848 if (tar_data->compression)
849 {
850 tar_set_error("unlink not supported with compression");
851 return -1;
852 }
853
854 /*
855 * Unlink the file that we just wrote to the tar. We do this by
856 * truncating it to the start of the header. This is safe as we only
857 * allow writing of the very last file.
858 */
859 if (ftruncate(tar_data->fd, tf->ofs_start) != 0)
860 {
861 tar_data->lasterrno = errno;
862 return -1;
863 }
864
865 pg_free(tf->pathname);
866 pg_free(tf);
867 tar_data->currentfile = NULL;
868
869 return 0;
870 }
871
872 /*
873 * Pad the file itself with zeroes if necessary. Note that this is
874 * different from the tar format padding -- this is the padding we asked
875 * for when the file was opened.
876 */
877 if (tf->pad_to_size)
878 {
879 if (tar_data->compression)
880 {
881 /*
882 * A compressed tarfile is padded on close since we cannot know
883 * the size of the compressed output until the end.
884 */
885 size_t sizeleft = tf->pad_to_size - tf->currpos;
886
887 if (sizeleft)
888 {
889 if (!tar_write_padding_data(tf, sizeleft))
890 return -1;
891 }
892 }
893 else

Callers 1

tar_finishFunction · 0.85

Calls 11

pg_freeFunction · 0.85
tar_write_padding_dataFunction · 0.85
tar_get_current_posFunction · 0.85
tarPaddingBytesRequiredFunction · 0.85
tar_writeFunction · 0.85
print_tar_numberFunction · 0.85
strlcpyFunction · 0.85
tarChecksumFunction · 0.85
tar_syncFunction · 0.85
tar_getlasterrorFunction · 0.85

Tested by

no test coverage detected