summaryrefslogtreecommitdiffstats
path: root/range_dec.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-01-05 20:07:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-01-05 20:07:41 +0000
commit33c0b568b11710608255b337a45aff0d147de2b4 (patch)
tree0d2d18685bef4b160194b2980174b2ebd62d97e1 /range_dec.cc
parentAdding upstream version 1.20. (diff)
downloadlziprecover-33c0b568b11710608255b337a45aff0d147de2b4.tar.xz
lziprecover-33c0b568b11710608255b337a45aff0d147de2b4.zip
Adding upstream version 1.21.upstream/1.21
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'range_dec.cc')
-rw-r--r--range_dec.cc62
1 files changed, 31 insertions, 31 deletions
diff --git a/range_dec.cc b/range_dec.cc
index 803a540..78d586f 100644
--- a/range_dec.cc
+++ b/range_dec.cc
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- Copyright (C) 2009-2018 Antonio Diaz Diaz.
+ Copyright (C) 2009-2019 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
@@ -30,8 +30,7 @@
#include "lzip.h"
#include "decoder.h"
-#include "block.h"
-#include "file_index.h"
+#include "lzip_index.h"
namespace {
@@ -42,14 +41,15 @@ int decompress_member( const int infd, const Pretty_print & pp,
const unsigned long long outend )
{
Range_decoder rdec( infd );
- File_header header;
- rdec.read_data( header.data, File_header::size );
+ Lzip_header header;
+ rdec.read_data( header.data, Lzip_header::size );
if( rdec.finished() ) // End Of File
{ pp( "File ends unexpectedly at member header." ); return 2; }
- if( !verify_header( header, pp ) ) return 2;
+ if( !header.verify_magic() ) { pp( bad_magic_msg ); return 2; }
+ if( !header.verify_version() )
+ { pp( bad_version( header.version() ) ); return 2; }
const unsigned dictionary_size = header.dictionary_size();
- if( !isvalid_ds( dictionary_size ) )
- { pp( "Invalid dictionary size in member header." ); return 2; }
+ if( !isvalid_ds( dictionary_size ) ) { pp( bad_dict_msg ); return 2; }
if( verbosity >= 2 ) pp();
@@ -117,49 +117,49 @@ int range_decompress( const std::string & input_filename,
const int infd = open_instream( input_filename.c_str(), &in_stats, true, true );
if( infd < 0 ) return 1;
- Pretty_print pp( input_filename );
- const File_index file_index( infd, ignore_errors, ignore_trailing,
- loose_trailing );
- if( file_index.retval() != 0 )
- { show_file_error( input_filename.c_str(), file_index.error().c_str() );
- return file_index.retval(); }
-
- if( range.end() > file_index.udata_size() )
- range.size( std::max( 0LL, file_index.udata_size() - range.pos() ) );
- if( range.size() <= 0 )
- { pp( "Nothing to do." ); return 0; }
+ const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing,
+ ignore_errors, ignore_errors );
+ if( lzip_index.retval() != 0 )
+ { show_file_error( input_filename.c_str(), lzip_index.error().c_str() );
+ return lzip_index.retval(); }
- if( verbosity >= 1 )
- std::fprintf( stderr, "Decompressing range %sB to %sB (%sof %sBytes)\n",
- format_num( range.pos() ),
- format_num( range.pos() + range.size() ),
- format_num( range.size() ),
- format_num( file_index.udata_size() ) );
+ if( range.end() > lzip_index.udata_size() )
+ range.size( std::max( 0LL, lzip_index.udata_size() - range.pos() ) );
+ if( range.size() <= 0 )
+ { show_file_error( input_filename.c_str(), "Nothing to do." ); return 0; }
if( to_stdout || default_output_filename.empty() )
outfd = STDOUT_FILENO;
else
{
output_filename = default_output_filename;
+ set_signal_handler();
if( !open_outstream( force, false, false, false ) )
{ close( infd ); return 1; }
}
+ if( verbosity >= 1 )
+ std::fprintf( stderr, "Decompressing range %sB to %sB (%sof %sBytes)\n",
+ format_num( range.pos() ),
+ format_num( range.pos() + range.size() ),
+ format_num( range.size() ),
+ format_num( lzip_index.udata_size() ) );
+
+ Pretty_print pp( input_filename );
int retval = 0;
- for( long i = 0; i < file_index.members(); ++i )
+ for( long i = 0; i < lzip_index.members(); ++i )
{
- const Block & db = file_index.dblock( i );
+ const Block & db = lzip_index.dblock( i );
if( range.overlaps( db ) )
{
- if( verbosity >= 3 && file_index.members() > 1 )
+ if( verbosity >= 3 && lzip_index.members() > 1 )
std::fprintf( stderr, "Decompressing member %3ld\n", i + 1 );
const long long outskip = std::max( 0LL, range.pos() - db.pos() );
const long long outend = std::min( db.size(), range.end() - db.pos() );
- const long long mpos = file_index.mblock( i ).pos();
+ const long long mpos = lzip_index.mblock( i ).pos();
if( !safe_seek( infd, mpos ) ) { retval = 1; break; }
const int tmp = decompress_member( infd, pp, mpos, outskip, outend );
- if( tmp && ( tmp != 2 || !ignore_errors ) )
- cleanup_and_fail( tmp );
+ if( tmp && ( tmp != 2 || !ignore_errors ) ) cleanup_and_fail( tmp );
if( tmp > retval ) retval = tmp;
pp.reset();
}