| 834 | } |
| 835 | |
| 836 | static int |
| 837 | tar_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 |
no test coverage detected