diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 11:45:45 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 11:45:45 +0000 |
commit | 5e8398a39d8758cb4dee9a43f92ac958277e0ebd (patch) | |
tree | 10ba2517467532e4a002f47cc32732f1f335eae0 /merge.cc | |
parent | Adding upstream version 1.16~pre1. (diff) | |
download | lziprecover-upstream/1.16_pre2.tar.xz lziprecover-upstream/1.16_pre2.zip |
Adding upstream version 1.16~pre2.upstream/1.16_pre2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r-- | merge.cc | 45 |
1 files changed, 20 insertions, 25 deletions
@@ -75,6 +75,7 @@ void combine( std::vector< Block > & block_vector, std::vector< Block > & bv ) } +// positions in 'block_vector' are absolute file positions. bool diff_member( const long long mpos, const long long msize, const std::vector< int > & infd_vector, std::vector< Block > & block_vector ) @@ -220,7 +221,7 @@ int open_input_files( const std::vector< std::string > & filenames, { const int infd = infd_vector[i]; bool error = false; - for( int j = 0; j < file_index.members(); ++j ) + for( long j = 0; j < file_index.members(); ++j ) { const long long mpos = file_index.mblock( j ).pos(); const long long msize = file_index.mblock( j ).size(); @@ -284,26 +285,21 @@ bool copy_file( const int infd, const int outfd, const long long max_size ) bool try_decompress_member( const int fd, const unsigned long long msize, long long * failure_posp ) { - try { - Range_decoder rdec( fd ); - File_header header; - rdec.read_data( header.data, File_header::size ); - if( !rdec.finished() && // End Of File - header.verify_magic() && header.verify_version() && - header.dictionary_size() >= min_dictionary_size && - header.dictionary_size() <= max_dictionary_size ) - { - LZ_decoder decoder( header, rdec, -1 ); - Pretty_print dummy( "", -1 ); + Range_decoder rdec( fd ); + File_header header; + rdec.read_data( header.data, File_header::size ); + if( !rdec.finished() && // End Of File + header.verify_magic() && header.verify_version() && + header.dictionary_size() >= min_dictionary_size && + header.dictionary_size() <= max_dictionary_size ) + { + LZ_decoder decoder( header, rdec, -1 ); + Pretty_print dummy( "", -1 ); - if( decoder.decode_member( dummy ) == 0 && - rdec.member_position() == msize ) return true; - if( failure_posp ) *failure_posp = rdec.member_position(); - } + if( decoder.decode_member( dummy ) == 0 && + rdec.member_position() == msize ) return true; + if( failure_posp ) *failure_posp = rdec.member_position(); } - catch( std::bad_alloc ) - { show_error( "Not enough memory." ); std::exit( 1 ); } - catch( Error e ) {} return false; } @@ -325,7 +321,7 @@ int merge_files( const std::vector< std::string > & filenames, if( !copy_file( infd_vector[0], outfd ) ) // copy whole file cleanup_and_fail( output_filename, outfd, 1 ); - for( int j = 0; j < file_index.members(); ++j ) + for( long j = 0; j < file_index.members(); ++j ) { const long long mpos = file_index.mblock( j ).pos(); const long long msize = file_index.mblock( j ).size(); @@ -360,7 +356,7 @@ int merge_files( const std::vector< std::string > & filenames, if( verbosity >= 1 && file_index.members() > 1 ) { - std::printf( "Merging member %d\n", j + 1 ); + std::printf( "Merging member %ld\n", j + 1 ); std::fflush( stdout ); } const int base_variations = ipow( files, block_vector.size() ); @@ -378,11 +374,10 @@ int merge_files( const std::vector< std::string > & filenames, { const int infd = infd_vector[tmp % files]; tmp /= files; - if( lseek( infd, block_vector[i].pos(), SEEK_SET ) < 0 || - lseek( outfd, block_vector[i].pos(), SEEK_SET ) < 0 || + if( !safe_seek( infd, block_vector[i].pos() ) || + !safe_seek( outfd, block_vector[i].pos() ) || !copy_file( infd, outfd, block_vector[i].size() ) ) - { show_error( "Error reading output file", errno ); - cleanup_and_fail( output_filename, outfd, 1 ); } + cleanup_and_fail( output_filename, outfd, 1 ); } if( !safe_seek( outfd, mpos ) ) cleanup_and_fail( output_filename, outfd, 1 ); |