Class: Omnizip::Formats::Rar::ArchiveRepairer
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::ArchiveRepairer
- Defined in:
- lib/omnizip/formats/rar/archive_repairer.rb
Overview
RAR archive repair functionality Attempts to repair corrupted archives using recovery records
Defined Under Namespace
Classes: RepairResult
Instance Attribute Summary collapse
-
#parity_handler ⇒ Object
readonly
Returns the value of attribute parity_handler.
-
#recovery_record ⇒ Object
readonly
Returns the value of attribute recovery_record.
-
#verifier ⇒ Object
readonly
Returns the value of attribute verifier.
Instance Method Summary collapse
-
#initialize ⇒ ArchiveRepairer
constructor
Initialize repairer.
-
#quick_repair(archive_path, options = {}) ⇒ RepairResult
Attempt quick repair (in-place).
-
#repair(input_path, output_path, options = {}) ⇒ RepairResult
Repair corrupted archive.
Constructor Details
#initialize ⇒ ArchiveRepairer
Initialize repairer
51 52 53 54 55 |
# File 'lib/omnizip/formats/rar/archive_repairer.rb', line 51 def initialize @verifier = nil @recovery_record = nil @parity_handler = nil end |
Instance Attribute Details
#parity_handler ⇒ Object (readonly)
Returns the value of attribute parity_handler.
11 12 13 |
# File 'lib/omnizip/formats/rar/archive_repairer.rb', line 11 def parity_handler @parity_handler end |
#recovery_record ⇒ Object (readonly)
Returns the value of attribute recovery_record.
11 12 13 |
# File 'lib/omnizip/formats/rar/archive_repairer.rb', line 11 def recovery_record @recovery_record end |
#verifier ⇒ Object (readonly)
Returns the value of attribute verifier.
11 12 13 |
# File 'lib/omnizip/formats/rar/archive_repairer.rb', line 11 def verifier @verifier end |
Instance Method Details
#quick_repair(archive_path, options = {}) ⇒ RepairResult
Attempt quick repair (in-place)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/omnizip/formats/rar/archive_repairer.rb', line 112 def quick_repair(archive_path, = {}) # Create temporary output temp_output = "#{archive_path}.repaired" result = repair(archive_path, temp_output, ) if result.success? # Replace original with repaired FileUtils.mv(temp_output, archive_path, force: true) result.output_path = archive_path else # Clean up temp file FileUtils.rm_f(temp_output) end result end |
#repair(input_path, output_path, options = {}) ⇒ RepairResult
Repair corrupted archive
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/omnizip/formats/rar/archive_repairer.rb', line 66 def repair(input_path, output_path, = {}) result = RepairResult.new result.output_path = output_path begin # Verify archive first @verifier = ArchiveVerifier.new(input_path) verification = @verifier.verify( use_recovery: true, verbose: [:verbose], ) unless verification.recovery_available result.errors << "No recovery records available" return result end unless verification.can_repair? result.errors << "Corruption not recoverable" return result end # Perform repair @recovery_record = @verifier.recovery_record @parity_handler = @verifier.parity_handler perform_repair(input_path, output_path, verification, result, ) # Verify repaired archive if [:verify_repaired] && result.success verify_repaired_archive(output_path, result) end rescue StandardError => e result.success = false result.errors << "Repair error: #{e.}" end result end |