Module: Metaclean

Defined in:
lib/metaclean/display.rb,
lib/metaclean.rb,
lib/metaclean/cli.rb,
lib/metaclean/mat2.rb,
lib/metaclean/qpdf.rb,
lib/metaclean/ffmpeg.rb,
lib/metaclean/runner.rb,
lib/metaclean/version.rb,
lib/metaclean/exiftool.rb,
lib/metaclean/strategy.rb

Overview

The “policy” module: which tools to run for which file, and what counts as privacy-relevant if it survives a clean.

Keeping this logic in its own file means the runner doesn’t need to know about formats — it just asks Strategy.tools_for(path) and runs whatever comes back.

Defined Under Namespace

Modules: Display, Exiftool, Ffmpeg, Mat2, Qpdf, Strategy Classes: CLI, Error, Runner, ToolsMissing

Constant Summary collapse

TMP_MARKER =

Marker embedded in every staging-temp filename (Runner, Ffmpeg, Qpdf) and matched by Runner#skip?, so a leftover temp from an interrupted run is ignored on a later directory scan. One literal keeps the producers and the matcher from drifting (qpdf previously embedded a divergent “.metaclean.qpdf.tmp.” that didn’t contain this marker).

'.metaclean.tmp.'
CLEAN_SUFFIX =

Suffix of the default “<name>_clean.<ext>” outputs. Runner#build_clean_path writes it; CLEAN_OUTPUT_RE derives the loop-prevention match from it so the producer and Runner#skip? can’t disagree.

'_clean'
CLEAN_OUTPUT_RE =

Matches our own “<name>_clean.<ext>” outputs (with optional “_N” collision counter) so a recursive re-run doesn’t re-clean them. Compiled once here, in the module body that runs after the requires, so CLEAN_SUFFIX exists.

/#{Regexp.escape(CLEAN_SUFFIX)}(_\d+)?\.[^.]+\z/
VERSION =
'4.0.1'

Class Method Summary collapse

Class Method Details

.ensure_tools!Object

Preflight: all four tools must be installed. We run them together for full coverage and to verify the strip, so a partial toolchain is not “good enough” — bail with one clear message naming what’s missing and how to install everything. Called once by the CLI before any inspect/clean work.

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/metaclean.rb', line 63

def self.ensure_tools!
  missing = []
  missing << 'exiftool' unless Exiftool.available?
  missing << 'mat2'     unless Mat2.available?
  missing << 'qpdf'     unless Qpdf.available?
  missing << 'ffmpeg'   unless Ffmpeg.available?
  return if missing.empty?

  raise ToolsMissing, <<~MSG
    Missing required tool(s): #{missing.join(', ')}

    metaclean needs ExifTool, mat2, qpdf and ffmpeg together. Install all four:
      macOS:          brew install exiftool mat2 qpdf ffmpeg
      Debian/Ubuntu:  sudo apt install libimage-exiftool-perl mat2 qpdf ffmpeg
      Fedora:         sudo dnf install perl-Image-ExifTool mat2 qpdf ffmpeg
      Arch:           sudo pacman -S perl-image-exiftool mat2 qpdf ffmpeg
      Windows:        use WSL2 (https://learn.microsoft.com/windows/wsl/install) + the Debian/Ubuntu line
  MSG
end

.ext_of(path) ⇒ Object

Lower-cased, dot-stripped extension used for FORMAT ROUTING decisions (Strategy#tools_for, Strategy#mat2_essential?, Mat2.supports?). One definition so every routing path normalizes the extension identically —a future tweak (double extensions, locale-safe downcasing) lands once.



38
39
40
# File 'lib/metaclean.rb', line 38

def self.ext_of(path)
  File.extname(path.to_s).downcase.delete('.')
end

.safe_path(path) ⇒ Object

A path beginning with “-” is misread as an option by the tools we shell out to — e.g. exiftool’s ‘-config FILE` loads and runs arbitrary Perl. Open3 argument arrays bypass the shell, but NOT the invoked tool’s own option parser. Prefixing a leading-dash relative path with “./” makes it unambiguously a filename to every tool. Absolute paths and normal names pass through untouched. Used at every shell-out boundary.



29
30
31
32
# File 'lib/metaclean.rb', line 29

def self.safe_path(path)
  s = path.to_s
  s.start_with?('-') ? File.join('.', s) : s
end