Class: Packages::PackageExtractor
- Inherits:
-
Object
- Object
- Packages::PackageExtractor
- Includes:
- Yast::Logger
- Defined in:
- library/packages/src/lib/packages/package_extractor.rb
Overview
Extracts the RPM package contents to a directory.
Constant Summary collapse
- EXTRACT_CMD =
Command to extract an RPM, the contents is extracted into the current working directory.
"rpm2cpio %<source>s | cpio --quiet --sparse -dimu --no-absolute-filenames".freeze
Instance Attribute Summary collapse
-
#package_path ⇒ String
readonly
Path to the package to extract.
Instance Method Summary collapse
-
#extract(dir) ⇒ Object
Extracts the RPM contents to the given directory.
-
#initialize(package_path) ⇒ PackageExtractor
constructor
Constructor.
Constructor Details
#initialize(package_path) ⇒ PackageExtractor
Constructor
39 40 41 |
# File 'library/packages/src/lib/packages/package_extractor.rb', line 39 def initialize(package_path) @package_path = package_path end |
Instance Attribute Details
#package_path ⇒ String (readonly)
Path to the package to extract.
34 35 36 |
# File 'library/packages/src/lib/packages/package_extractor.rb', line 34 def package_path @package_path end |
Instance Method Details
#extract(dir) ⇒ Object
Extracts the RPM contents to the given directory.
It is responsibility of the caller to remove the extracted content when it is not needed anymore.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'library/packages/src/lib/packages/package_extractor.rb', line 55 def extract(dir) Dir.chdir(dir) do cmd = format(EXTRACT_CMD, source: Shellwords.escape(package_path)) log.info("Extracting package #{package_path} to #{dir}...") # we need a shell to process the pipe, # the "allowed_exitstatus" option forces Cheetah to return the exit code ret = Yast::Execute.locally("sh", "-c", cmd, allowed_exitstatus: 0..255) log.info("Extraction result: #{ret}") raise Y2Packager::PackageExtractionError unless ret.zero? end end |