diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-16 11:13:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-16 11:13:24 +0000 |
commit | d7c278fca708bc2c4badaeac041ecb136a4ef955 (patch) | |
tree | 5b163b83e6e3171a311f67187aa75c0f96f98f13 /range_dec.cc | |
parent | Adding upstream version 1.23. (diff) | |
download | lziprecover-d7c278fca708bc2c4badaeac041ecb136a4ef955.tar.xz lziprecover-d7c278fca708bc2c4badaeac041ecb136a4ef955.zip |
Adding upstream version 1.24~pre1.upstream/1.24_pre1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | range_dec.cc | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/range_dec.cc b/range_dec.cc index ea7f7e7..b6000ec 100644 --- a/range_dec.cc +++ b/range_dec.cc @@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for the lzip format - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2023 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 @@ -45,8 +45,8 @@ bool decompress_member( const int infd, const Pretty_print & pp, rdec.read_data( header.data, Lzip_header::size ); if( rdec.finished() ) // End Of File { pp( "File ends unexpectedly at member header." ); return false; } - if( !header.verify_magic() ) { pp( bad_magic_msg ); return false; } - if( !header.verify_version() ) + if( !header.check_magic() ) { pp( bad_magic_msg ); return false; } + if( !header.check_version() ) { pp( bad_version( header.version() ) ); return false; } const unsigned dictionary_size = header.dictionary_size(); if( !isvalid_ds( dictionary_size ) ) { pp( bad_dict_msg ); return false; } @@ -113,36 +113,36 @@ const char * format_num( unsigned long long num, } -bool safe_seek( const int fd, const long long pos ) +bool safe_seek( const int fd, const long long pos, + const char * const filename ) { if( lseek( fd, pos, SEEK_SET ) == pos ) return true; - show_error( "Seek error", errno ); return false; + show_file_error( filename, "Seek error", errno ); + return false; } int range_decompress( const std::string & input_filename, const std::string & default_output_filename, - Block range, const bool force, const bool ignore_errors, - const bool ignore_trailing, const bool loose_trailing, - const bool to_stdout ) + const Cl_options & cl_opts, Block range, + const bool force, const bool to_stdout ) { + const char * const filename = input_filename.c_str(); struct stat in_stats; - const int infd = - open_instream( input_filename.c_str(), &in_stats, false, true ); + const int infd = open_instream( filename, &in_stats, false, true ); if( infd < 0 ) return 1; - const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing, - ignore_errors, ignore_errors ); + const Lzip_index lzip_index( infd, cl_opts, cl_opts.ignore_errors, + cl_opts.ignore_errors ); if( lzip_index.retval() != 0 ) - { show_file_error( input_filename.c_str(), lzip_index.error().c_str() ); + { show_file_error( filename, lzip_index.error().c_str() ); return lzip_index.retval(); } const long long udata_size = lzip_index.udata_size(); if( range.end() > udata_size ) range.size( std::max( 0LL, udata_size - range.pos() ) ); if( range.size() <= 0 ) - { if( udata_size > 0 ) - show_file_error( input_filename.c_str(), "Nothing to do." ); + { if( udata_size > 0 ) show_file_error( filename, "Nothing to do." ); return 0; } if( to_stdout || default_output_filename.empty() ) outfd = STDOUT_FILENO; @@ -171,13 +171,15 @@ int range_decompress( const std::string & input_filename, 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 = lzip_index.mblock( i ).pos(); - if( !safe_seek( infd, mpos ) ) cleanup_and_fail( 1 ); + if( !safe_seek( infd, mpos, filename ) ) cleanup_and_fail( 1 ); if( !decompress_member( infd, pp, mpos, outskip, outend ) ) - { if( !ignore_errors ) cleanup_and_fail( 2 ); else error = true; } + { if( cl_opts.ignore_errors ) error = true; else cleanup_and_fail( 2 ); } pp.reset(); } } - close( infd ); + if( close( infd ) != 0 ) + { show_file_error( filename, "Error closing input file", errno ); + cleanup_and_fail( 1 ); } if( close_outstream( &in_stats ) != 0 ) cleanup_and_fail( 1 ); if( verbosity >= 2 && !error ) std::fputs( "Byte range decompressed successfully.\n", stderr ); |