425
428
/* Check if the file shrunk when we updated it. */
426
429
if (action == ACTION_UPDATE)
427
430
#ifdef HAVE_FTRUNCATE
428
ftruncate (jarfd, lseek (jarfd, 0, SEEK_CUR));
431
if (-1 == ftruncate (jarfd, lseek (jarfd, 0, SEEK_CUR)))
432
exit_on_error("ftruncate");
430
434
_chsize (jarfd, lseek (jarfd, 0, SEEK_CUR));
462
466
create_central_header(jarfd);
464
468
#ifdef HAVE_FTRUNCATE
465
ftruncate (jarfd, lseek (jarfd, 0, SEEK_CUR));
469
if (-1 == ftruncate (jarfd, lseek (jarfd, 0, SEEK_CUR)))
470
exit_on_error("ftruncate");
467
472
_chsize (jarfd, lseek (jarfd, 0, SEEK_CUR));
812
819
size_t nlen; /* length of file name */
813
820
int mod_time; /* file modification time */
814
821
struct zipentry *ze;
816
nlen = 9; /* trust me on this one */
818
memset((file_header + 12), '\0', 16); /*clear mod time, crc, size fields*/
820
current_time = time(NULL);
821
if(current_time == (time_t)-1){
826
mod_time = unix2dostime(¤t_time);
828
PACK_UB2(file_header, LOC_EXTRA, 0);
829
PACK_UB2(file_header, LOC_COMP, 0);
830
PACK_UB2(file_header, LOC_FNLEN, nlen);
831
PACK_UB4(file_header, LOC_MODTIME, mod_time);
834
printf("adding: META-INF/ (in=0) (out=0) (stored 0%%)\n");
836
ze = (zipentry*)malloc(sizeof(zipentry));
842
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
843
ze->filename = strdup("META-INF/");
844
if (NULL == ze->filename) {
849
ze->offset = lseek(jfd, 0, SEEK_CUR);
850
ze->mod_time = (ub2)(mod_time & 0x0000ffff);
851
ze->mod_date = (ub2)((mod_time & 0xffff0000) >> 16);
852
ze->compressed = FALSE;
856
write(jfd, file_header, 30);
857
write(jfd, "META-INF/", nlen);
823
mod_time = unix2dostime(¤t_time);
825
/* If we are creating a new manifest, create a META-INF directory entry */
827
nlen = 9; /* trust me on this one */
829
memset((file_header + 12), '\0', 16); /*clear mod time, crc, size fields*/
831
current_time = time(NULL);
832
if(current_time == (time_t)-1)
833
exit_on_error("time");
835
PACK_UB2(file_header, LOC_EXTRA, 0);
836
PACK_UB2(file_header, LOC_COMP, 0);
837
PACK_UB2(file_header, LOC_FNLEN, nlen);
838
PACK_UB4(file_header, LOC_MODTIME, mod_time);
841
printf("adding: META-INF/ (in=0) (out=0) (stored 0%%)\n");
843
ze = (zipentry*)malloc(sizeof(zipentry));
845
exit_on_error("malloc");
847
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
848
ze->filename = strdup("META-INF/");
849
if (NULL == ze->filename)
850
exit_on_error("strdup");
852
ze->offset = lseek(jfd, 0, SEEK_CUR);
853
ze->mod_time = (ub2)(mod_time & 0x0000ffff);
854
ze->mod_date = (ub2)((mod_time & 0xffff0000) >> 16);
855
ze->compressed = FALSE;
859
if (-1 == write(jfd, file_header, 30))
860
exit_on_error("write");
861
if (-1 == write(jfd, "META-INF/", nlen))
862
exit_on_error("write");
859
865
/* if the user didn't specify an external manifest file... */
860
866
if(mf_name == NULL){
886
892
printf("adding: META-INF/MANIFEST.MF (in=56) (out=56) (stored 0%%)\n");
888
894
ze = (zipentry*)malloc(sizeof(zipentry));
896
exit_on_error("malloc");
894
898
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
895
899
ze->filename = strdup("META-INF/MANIFEST.MF");
896
if (NULL == ze->filename) {
900
if (NULL == ze->filename)
901
exit_on_error("strdup");
901
903
ze->offset = lseek(jfd, 0, SEEK_CUR);
902
904
ze->mod_time = (ub2)(mod_time & 0x0000ffff);
911
write(jfd, file_header, 30);
912
write(jfd, "META-INF/MANIFEST.MF", nlen);
913
write(jfd, mf, mf_len);
913
if (-1 == write(jfd, file_header, 30))
914
exit_on_error("write");
915
if (-1 == write(jfd, "META-INF/MANIFEST.MF", nlen))
916
exit_on_error("write");
917
if (-1 == write(jfd, mf, mf_len))
918
exit_on_error("write");
1112
1106
add_entry (ze);
1113
write (fd, file_header, 30);
1114
write (fd, fullname, nlen);
1107
if (-1 == write (fd, file_header, 30))
1108
exit_on_error("write");
1109
if (-1 == write (fd, fullname, nlen))
1110
exit_on_error("write");
1115
1111
end_of_entries = lseek (fd, 0, SEEK_CUR);
1261
1255
/* Write the local header */
1262
write(jfd, file_header, 30);
1256
if (-1 == write(jfd, file_header, 30))
1257
exit_on_error("write");
1264
1259
/* write the file name to the zip file */
1265
write(jfd, fname, file_name_length);
1260
if (1 == write(jfd, fname, file_name_length))
1261
exit_on_error("write");
1474
1466
PACK_UB2(header, CEN_FNLEN, strlen(ze->filename));
1475
1467
PACK_UB4(header, CEN_OFFSET, ze->offset);
1477
write(fd, header, 46);
1469
if (-1 == write(fd, header, 46))
1470
exit_on_error("write");
1479
write(fd, ze->filename, strlen(ze->filename));
1472
if (-1 == write(fd, ze->filename, strlen(ze->filename)))
1473
exit_on_error("write");
1482
1476
dir_size = lseek(fd, 0, SEEK_CUR) - start_offset;
1842
1833
while(out_a < (int)csize){
1843
1834
rdamt = (in_a > RDSZ ? RDSZ : in_a);
1844
if(pb_read(&pbf, rd_buff, rdamt) != rdamt){
1835
if(pb_read(&pbf, rd_buff, rdamt) != rdamt)
1836
exit_on_error("read");
1849
1838
ze.crc = crc32(ze.crc, (Bytef*)rd_buff, rdamt);
1851
1840
if(f_fd >= 0) {
1852
1841
ssize_t num_written;
1853
1842
num_written = write(f_fd, rd_buff, rdamt);
1854
if (num_written == -1) {
1843
if (num_written == -1)
1844
exit_on_error("write");
1860
1847
out_a += rdamt;
1958
1940
position, so we have to fall back on the method used for
1959
1941
non-seekable files. */
1960
1942
seekable = FALSE;
1961
if(lseek(fd, 0, SEEK_SET) == (off_t)-1){
1943
if(lseek(fd, 0, SEEK_SET) == (off_t)-1)
1944
exit_on_error("lseek");
1966
if(lseek(fd, 6, SEEK_CUR) == (off_t)-1){
1946
if(lseek(fd, 6, SEEK_CUR) == (off_t)-1)
1947
exit_on_error("lseek");
1971
if(read(fd, &cen_size, 2) != 2){
1949
if(read(fd, &cen_size, 2) != 2)
1950
exit_on_error("read");
1976
1952
#ifdef WORDS_BIGENDIAN
1977
1953
cen_size = L2BS(cen_size);
1980
1956
/* printf("%hu entries in central header\n", cen_size); */
1982
if(lseek(fd, 4, SEEK_CUR) == (off_t)-1){
1987
if(read(fd, &tmp, 4) != 4){
1958
if(lseek(fd, 4, SEEK_CUR) == (off_t)-1)
1959
exit_on_error("lseek");
1961
if(read(fd, &tmp, 4) != 4)
1962
exit_on_error("read");
1992
1965
#ifdef WORDS_BIGENDIAN
1993
1966
tmp = L2BI(tmp);
2535
2492
/* Write the local header */
2536
2493
written = write(jfd, file_header, 30);
2537
if ((written == -1) || ((size_t) written != 30)){
2494
if ((written == -1) || ((size_t) written != 30))
2495
exit_on_error("write");
2542
2497
/* write the file name to the zip file */
2543
2498
written = write(jfd, fname, file_name_length);
2544
if ((written == -1) || ((size_t) written != file_name_length)){
2499
if ((written == -1) || ((size_t) written != file_name_length))
2500
exit_on_error("write");
2577
2529
ze->crc = crc32(ze->crc, (unsigned char*)content, content_length);
2578
2530
written = write(jfd, content, content_length);
2579
if ((written == -1) || ((size_t) written != content_length)){
2531
if ((written == -1) || ((size_t) written != content_length))
2532
exit_on_error("write");
2584
2534
/* write out data descriptor */
2585
2535
PACK_UB4(data_descriptor, 4, ze->crc);