summaryrefslogtreecommitdiffstats
path: root/decode_lz.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--decode_lz.cc416
1 files changed, 224 insertions, 192 deletions
diff --git a/decode_lz.cc b/decode_lz.cc
index a941ace..8780eab 100644
--- a/decode_lz.cc
+++ b/decode_lz.cc
@@ -37,6 +37,7 @@
#include "arg_parser.h"
#include "lzip_index.h"
#include "archive_reader.h"
+#include "decode.h"
/* When a problem is detected by any worker:
- the worker requests mastership and returns.
@@ -48,14 +49,18 @@ namespace {
const char * const other_msg = "Other worker found an error.";
+/* line is preformatted and newline terminated except for prefix, error.
+ ok with an empty line is a no-op. */
struct Packet // member name and metadata or error message
{
- enum Status { ok, member_done, diag, error };
+ enum Status { ok, member_done, diag, prefix, error1, error2 };
+
long member_id; // lzip member containing the header of this tar member
std::string line; // member name and metadata ready to print, if any
Status status; // diagnostics and errors go to stderr
- Packet( const long i, const char * const msg, const Status s = ok )
- : member_id( i ), line( msg ), status( s ) {}
+ int errcode; // for error
+ Packet( const long i, const char * const msg, const Status s, const int e )
+ : member_id( i ), line( msg ), status( s ), errcode( e ) {}
};
@@ -65,9 +70,9 @@ public:
unsigned ocheck_counter;
unsigned owait_counter;
private:
- long error_member_id; // first lzip member with error/misalign/eof
+ long error_member_id; // first lzip member with error/misalign/eoa/eof
int deliver_worker_id; // worker queue currently delivering packets
- int master_worker_id; // worker in charge if error/misalignment/eof
+ int master_worker_id; // worker in charge if error/misalign/eoa/eof
std::vector< std::queue< const Packet * > > opacket_queues;
int num_working; // number of workers still running
const int num_workers; // number of workers
@@ -76,7 +81,7 @@ private:
pthread_cond_t oav_or_exit; // output packet available or all workers exited
std::vector< pthread_cond_t > slot_av; // output slot available
pthread_cond_t check_master;
- bool eof_found_;
+ bool eoa_found_; // EOA blocks found
Packet_courier( const Packet_courier & ); // declared as private
void operator=( const Packet_courier & ); // declared as private
@@ -87,7 +92,7 @@ public:
error_member_id( -1 ), deliver_worker_id( 0 ), master_worker_id( -1 ),
opacket_queues( workers ), num_working( workers ),
num_workers( workers ), out_slots( slots ), slot_av( workers ),
- eof_found_( false )
+ eoa_found_( false )
{
xinit_mutex( &omutex ); xinit_cond( &oav_or_exit );
for( unsigned i = 0; i < slot_av.size(); ++i ) xinit_cond( &slot_av[i] );
@@ -101,8 +106,8 @@ public:
xdestroy_cond( &oav_or_exit ); xdestroy_mutex( &omutex );
}
- bool eof_found() const { return eof_found_; }
- void report_eof() { eof_found_ = true; }
+ bool eoa_found() const { return eoa_found_; }
+ void report_eoa() { eoa_found_ = true; }
bool mastership_granted() const { return master_worker_id >= 0; }
@@ -142,10 +147,10 @@ public:
/* Collect a packet from a worker.
If a packet is rejected, the worker must terminate. */
bool collect_packet( const long member_id, const int worker_id,
- const char * const msg,
- const Packet::Status status = Packet::ok )
+ const char * const msg, const Packet::Status status,
+ const int errcode = 0 )
{
- const Packet * const opacket = new Packet( member_id, msg, status );
+ const Packet * const opacket = new Packet( member_id, msg, status, errcode );
xlock( &omutex );
if( ( mastership_granted() && master_worker_id != worker_id ) ||
( error_member_id >= 0 && error_member_id < opacket->member_id ) )
@@ -228,19 +233,31 @@ public:
};
-const char * skip_member_lz( Archive_reader_i & ar, Packet_courier & courier,
- const Extended & extended, const long member_id,
- const int worker_id )
+struct Trival // triple result value
{
- if( ar.skip_member( extended ) != 0 ) return ar.e_msg();
- if( !courier.collect_packet( member_id, worker_id, "",
- ar.at_member_end() ? Packet::member_done : Packet::ok ) )
- return other_msg;
- return 0;
+ const char * msg;
+ int errcode;
+ int retval;
+ explicit Trival( const char * const s = 0, const int e = 0, const int r = 0 )
+ : msg( s ), errcode( e ), retval( r ) {}
+ };
+
+
+Trival skip_member_lz( Archive_reader_i & ar, Packet_courier & courier,
+ const Extended & extended, const long member_id,
+ const int worker_id, const Typeflag typeflag )
+ {
+ if( data_may_follow( typeflag ) )
+ { const int ret = ar.skip_member( extended );
+ if( ret != 0 ) return Trival( ar.e_msg(), ar.e_code(), ret ); }
+ if( ar.at_member_end() &&
+ !courier.collect_packet( member_id, worker_id, "", Packet::member_done ) )
+ return Trival( other_msg, 0, 1);
+ return Trival();
}
-const char * compare_member_lz( const Cl_options & cl_opts,
+Trival compare_member_lz( const Cl_options & cl_opts,
Archive_reader_i & ar, Packet_courier & courier,
const Extended & extended, const Tar_header header,
Resizable_buffer & rbuf, const long member_id,
@@ -248,7 +265,7 @@ const char * compare_member_lz( const Cl_options & cl_opts,
{
if( verbosity < 1 ) rbuf()[0] = 0;
else if( !format_member_name( extended, header, rbuf, verbosity > 1 ) )
- return mem_msg;
+ return Trival( mem_msg, 0, 1 );
std::string estr, ostr;
const bool stat_differs =
!compare_file_type( estr, ostr, cl_opts, extended, header );
@@ -260,84 +277,95 @@ const char * compare_member_lz( const Cl_options & cl_opts,
ostr.c_str(), Packet::ok ) ) ||
( extended.file_size() <= 0 && ar.at_member_end() &&
!courier.collect_packet( member_id, worker_id, "", Packet::member_done ) ) )
- return other_msg;
- if( extended.file_size() <= 0 ) return 0;
+ return Trival( other_msg, 0, 1 );
+ if( extended.file_size() <= 0 ) return Trival();
const Typeflag typeflag = (Typeflag)header[typeflag_o];
if( ( typeflag != tf_regular && typeflag != tf_hiperf ) || stat_differs )
- return skip_member_lz( ar, courier, extended, member_id, worker_id );
+ return skip_member_lz( ar, courier, extended, member_id, worker_id, typeflag );
// else compare file contents
const char * const filename = extended.path().c_str();
const int infd2 = open_instream( filename );
if( infd2 < 0 ) { set_error_status( 1 );
- return skip_member_lz( ar, courier, extended, member_id, worker_id ); }
- int retval = compare_file_contents( estr, ostr, ar, extended.file_size(),
- filename, infd2 );
- if( retval ) return ar.e_msg();
+ return skip_member_lz( ar, courier, extended, member_id, worker_id, typeflag ); }
+ const int ret = compare_file_contents( estr, ostr, ar, extended.file_size(),
+ filename, infd2 );
+ if( ret != 0 ) return Trival( ar.e_msg(), ar.e_code(), ret );
if( ( estr.size() && !courier.collect_packet( member_id, worker_id,
estr.c_str(), Packet::diag ) ) ||
( ostr.size() && !courier.collect_packet( member_id, worker_id,
ostr.c_str(), Packet::ok ) ) ||
( ar.at_member_end() &&
!courier.collect_packet( member_id, worker_id, "", Packet::member_done ) ) )
- return other_msg;
- return 0;
+ return Trival( other_msg, 0, 1 );
+ return Trival();
}
-const char * list_member_lz( Archive_reader_i & ar, Packet_courier & courier,
- const Extended & extended, const Tar_header header,
- Resizable_buffer & rbuf, const long member_id,
- const int worker_id )
+Trival list_member_lz( Archive_reader_i & ar, Packet_courier & courier,
+ const Extended & extended, const Tar_header header,
+ Resizable_buffer & rbuf, const long member_id,
+ const int worker_id )
{
if( verbosity < 0 ) rbuf()[0] = 0;
else if( !format_member_name( extended, header, rbuf, verbosity > 0 ) )
- return mem_msg;
- const int ret = ar.skip_member( extended ); // print name even on error
+ return Trival( mem_msg, 0, 1 );
+ const int ret = data_may_follow( (Typeflag)header[typeflag_o] ) ?
+ ar.skip_member( extended ) : 0; // print name even on read error
if( !courier.collect_packet( member_id, worker_id, rbuf(),
ar.at_member_end() ? Packet::member_done : Packet::ok ) )
- return other_msg;
- if( ret != 0 ) return ar.e_msg();
- return 0;
+ return Trival( other_msg, 0, 1 );
+ if( ret != 0 ) return Trival( ar.e_msg(), ar.e_code(), ret );
+ return Trival();
}
-const char * extract_member_lz( const Cl_options & cl_opts,
- Archive_reader_i & ar, Packet_courier & courier,
- const Extended & extended, const Tar_header header,
- Resizable_buffer & rbuf, const long member_id,
- const int worker_id, Name_monitor & name_monitor )
+Trival extract_member_lz( const Cl_options & cl_opts,
+ Archive_reader_i & ar, Packet_courier & courier,
+ const Extended & extended, const Tar_header header,
+ Resizable_buffer & rbuf, const long member_id,
+ const int worker_id, Name_monitor & name_monitor )
{
- // skip member if another copy is already being extracted by another thread
- if( !name_monitor.reserve_name( worker_id, extended.path() ) )
- return skip_member_lz( ar, courier, extended, member_id, worker_id );
const char * const filename = extended.path().c_str();
+ const Typeflag typeflag = (Typeflag)header[typeflag_o];
if( contains_dotdot( filename ) )
{
- if( verbosity >= 0 )
- { std::string estr( extended.path() );
- estr += ": Contains a '..' component, skipping.";
- if( !courier.collect_packet( member_id, worker_id, estr.c_str(),
- Packet::diag ) ) return other_msg; }
- return skip_member_lz( ar, courier, extended, member_id, worker_id );
+ if( format_file_error( rbuf, filename, dotdot_msg ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ return skip_member_lz( ar, courier, extended, member_id, worker_id, typeflag );
+ }
+ // skip member if another copy is already being extracted by another thread
+ if( !name_monitor.reserve_name( worker_id, extended.path() ) )
+ {
+ if( verbosity >= 3 && format_file_error( rbuf, filename,
+ "Is being extracted by another thread, skipping." ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ return skip_member_lz( ar, courier, extended, member_id, worker_id, typeflag );
}
mode_t mode = parse_octal( header + mode_o, mode_l ); // 12 bits
if( geteuid() != 0 && !cl_opts.preserve_permissions ) mode &= ~get_umask();
- const time_t mtime = parse_octal( header + mtime_o, mtime_l ); // 33 bits
- const Typeflag typeflag = (Typeflag)header[typeflag_o];
- const bool islink = ( typeflag == tf_link || typeflag == tf_symlink );
int outfd = -1;
- if( verbosity < 1 ) rbuf()[0] = 0;
- else if( !format_member_name( extended, header, rbuf, verbosity > 1 ) )
- return mem_msg;
- if( rbuf()[0] && !courier.collect_packet( member_id, worker_id, rbuf(),
- Packet::ok ) ) return other_msg;
+ if( verbosity >= 1 )
+ {
+ if( !format_member_name( extended, header, rbuf, verbosity > 1 ) )
+ return Trival( mem_msg, 0, 1 );
+ if( !courier.collect_packet( member_id, worker_id, rbuf(), Packet::ok ) )
+ return Trival( other_msg, 0, 1 );
+ }
+ /* Remove file before extraction to prevent following links.
+ Don't remove an empty dir because other thread may need it. */
if( typeflag != tf_directory ) std::remove( filename );
- if( !make_path( filename ) && verbosity >= 0 )
- { std::string estr( extended.path() );
- estr += ": warning: Failed to create intermediate directory.";
- if( !courier.collect_packet( member_id, worker_id, estr.c_str(),
- Packet::diag ) ) return other_msg; }
+ if( !make_path( filename ) )
+ {
+ if( format_file_error( rbuf, filename, intdir_msg, errno ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
+ return skip_member_lz( ar, courier, extended, member_id, worker_id, typeflag );
+ }
+
switch( typeflag )
{
case tf_regular:
@@ -345,10 +373,12 @@ const char * extract_member_lz( const Cl_options & cl_opts,
outfd = open_outstream( filename, true, &rbuf );
if( outfd < 0 )
{
- if( verbosity >= 0 && !courier.collect_packet( member_id, worker_id,
- rbuf(), Packet::diag ) ) return other_msg;
- set_error_status( 2 );
- return skip_member_lz( ar, courier, extended, member_id, worker_id );
+ if( verbosity >= 0 &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
+ return skip_member_lz( ar, courier, extended, member_id, worker_id,
+ typeflag );
}
break;
case tf_link:
@@ -359,21 +389,11 @@ const char * extract_member_lz( const Cl_options & cl_opts,
if( ( hard && link( linkname, filename ) != 0 ) ||
( !hard && symlink( linkname, filename ) != 0 ) )
{
- if( verbosity >= 0 )
- {
- const int saved_errno = errno;
- const int size =
- snprintf( rbuf(), rbuf.size(), "Can't %slink '%s' to '%s': %s.\n",
- hard ? "" : "sym", linkname, filename,
- std::strerror( saved_errno ) );
- if( size > 0 && (unsigned)size > rbuf.size() && rbuf.resize( size ) )
- snprintf( rbuf(), rbuf.size(), "Can't %slink '%s' to '%s': %s.\n",
- hard ? "" : "sym", linkname, filename,
- std::strerror( saved_errno ) );
- if( verbosity >= 0 && !courier.collect_packet( member_id, worker_id,
- rbuf(), Packet::diag ) ) return other_msg;
- }
- set_error_status( 2 );
+ if( format_error( rbuf, errno, cantln_msg, hard ? "" : "sym",
+ linkname, filename ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
}
} break;
case tf_directory:
@@ -384,12 +404,10 @@ const char * extract_member_lz( const Cl_options & cl_opts,
{ exists = false; std::remove( filename ); }
if( !exists && mkdir( filename, mode ) != 0 && errno != EEXIST )
{
- if( verbosity >= 0 )
- { snprintf( rbuf(), rbuf.size(), "%s: Can't create directory: %s\n",
- filename, std::strerror( errno ) );
- if( !courier.collect_packet( member_id, worker_id, rbuf(),
- Packet::diag ) ) return other_msg; }
- set_error_status( 2 );
+ if( format_file_error( rbuf, filename, mkdir_msg, errno ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
}
} break;
case tf_chardev:
@@ -401,92 +419,93 @@ const char * extract_member_lz( const Cl_options & cl_opts,
const int dmode = ( typeflag == tf_chardev ? S_IFCHR : S_IFBLK ) | mode;
if( mknod( filename, dmode, dev ) != 0 )
{
- if( verbosity >= 0 )
- { snprintf( rbuf(), rbuf.size(), "%s: Can't create device node: %s\n",
- filename, std::strerror( errno ) );
- if( !courier.collect_packet( member_id, worker_id, rbuf(),
- Packet::diag ) ) return other_msg; }
- set_error_status( 2 );
+ if( format_file_error( rbuf, filename, mknod_msg, errno ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
}
break;
}
case tf_fifo:
- if( mkfifo( filename, mode ) != 0 && errno != EEXIST )
+ if( mkfifo( filename, mode ) != 0 )
{
- if( verbosity >= 0 )
- { snprintf( rbuf(), rbuf.size(), "%s: Can't create FIFO file: %s\n",
- filename, std::strerror( errno ) );
- if( !courier.collect_packet( member_id, worker_id, rbuf(),
- Packet::diag ) ) return other_msg; }
- set_error_status( 2 );
+ if( format_file_error( rbuf, filename, mkfifo_msg, errno ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
}
break;
default:
- if( verbosity >= 0 )
- { snprintf( rbuf(), rbuf.size(),
- "File type '%c' not supported for file '%s'.\n",
- typeflag, filename );
- if( !courier.collect_packet( member_id, worker_id, rbuf(),
- Packet::diag ) ) return other_msg; }
+ if( format_error( rbuf, 0, uftype_msg, filename, typeflag ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
set_error_status( 2 );
+ return skip_member_lz( ar, courier, extended, member_id, worker_id,
+ typeflag );
}
- const uid_t uid = (uid_t)parse_octal( header + uid_o, uid_l );
- const gid_t gid = (gid_t)parse_octal( header + gid_o, gid_l );
- if( !islink && chown( filename, uid, gid ) != 0 &&
- errno != EPERM && errno != EINVAL )
+ const bool islink = ( typeflag == tf_link || typeflag == tf_symlink );
+ errno = 0;
+ if( !islink &&
+ ( !uid_gid_in_range( extended.get_uid(), extended.get_gid() ) ||
+ chown( filename, extended.get_uid(), extended.get_gid() ) != 0 ) )
{
- if( verbosity >= 0 )
- { snprintf( rbuf(), rbuf.size(), "%s: Can't change file owner: %s\n",
- filename, std::strerror( errno ) );
- if( !courier.collect_packet( member_id, worker_id, rbuf(),
- Packet::diag ) ) return other_msg; }
- set_error_status( 2 );
+ if( outfd >= 0 ) mode &= ~( S_ISUID | S_ISGID | S_ISVTX );
+ // chown will in many cases return with EPERM, which can be safely ignored.
+ if( errno != EPERM && errno != EINVAL )
+ {
+ if( format_file_error( rbuf, filename, chown_msg, errno ) &&
+ !courier.collect_packet( member_id, worker_id, rbuf(), Packet::diag ) )
+ return Trival( other_msg, 0, 1 );
+ set_error_status( 1 );
+ }
}
- if( typeflag == tf_regular || typeflag == tf_directory ||
- typeflag == tf_hiperf ) fchmod( outfd, mode ); // ignore errors
+ if( outfd >= 0 ) fchmod( outfd, mode ); // ignore errors
- const int bufsize = 32 * header_size;
- uint8_t buf[bufsize];
- long long rest = extended.file_size();
- const int rem = rest % header_size;
- const int padding = rem ? header_size - rem : 0;
- while( rest > 0 )
+ if( data_may_follow( typeflag ) )
{
- const int rsize = ( rest >= bufsize ) ? bufsize : rest + padding;
- const int ret = ar.read( buf, rsize );
- if( ret != 0 )
+ const int bufsize = 32 * header_size;
+ uint8_t buf[bufsize];
+ long long rest = extended.file_size();
+ const int rem = rest % header_size;
+ const int padding = rem ? header_size - rem : 0;
+ while( rest > 0 )
{
- if( outfd >= 0 )
+ const int rsize = ( rest >= bufsize ) ? bufsize : rest + padding;
+ const int ret = ar.read( buf, rsize );
+ if( ret != 0 )
{
- if( cl_opts.keep_damaged )
- { writeblock( outfd, buf, std::min( rest, (long long)ar.e_size() ) );
- close( outfd ); }
- else { close( outfd ); std::remove( filename ); }
+ if( outfd >= 0 )
+ {
+ if( cl_opts.keep_damaged )
+ { writeblock( outfd, buf, std::min( rest, (long long)ar.e_size() ) );
+ close( outfd ); }
+ else { close( outfd ); std::remove( filename ); }
+ }
+ return Trival( ar.e_msg(), ar.e_code(), ret );
}
- return ar.e_msg();
+ const int wsize = ( rest >= bufsize ) ? bufsize : rest;
+ if( outfd >= 0 && writeblock( outfd, buf, wsize ) != wsize )
+ { format_file_error( rbuf, filename, werr_msg, errno );
+ return Trival( rbuf(), 0, 1 ); }
+ rest -= wsize;
}
- const int wsize = ( rest >= bufsize ) ? bufsize : rest;
- if( outfd >= 0 && writeblock( outfd, buf, wsize ) != wsize )
- { snprintf( rbuf(), rbuf.size(), "%s: Error writing file: %s\n",
- filename, std::strerror( errno ) ); return rbuf(); }
- rest -= wsize;
}
if( outfd >= 0 && close( outfd ) != 0 )
- { snprintf( rbuf(), rbuf.size(), "%s: Error closing file: %s\n",
- filename, std::strerror( errno ) ); return rbuf(); }
+ { format_file_error( rbuf, filename, eclosf_msg, errno );
+ return Trival( rbuf(), 0, 1 ); }
if( !islink )
{
struct utimbuf t;
- t.actime = mtime;
- t.modtime = mtime;
+ t.actime = extended.atime().sec();
+ t.modtime = extended.mtime().sec();
utime( filename, &t ); // ignore errors
}
if( ar.at_member_end() &&
!courier.collect_packet( member_id, worker_id, "", Packet::member_done ) )
- return other_msg;
- return 0;
+ return Trival( other_msg, 0, 1 );
+ return Trival();
}
@@ -521,7 +540,7 @@ extern "C" void * dworker( void * arg )
Archive_reader_i ar( ad ); // 1 of N parallel readers
if( !rbuf.size() || ar.fatal() )
{ if( courier.request_mastership( worker_id, worker_id ) )
- courier.collect_packet( worker_id, worker_id, mem_msg, Packet::error );
+ courier.collect_packet( worker_id, worker_id, mem_msg, Packet::error1 );
goto done; }
for( long i = worker_id; !master && i < ad.lzip_index.members(); i += num_workers )
@@ -545,7 +564,7 @@ extern "C" void * dworker( void * arg )
if( !courier.request_mastership( i, worker_id ) ) goto done;
master = true;
if( data_end >= ad.lzip_index.udata_size() )
- { courier.collect_packet( i, worker_id, end_msg, Packet::error );
+ { courier.collect_packet( i, worker_id, end_msg, Packet::error2 );
goto done; }
data_end = ad.lzip_index.udata_size();
if( ar.data_pos() == data_end && !prev_extended ) break;
@@ -554,30 +573,31 @@ extern "C" void * dworker( void * arg )
const int ret = ar.read( header, header_size );
if( ret != 0 )
{ if( courier.request_mastership( i, worker_id ) )
- courier.collect_packet( i, worker_id, ar.e_msg(), Packet::error );
+ courier.collect_packet( i, worker_id, ar.e_msg(),
+ ( ret == 1 ) ? Packet::error1 : Packet::error2, ar.e_code() );
goto done; }
- if( !verify_ustar_chksum( header ) )
+ if( !verify_ustar_chksum( header ) ) // error or EOA
{
if( !courier.request_mastership( i, worker_id ) ) goto done;
- if( block_is_zero( header, header_size ) ) // EOF
+ if( block_is_zero( header, header_size ) ) // EOA
{
- if( !prev_extended || cl_opts.permissive ) courier.report_eof();
- else courier.collect_packet( i, worker_id, fv_msg1, Packet::error );
+ if( !prev_extended || cl_opts.permissive ) courier.report_eoa();
+ else courier.collect_packet( i, worker_id, fv_msg1, Packet::error2 );
goto done;
}
courier.collect_packet( i, worker_id, ( ar.data_pos() > header_size ) ?
- bad_hdr_msg : posix_lz_msg, Packet::error );
+ bad_hdr_msg : posix_lz_msg, Packet::error2 );
goto done;
}
const Typeflag typeflag = (Typeflag)header[typeflag_o];
if( typeflag == tf_global )
{
- const char * msg = 0;
+ const char * msg = 0; int ret = 2;
Extended dummy; // global headers are parsed and ignored
if( prev_extended && !cl_opts.permissive ) msg = fv_msg2;
- else if( ar.parse_records( dummy, header, rbuf, true ) != 0 )
- msg = gblrec_msg;
+ else if( ( ret = ar.parse_records( dummy, header, rbuf, gblrec_msg,
+ true ) ) != 0 ) msg = ar.e_msg();
else
{
if( ar.data_pos() == data_end && // end of lzip member or EOF
@@ -586,20 +606,22 @@ extern "C" void * dworker( void * arg )
continue;
}
if( courier.request_mastership( i, worker_id ) )
- courier.collect_packet( i, worker_id, msg, Packet::error );
+ courier.collect_packet( i, worker_id, msg, ( ret == 1 ) ?
+ Packet::error1 : Packet::error2 );
goto done;
}
if( typeflag == tf_extended )
{
- const char * msg = 0;
+ const char * msg = 0; int ret = 2;
if( prev_extended && !cl_opts.permissive ) msg = fv_msg3;
- else if( ar.parse_records( extended, header, rbuf,
- cl_opts.permissive ) != 0 ) msg = extrec_msg;
+ else if( ( ret = ar.parse_records( extended, header, rbuf, extrec_msg,
+ cl_opts.permissive ) ) != 0 ) msg = ar.e_msg();
else if( !extended.crc_present() && cl_opts.missing_crc )
- msg = mcrc_msg;
+ { msg = miscrc_msg; ret = 2; }
else { prev_extended = true; continue; }
if( courier.request_mastership( i, worker_id ) )
- courier.collect_packet( i, worker_id, msg, Packet::error );
+ courier.collect_packet( i, worker_id, msg, ( ret == 1 ) ?
+ Packet::error1 : Packet::error2 );
goto done;
}
prev_extended = false;
@@ -609,21 +631,30 @@ extern "C" void * dworker( void * arg )
/* Skip members with an empty name in the ustar header. If there is an
extended header in a previous lzip member, its worker will request
mastership. Else the ustar-only unnamed member will be ignored. */
- const char * msg;
+ Trival trival;
if( check_skip_filename( cl_opts, name_pending, extended.path().c_str() ) )
- msg = skip_member_lz( ar, courier, extended, i, worker_id );
- else if( cl_opts.program_mode == m_list )
- msg = list_member_lz( ar, courier, extended, header, rbuf, i, worker_id );
- else if( extended.path().empty() )
- msg = skip_member_lz( ar, courier, extended, i, worker_id );
- else if( cl_opts.program_mode == m_diff )
- msg = compare_member_lz( cl_opts, ar, courier, extended, header,
- rbuf, i, worker_id );
- else msg = extract_member_lz( cl_opts, ar, courier, extended, header,
- rbuf, i, worker_id, name_monitor );
- if( msg ) // fatal error
- { if( courier.request_mastership( i, worker_id ) )
- courier.collect_packet( i, worker_id, msg, Packet::error );
+ trival = skip_member_lz( ar, courier, extended, i, worker_id, typeflag );
+ else
+ {
+ std::string rpmsg;
+ if( print_removed_prefix( extended.removed_prefix, &rpmsg ) &&
+ !courier.collect_packet( i, worker_id, rpmsg.c_str(), Packet::prefix ) )
+ { trival = Trival( other_msg, 0, 1 ); goto fatal; }
+ if( cl_opts.program_mode == m_list )
+ trival = list_member_lz( ar, courier, extended, header, rbuf, i, worker_id );
+ else if( extended.path().empty() )
+ trival = skip_member_lz( ar, courier, extended, i, worker_id, typeflag );
+ else if( cl_opts.program_mode == m_diff )
+ trival = compare_member_lz( cl_opts, ar, courier, extended, header,
+ rbuf, i, worker_id );
+ else trival = extract_member_lz( cl_opts, ar, courier, extended, header,
+ rbuf, i, worker_id, name_monitor );
+ }
+ if( trival.retval ) // fatal error
+fatal: { if( courier.request_mastership( i, worker_id ) )
+ courier.collect_packet( i, worker_id, trival.msg,
+ ( trival.retval == 1 ) ? Packet::error1 : Packet::error2,
+ trival.errcode );
goto done; }
extended.reset();
}
@@ -639,26 +670,28 @@ done:
*/
void muxer( const char * const archive_namep, Packet_courier & courier )
{
- bool error = false;
- while( !error )
+ int retval = 0;
+ while( retval == 0 )
{
const Packet * const opacket = courier.deliver_packet();
if( !opacket ) break; // queue is empty. all workers exited
switch( opacket->status )
{
- case Packet::error:
- show_file_error( archive_namep, opacket->line.c_str() );
- error = true; break;
+ case Packet::error1:
+ case Packet::error2:
+ show_file_error( archive_namep, opacket->line.c_str(), opacket->errcode );
+ retval = ( opacket->status == Packet::error1 ) ? 1 : 2; break;
+ case Packet::prefix: show_error( opacket->line.c_str() ); break;
case Packet::diag: std::fputs( opacket->line.c_str(), stderr ); break;
default: if( opacket->line.size() )
{ std::fputs( opacket->line.c_str(), stdout ); std::fflush( stdout ); }
}
delete opacket;
}
- if( !error && !courier.eof_found() ) // no worker found EOF blocks
- { show_file_error( archive_namep, end_msg ); error = true; }
- if( error ) exit_fail_mt( 2 );
+ if( retval == 0 && !courier.eoa_found() ) // no worker found EOA blocks
+ { show_file_error( archive_namep, end_msg ); retval = 2; }
+ if( retval ) exit_fail_mt( retval );
}
} // end namespace
@@ -710,13 +743,13 @@ int decode_lz( const Cl_options & cl_opts, const Archive_descriptor & ad,
int retval = 0;
if( close( ad.infd ) != 0 )
- { show_file_error( ad.namep, "Error closing archive", errno ); retval = 1; }
+ { show_file_error( ad.namep, eclosa_msg, errno ); retval = 1; }
if( retval == 0 )
for( int i = 0; i < cl_opts.parser.arguments(); ++i )
if( nonempty_arg( cl_opts.parser, i ) && name_pending[i] )
- { show_file_error( cl_opts.parser.argument( i ).c_str(),
- "Not found in archive." ); retval = 1; }
+ { show_file_error( cl_opts.parser.argument( i ).c_str(), nfound_msg );
+ retval = 1; }
if( cl_opts.debug_level & 1 )
std::fprintf( stderr,
@@ -725,7 +758,6 @@ int decode_lz( const Cl_options & cl_opts, const Archive_descriptor & ad,
courier.ocheck_counter,
courier.owait_counter );
- Exclude::clear(); // avoid error with gcc 3.3.6
if( !courier.finished() ) internal_error( "courier not finished." );
return final_exit_status( retval, cl_opts.program_mode != m_diff );
}