lib/omnibus/fetchers/net_fetcher.rb in omnibus-5.4.0 vs lib/omnibus/fetchers/net_fetcher.rb in omnibus-5.5.0
- old
+ new
@@ -12,23 +12,23 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'fileutils'
-require 'omnibus/download_helpers'
+require "fileutils"
+require "omnibus/download_helpers"
module Omnibus
class NetFetcher < Fetcher
include DownloadHelpers
# Use 7-zip to extract 7z/zip for Windows
- WIN_7Z_EXTENSIONS = %w(.7z .zip)
+ WIN_7Z_EXTENSIONS = %w{.7z .zip}
# tar probably has compression scheme linked in, otherwise for tarballs
- COMPRESSED_TAR_EXTENSIONS = %w(.tar.gz .tgz tar.bz2 .tar.xz .txz .tar.lzma)
- TAR_EXTENSIONS = COMPRESSED_TAR_EXTENSIONS + ['.tar']
+ COMPRESSED_TAR_EXTENSIONS = %w{.tar.gz .tgz tar.bz2 .tar.xz .txz .tar.lzma}
+ TAR_EXTENSIONS = COMPRESSED_TAR_EXTENSIONS + [".tar"]
ALL_EXTENSIONS = WIN_7Z_EXTENSIONS + TAR_EXTENSIONS
# Digest types used for verifying file checksums
DIGESTS = [:sha512, :sha256, :sha1, :md5]
@@ -116,11 +116,11 @@
# presence of a +source_uri+.
#
# @return [String]
#
def downloaded_file
- filename = File.basename(source[:url], '?*')
+ filename = File.basename(source[:url], "?*")
File.join(Config.cache_dir, filename)
end
#
# The checksum as defined by the user in the software definition.
@@ -166,11 +166,11 @@
log.warn(log_key) { "Permitting unsafe redirects!" }
options[:allow_unsafe_redirects] = true
end
# Set the cookie if one was given
- options['Cookie'] = source[:cookie] if source[:cookie]
+ options["Cookie"] = source[:cookie] if source[:cookie]
download_file!(download_url, downloaded_file, options)
end
#
@@ -227,41 +227,41 @@
# cleaning an existing project_dir. It should be less of a problem now...
# but who knows.
#
def extract
# Only used by tar
- compression_switch = ''
- compression_switch = 'z' if downloaded_file.end_with?('gz')
- compression_switch = '--lzma -' if downloaded_file.end_with?('lzma')
- compression_switch = 'j' if downloaded_file.end_with?('bz2')
- compression_switch = 'J' if downloaded_file.end_with?('xz')
+ compression_switch = ""
+ compression_switch = "z" if downloaded_file.end_with?("gz")
+ compression_switch = "--lzma -" if downloaded_file.end_with?("lzma")
+ compression_switch = "j" if downloaded_file.end_with?("bz2")
+ compression_switch = "J" if downloaded_file.end_with?("xz")
- if Ohai['platform'] == 'windows'
+ if Ohai["platform"] == "windows"
if downloaded_file.end_with?(*TAR_EXTENSIONS) && source[:extract] != :seven_zip
returns = [0]
returns << 1 if source[:extract] == :lax_tar
- shellout!("tar.exe #{compression_switch}xf #{safe_downloaded_file} -C#{safe_project_dir}", returns: returns)
+ shellout!("tar #{compression_switch}xf #{safe_downloaded_file} -C#{safe_project_dir}", returns: returns)
elsif downloaded_file.end_with?(*COMPRESSED_TAR_EXTENSIONS)
Dir.mktmpdir do |temp_dir|
log.debug(log_key) { "Temporarily extracting `#{safe_downloaded_file}' to `#{temp_dir}'" }
shellout!("7z.exe x #{safe_downloaded_file} -o#{windows_safe_path(temp_dir)} -r -y")
fname = File.basename(downloaded_file, File.extname(downloaded_file))
- fname << ".tar" if downloaded_file.end_with?('tgz', 'txz')
+ fname << ".tar" if downloaded_file.end_with?("tgz", "txz")
next_file = windows_safe_path(File.join(temp_dir, fname))
log.debug(log_key) { "Temporarily extracting `#{next_file}' to `#{safe_project_dir}'" }
shellout!("7z.exe x #{next_file} -o#{safe_project_dir} -r -y")
end
else
shellout!("7z.exe x #{safe_downloaded_file} -o#{safe_project_dir} -r -y")
end
- elsif downloaded_file.end_with?('.7z')
+ elsif downloaded_file.end_with?(".7z")
shellout!("7z x #{safe_downloaded_file} -o#{safe_project_dir} -r -y")
- elsif downloaded_file.end_with?('.zip')
+ elsif downloaded_file.end_with?(".zip")
shellout!("unzip #{safe_downloaded_file} -d #{safe_project_dir}")
else
shellout!("#{tar} #{compression_switch}xf #{safe_downloaded_file} -C#{safe_project_dir}")
end
end
@@ -286,11 +286,11 @@
#
# @raise [ChecksumMismatch]
# if the checksum does not match
#
def verify_checksum!
- log.info(log_key) { 'Verifying checksum' }
+ log.info(log_key) { "Verifying checksum" }
expected = checksum
actual = digest(downloaded_file, digest_type)
if expected != actual
@@ -319,9 +319,9 @@
# If gtar is present, we will use gtar (AIX). Otherwise, we fallback to tar.
#
# @return [String]
#
def tar
- Omnibus.which('gtar') ? 'gtar' : 'tar'
+ Omnibus.which("gtar") ? "gtar" : "tar"
end
end
end