@@ -749,7 +749,7 @@ tar_write(Walfile f, const void *buf, size_t count)
749
749
tar_clear_error ();
750
750
751
751
/* Tarfile will always be positioned at the end */
752
- if (! tar_data -> compression_level )
752
+ if (tar_data -> compression_method == COMPRESSION_NONE )
753
753
{
754
754
errno = 0 ;
755
755
r = write (tar_data -> fd , buf , count );
@@ -763,21 +763,20 @@ tar_write(Walfile f, const void *buf, size_t count)
763
763
return r ;
764
764
}
765
765
#ifdef HAVE_LIBZ
766
- else
766
+ else if ( tar_data -> compression_method == COMPRESSION_GZIP )
767
767
{
768
768
if (!tar_write_compressed_data (unconstify (void * , buf ), count , false))
769
769
return -1 ;
770
770
((TarMethodFile * ) f )-> currpos += count ;
771
771
return count ;
772
772
}
773
- #else
773
+ #endif
774
774
else
775
775
{
776
- /* Can't happen - compression enabled with no libz */
776
+ /* Can't happen - compression enabled with no method set */
777
777
tar_data -> lasterrno = ENOSYS ;
778
778
return -1 ;
779
779
}
780
- #endif
781
780
}
782
781
783
782
static bool
@@ -833,7 +832,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
833
832
}
834
833
835
834
#ifdef HAVE_LIBZ
836
- if (tar_data -> compression_level )
835
+ if (tar_data -> compression_method == COMPRESSION_GZIP )
837
836
{
838
837
tar_data -> zp = (z_streamp ) pg_malloc (sizeof (z_stream ));
839
838
tar_data -> zp -> zalloc = Z_NULL ;
@@ -884,7 +883,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
884
883
pg_free (tmppath );
885
884
886
885
#ifdef HAVE_LIBZ
887
- if (tar_data -> compression_level )
886
+ if (tar_data -> compression_method == COMPRESSION_GZIP )
888
887
{
889
888
/* Flush existing data */
890
889
if (!tar_write_compressed_data (NULL , 0 , true))
@@ -909,7 +908,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
909
908
}
910
909
tar_data -> currentfile -> currpos = 0 ;
911
910
912
- if (! tar_data -> compression_level )
911
+ if (tar_data -> compression_method == COMPRESSION_NONE )
913
912
{
914
913
errno = 0 ;
915
914
if (write (tar_data -> fd , tar_data -> currentfile -> header ,
@@ -923,7 +922,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
923
922
}
924
923
}
925
924
#ifdef HAVE_LIBZ
926
- else
925
+ else if ( tar_data -> compression_method == COMPRESSION_GZIP )
927
926
{
928
927
/* Write header through the zlib APIs but with no compression */
929
928
if (!tar_write_compressed_data (tar_data -> currentfile -> header ,
@@ -938,6 +937,11 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
938
937
}
939
938
}
940
939
#endif
940
+ else
941
+ {
942
+ /* not reachable */
943
+ Assert (false);
944
+ }
941
945
942
946
tar_data -> currentfile -> pathname = pg_strdup (pathname );
943
947
@@ -948,7 +952,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
948
952
if (pad_to_size )
949
953
{
950
954
tar_data -> currentfile -> pad_to_size = pad_to_size ;
951
- if (! tar_data -> compression_level )
955
+ if (tar_data -> compression_method == COMPRESSION_NONE )
952
956
{
953
957
/* Uncompressed, so pad now */
954
958
if (!tar_write_padding_data (tar_data -> currentfile , pad_to_size ))
@@ -1009,7 +1013,7 @@ tar_sync(Walfile f)
1009
1013
* Always sync the whole tarfile, because that's all we can do. This makes
1010
1014
* no sense on compressed files, so just ignore those.
1011
1015
*/
1012
- if (tar_data -> compression_level )
1016
+ if (tar_data -> compression_method != COMPRESSION_NONE )
1013
1017
return 0 ;
1014
1018
1015
1019
r = fsync (tar_data -> fd );
@@ -1030,7 +1034,7 @@ tar_close(Walfile f, WalCloseMethod method)
1030
1034
1031
1035
if (method == CLOSE_UNLINK )
1032
1036
{
1033
- if (tar_data -> compression_level )
1037
+ if (tar_data -> compression_method != COMPRESSION_NONE )
1034
1038
{
1035
1039
tar_set_error ("unlink not supported with compression" );
1036
1040
return -1 ;
@@ -1061,7 +1065,7 @@ tar_close(Walfile f, WalCloseMethod method)
1061
1065
*/
1062
1066
if (tf -> pad_to_size )
1063
1067
{
1064
- if (tar_data -> compression_level )
1068
+ if (tar_data -> compression_method == COMPRESSION_GZIP )
1065
1069
{
1066
1070
/*
1067
1071
* A compressed tarfile is padded on close since we cannot know
@@ -1102,7 +1106,7 @@ tar_close(Walfile f, WalCloseMethod method)
1102
1106
1103
1107
1104
1108
#ifdef HAVE_LIBZ
1105
- if (tar_data -> compression_level )
1109
+ if (tar_data -> compression_method == COMPRESSION_GZIP )
1106
1110
{
1107
1111
/* Flush the current buffer */
1108
1112
if (!tar_write_compressed_data (NULL , 0 , true))
@@ -1131,7 +1135,7 @@ tar_close(Walfile f, WalCloseMethod method)
1131
1135
tar_data -> lasterrno = errno ;
1132
1136
return -1 ;
1133
1137
}
1134
- if (! tar_data -> compression_level )
1138
+ if (tar_data -> compression_method == COMPRESSION_NONE )
1135
1139
{
1136
1140
errno = 0 ;
1137
1141
if (write (tar_data -> fd , tf -> header , TAR_BLOCK_SIZE ) != TAR_BLOCK_SIZE )
@@ -1142,7 +1146,7 @@ tar_close(Walfile f, WalCloseMethod method)
1142
1146
}
1143
1147
}
1144
1148
#ifdef HAVE_LIBZ
1145
- else
1149
+ else if ( tar_data -> compression_method == COMPRESSION_GZIP )
1146
1150
{
1147
1151
/* Turn off compression */
1148
1152
if (deflateParams (tar_data -> zp , 0 , 0 ) != Z_OK )
@@ -1164,6 +1168,11 @@ tar_close(Walfile f, WalCloseMethod method)
1164
1168
}
1165
1169
}
1166
1170
#endif
1171
+ else
1172
+ {
1173
+ /* not reachable */
1174
+ Assert (false);
1175
+ }
1167
1176
1168
1177
/* Move file pointer back down to end, so we can write the next file */
1169
1178
if (lseek (tar_data -> fd , 0 , SEEK_END ) < 0 )
@@ -1212,7 +1221,7 @@ tar_finish(void)
1212
1221
1213
1222
/* A tarfile always ends with two empty blocks */
1214
1223
MemSet (zerobuf , 0 , sizeof (zerobuf ));
1215
- if (! tar_data -> compression_level )
1224
+ if (tar_data -> compression_method == COMPRESSION_NONE )
1216
1225
{
1217
1226
errno = 0 ;
1218
1227
if (write (tar_data -> fd , zerobuf , sizeof (zerobuf )) != sizeof (zerobuf ))
@@ -1223,7 +1232,7 @@ tar_finish(void)
1223
1232
}
1224
1233
}
1225
1234
#ifdef HAVE_LIBZ
1226
- else
1235
+ else if ( tar_data -> compression_method == COMPRESSION_GZIP )
1227
1236
{
1228
1237
if (!tar_write_compressed_data (zerobuf , sizeof (zerobuf ), false))
1229
1238
return false;
@@ -1268,6 +1277,11 @@ tar_finish(void)
1268
1277
}
1269
1278
}
1270
1279
#endif
1280
+ else
1281
+ {
1282
+ /* not reachable */
1283
+ Assert (false);
1284
+ }
1271
1285
1272
1286
/* sync the empty blocks as well, since they're after the last file */
1273
1287
if (tar_data -> sync )
@@ -1312,7 +1326,8 @@ CreateWalTarMethod(const char *tarbase,
1312
1326
int compression_level , bool sync )
1313
1327
{
1314
1328
WalWriteMethod * method ;
1315
- const char * suffix = (compression_level != 0 ) ? ".tar.gz" : ".tar" ;
1329
+ const char * suffix = (compression_method == COMPRESSION_GZIP ) ?
1330
+ ".tar.gz" : ".tar" ;
1316
1331
1317
1332
method = pg_malloc0 (sizeof (WalWriteMethod ));
1318
1333
method -> open_for_write = tar_open_for_write ;
@@ -1335,7 +1350,7 @@ CreateWalTarMethod(const char *tarbase,
1335
1350
tar_data -> compression_level = compression_level ;
1336
1351
tar_data -> sync = sync ;
1337
1352
#ifdef HAVE_LIBZ
1338
- if (compression_level )
1353
+ if (compression_method == COMPRESSION_GZIP )
1339
1354
tar_data -> zlibOut = (char * ) pg_malloc (ZLIB_OUT_SIZE + 1 );
1340
1355
#endif
1341
1356
@@ -1347,7 +1362,7 @@ FreeWalTarMethod(void)
1347
1362
{
1348
1363
pg_free (tar_data -> tarfilename );
1349
1364
#ifdef HAVE_LIBZ
1350
- if (tar_data -> compression_level )
1365
+ if (tar_data -> compression_method == COMPRESSION_GZIP )
1351
1366
pg_free (tar_data -> zlibOut );
1352
1367
#endif
1353
1368
pg_free (tar_data );
0 commit comments