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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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