Document UnpackStrategy.

This commit is contained in:
Markus Reiter 2020-08-09 06:09:05 +02:00
parent b7e96e6096
commit 0e7f18a51e
35 changed files with 52 additions and 12 deletions

View File

@ -1,8 +1,12 @@
# frozen_string_literal: true
# Module containing all available strategies for unpacking archives.
#
# @api private
module UnpackStrategy
# Helper module for identifying the file type.
module Magic
# length of the longest regex (currently Tar)
# Length of the longest regex (currently Tar).
MAX_MAGIC_NUMBER_LENGTH = 262
refine Pathname do
@ -31,18 +35,18 @@ module UnpackStrategy
def self.strategies
@strategies ||= [
Tar, # needs to be before Bzip2/Gzip/Xz/Lzma
Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma.
Pax,
Gzip,
Lzma,
Xz,
Lzip,
Air, # needs to be before Zip
Jar, # needs to be before Zip
LuaRock, # needs to be before Zip
MicrosoftOfficeXml, # needs to be before Zip
Air, # Needs to be before `Zip`.
Jar, # Needs to be before `Zip`.
LuaRock, # Needs to be before `Zip`.
MicrosoftOfficeXml, # Needs to be before `Zip`.
Zip,
Pkg, # needs to be before Xar
Pkg, # Needs to be before `Xar`.
Xar,
Ttf,
Otf,
@ -50,10 +54,10 @@ module UnpackStrategy
Mercurial,
Subversion,
Cvs,
SelfExtractingExecutable, # needs to be before Cab
SelfExtractingExecutable, # Needs to be before `Cab`.
Cab,
Executable,
Dmg, # needs to be before Bzip2
Dmg, # Needs to be before `Bzip2`.
Bzip2,
Fossil,
Bazaar,

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking Adobe Air archives.
class Air
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Bazaar archives.
class Bazaar < Directory
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking bzip2 archives.
class Bzip2
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking Cabinet archives.
class Cab
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "tar"
module UnpackStrategy
# Strategy for unpacking compress archives.
class Compress < Tar
using Magic

View File

@ -3,6 +3,7 @@
require_relative "directory"
module UnpackStrategy
# Strategy for unpacking CVS repositories.
class Cvs < Directory
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking directories.
class Directory
include UnpackStrategy

View File

@ -3,9 +3,11 @@
require "tempfile"
module UnpackStrategy
# Strategy for unpacking disk images.
class Dmg
include UnpackStrategy
# Helper module for listing the contents of a volume mounted from a disk image.
module Bom
DMG_METADATA = Set.new(%w[
.background
@ -23,11 +25,12 @@ module UnpackStrategy
private_constant :DMG_METADATA
refine Pathname do
# Check if path is considered disk image metadata.
def dmg_metadata?
DMG_METADATA.include?(cleanpath.ascend.to_a.last.to_s)
end
# symlinks to system directories (commonly to /Applications)
# Check if path is a symlink to a system directory (commonly to /Applications).
def system_dir_symlink?
symlink? && MacOS.system_dir?(dirname.join(readlink))
end
@ -48,9 +51,9 @@ module UnpackStrategy
end
private_constant :Bom
using Bom
# Strategy for unpacking a volume mounted from a disk image.
class Mount
using Bom
include UnpackStrategy
def eject(verbose: false)

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking executables.
class Executable < Uncompressed
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking Fossil repositories.
class Fossil
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking archives with `unar`.
class GenericUnar
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Git repositories.
class Git < Directory
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking gzip archives.
class Gzip
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking Java archives.
class Jar < Uncompressed
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking LHa archives.
class Lha
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking LuaRock archives.
class LuaRock < Uncompressed
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking lzip archives.
class Lzip
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking LZMA archives.
class Lzma
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Mercurial repositories.
class Mercurial < Directory
using Magic

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking Microsoft Office documents.
class MicrosoftOfficeXml < Uncompressed
using Magic

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking OpenType fonts.
class Otf < Uncompressed
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking P7ZIP archives.
class P7Zip
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking pax archives.
class Pax
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking macOS package installers.
class Pkg < Uncompressed
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking RAR archives.
class Rar
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "generic_unar"
module UnpackStrategy
# Strategy for unpacking self-extracting executables.
class SelfExtractingExecutable < GenericUnar
using Magic

View File

@ -3,6 +3,7 @@
require_relative "generic_unar"
module UnpackStrategy
# Strategy for unpacking Stuffit archives.
class Sit < GenericUnar
using Magic

View File

@ -3,6 +3,7 @@
require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Subversion repositories.
class Subversion < Directory
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking tar archives.
class Tar
include UnpackStrategy

View File

@ -3,6 +3,7 @@
require_relative "uncompressed"
module UnpackStrategy
# Strategy for unpacking TrueType fonts.
class Ttf < Uncompressed
using Magic

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking uncompressed files.
class Uncompressed
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking xar archives.
class Xar
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking xz archives.
class Xz
include UnpackStrategy

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module UnpackStrategy
# Strategy for unpacking ZIP archives.
class Zip
include UnpackStrategy