summaryrefslogtreecommitdiffstats
path: root/create_lz.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:08:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:08:19 +0000
commitcb1387c92038634c063ee06a24e249b87525f519 (patch)
treeaeebf76566be407c42678fff1c2482ee9dc8fe17 /create_lz.cc
parentReleasing debian version 0.23-3. (diff)
downloadtarlz-cb1387c92038634c063ee06a24e249b87525f519.tar.xz
tarlz-cb1387c92038634c063ee06a24e249b87525f519.zip
Merging upstream version 0.25.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'create_lz.cc')
-rw-r--r--create_lz.cc50
1 files changed, 22 insertions, 28 deletions
diff --git a/create_lz.cc b/create_lz.cc
index 1acaf23..5436bf5 100644
--- a/create_lz.cc
+++ b/create_lz.cc
@@ -1,5 +1,5 @@
/* Tarlz - Archiver with multimember lzip compression
- Copyright (C) 2013-2022 Antonio Diaz Diaz.
+ Copyright (C) 2013-2024 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@
#include <algorithm>
#include <cerrno>
#include <cstdio>
-#include <cstdlib>
#include <queue>
#include <pthread.h>
#include <stdint.h> // for lzlib.h
@@ -31,6 +30,7 @@
#include "tarlz.h"
#include "arg_parser.h"
+#include "common_mutex.h"
#include "create.h"
@@ -87,9 +87,9 @@ struct Ipacket // filename, file size and headers
const uint8_t * const header;
Ipacket() : file_size( 0 ), extended( 0 ), header( 0 ) {}
- Ipacket( const char * const name, const long long s,
+ Ipacket( const char * const name, const long long fs,
const Extended * const ext, const uint8_t * const head )
- : file_size( s ), filename( name ), extended( ext ), header( head ) {}
+ : file_size( fs ), filename( name ), extended( ext ), header( head ) {}
};
struct Opacket // compressed data to be written to the archive
@@ -269,11 +269,14 @@ int add_member_lz( const char * const filename, const struct stat *,
{ delete[] header; delete extended; return 0; }
print_removed_prefix( extended->removed_prefix );
- if( gcl_opts->solidity == bsolid &&
- block_is_full( extended->full_size(), file_size, gcl_opts->data_size,
- partial_data_size ) )
- courierp->receive_packet( new Ipacket ); // end of group
-
+ if( gcl_opts->solidity == bsolid )
+ {
+ const int ebsize = extended->full_size();
+ if( ebsize < 0 ) { show_error( extended->full_size_error() ); return 1; }
+ if( block_is_full( ebsize, file_size, gcl_opts->data_size,
+ partial_data_size ) )
+ courierp->receive_packet( new Ipacket ); // end of group
+ }
courierp->receive_packet( new Ipacket( filename, file_size, extended, header ) );
if( gcl_opts->solidity == no_solid ) // one tar member per group
@@ -331,9 +334,9 @@ extern "C" void * grouper( void * arg )
}
-/* Writes ibuf to encoder. To minimize dictionary size, it does not read
- from encoder until encoder's input buffer is full or finish is true.
- Sends opacket to courier and allocates new obuf each time obuf is full.
+/* Write ibuf to encoder. To minimize dictionary size, do not read from
+ encoder until encoder's input buffer is full or finish is true.
+ Send opacket to courier and allocate new obuf each time obuf is full.
*/
void loop_encode( const uint8_t * const ibuf, const int isize,
uint8_t * & obuf, int & opos, Packet_courier & courier,
@@ -423,8 +426,7 @@ extern "C" void * cworker( void * arg )
}
const char * const filename = ipacket->filename.c_str();
- const int infd =
- ipacket->file_size ? open_instream( filename ) : -1;
+ const int infd = ipacket->file_size ? open_instream( filename ) : -1;
if( ipacket->file_size && infd < 0 ) // can't read file data
{ delete[] ipacket->header; delete ipacket->extended; delete ipacket;
set_error_status( 1 ); continue; } // skip file
@@ -444,17 +446,11 @@ extern "C" void * cworker( void * arg )
}
}
- if( !ipacket->extended->empty() ) // compress extended block
- {
- const long long ebsize = ipacket->extended->format_block( rbuf );
- if( ebsize < 0 )
- { show_error( ( ebsize == -2 ) ? mem_msg2 : eferec_msg ); exit_fail_mt(); }
- /* Limit the size of the extended block to INT_MAX - 1 so that it can
- be fed to lzlib as one buffer. */
- if( ebsize >= INT_MAX )
- { show_error( "Extended records size >= INT_MAX." ); exit_fail_mt(); }
+ const int ebsize = ipacket->extended->format_block( rbuf ); // may be 0
+ if( ebsize < 0 )
+ { show_error( ipacket->extended->full_size_error() ); exit_fail_mt(); }
+ if( ebsize > 0 ) // compress extended block
loop_encode( rbuf.u8(), ebsize, data, opos, courier, encoder, worker_id );
- }
// compress ustar header
loop_encode( ipacket->header, header_size, data, opos, courier,
encoder, worker_id );
@@ -472,9 +468,7 @@ extern "C" void * cworker( void * arg )
rest -= rd;
if( rd != size )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "File '%s' ends unexpectedly at pos %llu\n",
- filename, ipacket->file_size - rest );
+ show_atpos_error( filename, ipacket->file_size - rest, false );
close( infd ); exit_fail_mt();
}
if( rest == 0 ) // last read
@@ -595,6 +589,6 @@ int encode_lz( const Cl_options & cl_opts, const char * const archive_namep,
courier.ocheck_counter,
courier.owait_counter );
- if( !courier.finished() ) internal_error( "courier not finished." );
+ if( !courier.finished() ) internal_error( conofin_msg );
return final_exit_status( retval );
}