Class: Omnizip::Formats::Rar::ArchiveRepairer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeArchiveRepairer

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_handlerObject (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_recordObject (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

#verifierObject (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)

Parameters:

  • archive_path (String)

    Path to archive

  • options (Hash) (defaults to: {})

    Repair options

Returns:



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, options = {})
  # Create temporary output
  temp_output = "#{archive_path}.repaired"

  result = repair(archive_path, temp_output, options)

  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

Parameters:

  • input_path (String)

    Path to corrupted archive

  • output_path (String)

    Path for repaired archive

  • options (Hash) (defaults to: {})

    Repair options

Options Hash (options):

  • :use_external_rev (Boolean)

    Use external .rev files

  • :verify_repaired (Boolean)

    Verify after repair

  • :verbose (Boolean)

    Enable verbose output

Returns:



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, options = {})
  result = RepairResult.new
  result.output_path = output_path

  begin
    # Verify archive first
    @verifier = ArchiveVerifier.new(input_path)
    verification = @verifier.verify(
      use_recovery: true,
      verbose: options[: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,
                   options)

    # Verify repaired archive
    if options[:verify_repaired] && result.success
      verify_repaired_archive(output_path, result)
    end
  rescue StandardError => e
    result.success = false
    result.errors << "Repair error: #{e.message}"
  end

  result
end