Skip to content

Refactor RPM::File#files #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arr-pm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
spec.email = ["[email protected]"]

spec.add_development_dependency "flores", ">0"
spec.add_development_dependency "rspec", ">3.0.0"
#spec.homepage = "..."
end

49 changes: 6 additions & 43 deletions lib/arr-pm/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,49 +195,12 @@ def config_files
#
# % rpm2cpio blah.rpm | cpio -it
def files
return @files unless @files.nil?

lister = IO.popen("#{tags[:payloadcompressor]} -d | cpio -it --quiet", "r+")
buffer = ""
begin
buffer.force_encoding("BINARY")
rescue NoMethodError
# Do Nothing
end
payload_fd = payload.clone
output = ""
loop do
data = payload_fd.read(16384, buffer)
break if data.nil? # listerextractor.write(data)
lister.write(data)

# Read output from the pipe.
begin
output << lister.read_nonblock(16384)
rescue Errno::EAGAIN
# Nothing to read, move on!
end
end
lister.close_write

# Read remaining output
begin
output << lister.read
rescue Errno::EAGAIN
# Because read_nonblock enables NONBLOCK the 'lister' fd,
# and we may have invoked a read *before* cpio has started
# writing, let's keep retrying this read until we get an EOF
retry
rescue EOFError
# At EOF, hurray! We're done reading.
end

# Split output by newline and strip leading "."
@files = output.split("\n").collect { |s| s.gsub(/^\./, "") }
return @files
ensure
lister.close unless lister.nil?
payload_fd.close unless payload_fd.nil?
# RPM stores the file metadata split across multiple tags.
# A single path's filename (with no directories) is stored in the "basename" tag.
# The directory a file lives in is stored in the "dirnames" tag
#
# We can join each entry of dirnames and basenames to make the full filename.
return tags[:dirnames].zip(tags[:basenames]).map &File.method(:join)
end # def files

def mask?(value, mask)
Expand Down
Binary file not shown.
22 changes: 22 additions & 0 deletions spec/rpm/file_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# encoding: utf-8

require "arr-pm/file"

describe ::RPM::File do
context "with a known good rpm" do
let(:path) { File.join(File.dirname(__FILE__), "../fixtures/pagure-mirror-5.13.2-5.fc35.noarch.rpm") }
subject { described_class.new(path) }

context "#files" do
let(:files) { [
"/usr/lib/systemd/system/pagure_mirror.service",
"/usr/share/licenses/pagure-mirror",
"/usr/share/licenses/pagure-mirror/LICENSE"
]}

it "should have the correct list of files" do
expect(subject.files).to eq(files)
end
end
end
end