Document UnpackStrategy.
This commit is contained in:
parent
b7e96e6096
commit
0e7f18a51e
@ -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,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Adobe Air archives.
|
||||
class Air
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "directory"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Bazaar archives.
|
||||
class Bazaar < Directory
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking bzip2 archives.
|
||||
class Bzip2
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Cabinet archives.
|
||||
class Cab
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "tar"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking compress archives.
|
||||
class Compress < Tar
|
||||
using Magic
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "directory"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking CVS repositories.
|
||||
class Cvs < Directory
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking directories.
|
||||
class Directory
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking executables.
|
||||
class Executable < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Fossil repositories.
|
||||
class Fossil
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking archives with `unar`.
|
||||
class GenericUnar
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "directory"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Git repositories.
|
||||
class Git < Directory
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking gzip archives.
|
||||
class Gzip
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Java archives.
|
||||
class Jar < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking LHa archives.
|
||||
class Lha
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking LuaRock archives.
|
||||
class LuaRock < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking lzip archives.
|
||||
class Lzip
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking LZMA archives.
|
||||
class Lzma
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "directory"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Mercurial repositories.
|
||||
class Mercurial < Directory
|
||||
using Magic
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Microsoft Office documents.
|
||||
class MicrosoftOfficeXml < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking OpenType fonts.
|
||||
class Otf < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking P7ZIP archives.
|
||||
class P7Zip
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking pax archives.
|
||||
class Pax
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking macOS package installers.
|
||||
class Pkg < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking RAR archives.
|
||||
class Rar
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "generic_unar"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking self-extracting executables.
|
||||
class SelfExtractingExecutable < GenericUnar
|
||||
using Magic
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "generic_unar"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Stuffit archives.
|
||||
class Sit < GenericUnar
|
||||
using Magic
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "directory"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking Subversion repositories.
|
||||
class Subversion < Directory
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking tar archives.
|
||||
class Tar
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
require_relative "uncompressed"
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking TrueType fonts.
|
||||
class Ttf < Uncompressed
|
||||
using Magic
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking uncompressed files.
|
||||
class Uncompressed
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking xar archives.
|
||||
class Xar
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking xz archives.
|
||||
class Xz
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
# Strategy for unpacking ZIP archives.
|
||||
class Zip
|
||||
include UnpackStrategy
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user