summaryrefslogtreecommitdiffstats
path: root/delete.cc
diff options
context:
space:
mode:
Diffstat (limited to 'delete.cc')
-rw-r--r--delete.cc72
1 files changed, 35 insertions, 37 deletions
diff --git a/delete.cc b/delete.cc
index 08d44fb..6fc58f5 100644
--- a/delete.cc
+++ b/delete.cc
@@ -34,7 +34,7 @@
bool safe_seek( const int fd, const long long pos )
{
if( lseek( fd, pos, SEEK_SET ) == pos ) return true;
- show_error( "Seek error", errno ); return false;
+ show_error( seek_msg, errno ); return false;
}
@@ -49,7 +49,8 @@ int tail_copy( const Arg_parser & parser, const Archive_descriptor & ad,
{ show_file_error( ad.namep, "Error during tail copy." );
return retval ? retval : 1; }
const long long ostream_pos = lseek( outfd, 0, SEEK_CUR );
- if( ostream_pos < 0 ) { show_error( "Seek error", errno ); retval = 1; }
+ if( ostream_pos < 0 )
+ { show_file_error( ad.namep, seek_msg, errno ); retval = 1; }
else if( ostream_pos > 0 && ostream_pos < ad.lzip_index.file_size() )
{
int ret;
@@ -62,15 +63,14 @@ int tail_copy( const Arg_parser & parser, const Archive_descriptor & ad,
}
}
- if( ( close( outfd ) != 0 || close( ad.infd ) != 0 ) && !retval )
- { show_file_error( ad.namep, "Error closing archive", errno ); retval = 1; }
+ if( ( close( outfd ) | close( ad.infd ) ) != 0 && retval == 0 )
+ { show_file_error( ad.namep, eclosa_msg, errno ); retval = 1; }
- if( retval == 0 ) for( int i = 0; i < parser.arguments(); ++i )
- if( nonempty_arg( parser, i ) && name_pending[i] )
- {
- show_file_error( parser.argument( i ).c_str(), "Not found in archive." );
- retval = 1;
- }
+ if( retval == 0 )
+ for( int i = 0; i < parser.arguments(); ++i )
+ if( nonempty_arg( parser, i ) && name_pending[i] )
+ { show_file_error( parser.argument( i ).c_str(), nfound_msg );
+ retval = 1; }
return retval;
}
@@ -101,33 +101,36 @@ int delete_members( const Cl_options & cl_opts )
if( !ad.seekable )
{ show_file_error( ad.namep, "Archive is not seekable." ); return 1; }
if( ad.lzip_index.file_size() < 3 * header_size )
- { show_file_error( ad.namep, posix_msg ); return 2; }
+ { show_file_error( ad.namep, has_lz_ext( ad.name ) ? posix_lz_msg : posix_msg );
+ return 2; }
// archive is uncompressed seekable, unless compressed corrupt
- Archive_reader ar( ad );
+ Archive_reader ar( ad ); // serial reader
Resizable_buffer rbuf;
long long istream_pos = 0; // source of next data move
long long member_begin = 0; // first pos of current tar member
Extended extended; // metadata from extended records
int retval = 0;
bool prev_extended = false; // prev header was extended
+ if( !rbuf.size() ) { show_error( mem_msg ); return 1; }
+
while( true ) // process one tar header per iteration
{
if( !prev_extended && ( member_begin = lseek( ad.infd, 0, SEEK_CUR ) ) < 0 )
- { show_error( "Seek error", errno ); retval = 1; break; }
+ { show_file_error( ad.namep, seek_msg, errno ); retval = 1; break; }
Tar_header header;
- const int ret = ar.read( header, header_size );
- if( ret != 0 ) { show_file_error( ar.ad.namep, ar.e_msg(), ar.e_code() );
- retval = ret; break; }
- if( !verify_ustar_chksum( header ) )
+ if( ( retval = ar.read( header, header_size ) ) != 0 )
+ { show_file_error( ad.namep, ar.e_msg(), ar.e_code() ); break; }
+ if( !verify_ustar_chksum( header ) ) // error or EOA
{
- if( block_is_zero( header, header_size ) ) // EOF
+ if( block_is_zero( header, header_size ) ) // EOA
{
if( prev_extended && !cl_opts.permissive )
{ show_file_error( ad.namep, fv_msg1 ); retval = 2; }
break;
}
- show_file_error( ad.namep, "Corrupt header in archive." );
+ // posix format already verified by archive reader
+ show_file_error( ad.namep, bad_hdr_msg );
retval = 2; break;
}
@@ -137,43 +140,38 @@ int delete_members( const Cl_options & cl_opts )
if( prev_extended && !cl_opts.permissive )
{ show_file_error( ad.namep, fv_msg2 ); retval = 2; break; }
Extended dummy; // global headers are parsed and ignored
- const int ret = ar.parse_records( dummy, header, rbuf, true );
- if( ret != 0 )
- { show_file_error( ad.namep, gblrec_msg ); retval = ret; break; }
+ retval = ar.parse_records( dummy, header, rbuf, gblrec_msg, true );
+ if( retval )
+ { show_file_error( ad.namep, ar.e_msg(), ar.e_code() ); break; }
continue;
}
if( typeflag == tf_extended )
{
if( prev_extended && !cl_opts.permissive )
{ show_file_error( ad.namep, fv_msg3 ); retval = 2; break; }
- const int ret = ar.parse_records( extended, header, rbuf,
- cl_opts.permissive );
- if( ret != 0 )
- { show_file_error( ad.namep, extrec_msg ); retval = ret; break; }
- else if( !extended.crc_present() && cl_opts.missing_crc )
- { show_file_error( ad.namep, mcrc_msg ); retval = 2; break; }
- prev_extended = true;
- continue;
+ if( ( retval = ar.parse_records( extended, header, rbuf, extrec_msg,
+ cl_opts.permissive ) ) != 0 )
+ { show_file_error( ad.namep, ar.e_msg(), ar.e_code() ); break; }
+ if( !extended.crc_present() && cl_opts.missing_crc )
+ { show_file_error( ad.namep, miscrc_msg ); retval = 2; break; }
+ prev_extended = true; continue;
}
prev_extended = false;
extended.fill_from_ustar( header ); // copy metadata from header
- {
- const int ret = ar.skip_member( extended );
- if( ret != 0 )
- { show_file_error( ad.namep, "Seek error", errno ); retval = ret; break; }
- }
+ if( ( retval = ar.skip_member( extended ) ) != 0 )
+ { show_file_error( ad.namep, seek_msg, errno ); break; }
// delete tar member
if( !check_skip_filename( cl_opts, name_pending, extended.path().c_str() ) )
{
+ print_removed_prefix( extended.removed_prefix );
if( !show_member_name( extended, header, 1, rbuf ) )
{ retval = 1; break; }
const long long pos = lseek( ad.infd, 0, SEEK_CUR );
if( pos <= 0 || pos <= member_begin || member_begin < istream_pos )
- { show_file_error( ad.namep, "Seek error", errno );
- retval = 1; break; }
+ { show_file_error( ad.namep, seek_msg, errno ); retval = 1; break; }
const long long size = member_begin - istream_pos;
if( size > 0 ) // move pending data each time a member is deleted
{