Skip to content

Commit

Permalink
merge #164 and #168
Browse files Browse the repository at this point in the history
  • Loading branch information
morph027 committed Jul 8, 2020
1 parent 5e6ac28 commit b305fef
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.bundle
/.idea/
*.gem
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.0
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.2.0
- 2.5
- 2.6
- 2.7
before_install:
- gem update bundler
22 changes: 12 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ PATH
GEM
remote: https://rubygems.org/
specs:
aws-sdk (2.7.12)
aws-sdk-resources (= 2.7.12)
aws-sdk-core (2.7.12)
aws-eventstream (1.0.3)
aws-sdk (2.11.454)
aws-sdk-resources (= 2.11.454)
aws-sdk-core (2.11.454)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-resources (2.7.12)
aws-sdk-core (= 2.7.12)
aws-sigv4 (1.0.0)
jmespath (1.3.1)
minitest (5.0.8)
rake (11.1.2)
aws-sdk-resources (2.11.454)
aws-sdk-core (= 2.11.454)
aws-sigv4 (1.1.1)
aws-eventstream (~> 1.0, >= 1.0.2)
jmespath (1.4.0)
minitest (5.14.0)
rake (11.3.0)
thor (0.19.4)

PLATFORMS
Expand All @@ -30,4 +32,4 @@ DEPENDENCIES
rake (~> 11)

BUNDLED WITH
1.15.4
1.17.3
67 changes: 45 additions & 22 deletions lib/deb/s3/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@ def upload(*files)
# throw an error. This is mainly the case when initializing a brand new
# repository. With "all", we won't know which architectures they're using.
if arch == "all" && manifests.count == 0
error("Package #{File.basename(file)} had architecture \"all\", " +
"however noexisting package lists exist. This can often happen " +
"if the first package you are add to a new repository is an " +
"\"all\" architecture file. Please use --arch [i386|amd64|armhf] or " +
"another platform type to upload the file.")
manifests['amd64'] = Deb::S3::Manifest.retrieve(options[:codename], component,'amd64', options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
manifests['i386'] = Deb::S3::Manifest.retrieve(options[:codename], component,'i386', options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
manifests['armhf'] = Deb::S3::Manifest.retrieve(options[:codename], component,'armhf', options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])

# error("Package #{File.basename(file)} had architecture \"all\", " +
# "however noexisting package lists exist. This can often happen " +
# "if the first package you are add to a new repository is an " +
# "\"all\" architecture file. Please use --arch [i386|amd64|armhf] or " +
# "another platform type to upload the file.")
end

# retrieve the manifest for the arch if we don't have it already
Expand Down Expand Up @@ -469,27 +473,46 @@ def delete(package)
# retrieve the existing manifests
log("Retrieving existing manifests")
release = Deb::S3::Release.retrieve(options[:codename], options[:origin], options[:suite])
manifest = Deb::S3::Manifest.retrieve(options[:codename], component, options[:arch], options[:cache_control], false, options[:skip_package_upload])

deleted = manifest.delete_package(package, versions)
if deleted.length == 0
if versions.nil?
error("No packages were deleted. #{package} not found.")
else
error("No packages were deleted. #{package} versions #{versions.join(', ')} could not be found.")
end
if arch == 'all'
selected_arch = release.architectures
else
deleted.each { |p|
sublog("Deleting #{p.name} version #{p.full_version}")
}
selected_arch = [arch]
end
all_found = 0
selected_arch.each { |ar|
manifest = Deb::S3::Manifest.retrieve(options[:codename], component, ar, options[:cache_control], false, options[:skip_package_upload])

deleted = manifest.delete_package(package, versions)
all_found += deleted.length
if deleted.length == 0
if versions.nil?
sublog("No packages were deleted. #{package} not found in arch #{ar}.")
next
else
sublog("No packages were deleted. #{package} versions #{versions.join(', ')} could not be found in arch #{ar}.")
next
end
else
deleted.each { |p|
sublog("Deleting #{p.name} version #{p.full_version} from arch #{ar}")
}
end

log("Uploading new manifests to S3")
manifest.write_to_s3 {|f| sublog("Transferring #{f}") }
release.update_manifest(manifest)
release.write_to_s3 {|f| sublog("Transferring #{f}") }
log("Uploading new manifests to S3")
manifest.write_to_s3 {|f| sublog("Transferring #{f}") }
release.update_manifest(manifest)
release.write_to_s3 {|f| sublog("Transferring #{f}") }

log("Update complete.")
}
if all_found == 0
if versions.nil?
error("No packages were deleted. #{package} not found.")
else
error("No packages were deleted. #{package} versions #{versions.join(', ')} could not be found.")
end
end

log("Update complete.")
end


Expand Down
19 changes: 15 additions & 4 deletions lib/deb/s3/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,31 @@ def extract_control(package)
if system("which dpkg > /dev/null 2>&1")
`dpkg -f #{package}`
else
# use ar to determine control file name (control.ext)
package_files = `ar t #{package}`
control_file = package_files.split("\n").select do |file|
file.start_with?("control.")
end.first
if control_file === "control.tar.gz"
compression = "z"
else
compression = "J"
end

# ar fails to find the control.tar.gz tarball within the .deb
# on Mac OS. Try using ar to list the control file, if found,
# use ar to extract, otherwise attempt with tar which works on OS X.
extract_control_tarball_cmd = "ar p #{package} control.tar.gz"
extract_control_tarball_cmd = "ar p #{package} #{control_file}"

begin
safesystem("ar t #{package} control.tar.gz &> /dev/null")
safesystem("ar t #{package} #{control_file} &> /dev/null")
rescue SafeSystemError
warn "Failed to find control data in .deb with ar, trying tar."
extract_control_tarball_cmd = "tar zxf #{package} --to-stdout control.tar.gz"
extract_control_tarball_cmd = "tar #{compression}xf #{package} --to-stdout #{control_file}"
end

Dir.mktmpdir do |path|
safesystem("#{extract_control_tarball_cmd} | tar -zxf - -C #{path}")
safesystem("#{extract_control_tarball_cmd} | tar -#{compression}xf - -C #{path}")
File.read(File.join(path, "control"))
end
end
Expand Down

0 comments on commit b305fef

Please sign in to comment.