class FPM::Fry::Source::Patched::Cache
Attributes
inner[R]
Public Class Methods
new(*_)
click to toggle source
Calls superclass method
# File lib/fpm/fry/source/patched.rb, line 15 def initialize(*_) @updated = false super @inner = package.inner.build_cache(tmpdir) end
Public Instance Methods
cachekey()
click to toggle source
# File lib/fpm/fry/source/patched.rb, line 88 def cachekey dig = Digest::SHA2.new dig << inner.cachekey << "\x00" package.patches.each do |patch| dig.file(patch[:file]) dig << "\x00" end return dig.hexdigest end
tar_io()
click to toggle source
# File lib/fpm/fry/source/patched.rb, line 83 def tar_io update! return Exec::popen('tar','-c','.',chdir: unpacked_tmpdir, logger: logger) end
unpacked_tmpdir()
click to toggle source
# File lib/fpm/fry/source/patched.rb, line 98 def unpacked_tmpdir File.join(tmpdir, cachekey) end
Private Instance Methods
update!()
click to toggle source
# File lib/fpm/fry/source/patched.rb, line 21 def update! return if @updated if !File.directory?(unpacked_tmpdir) workdir = unpacked_tmpdir + '.tmp' begin FileUtils.mkdir(workdir) rescue Errno::EEXIST FileUtils.rm_rf(workdir) FileUtils.mkdir(workdir) end if inner.respond_to? :copy_to inner.copy_to(workdir) else ex = Tar::Extractor.new(logger: logger) tio = inner.tar_io begin ex.extract(workdir, FPM::Fry::Tar::Reader.new(tio), chown: false) ensure tio.close end end base = workdir if inner.respond_to? :prefix base = File.expand_path(inner.prefix, base) end package.patches.each do |patch| cmd = ['patch','-t','-p1','-i',patch[:file]] chdir = base if patch.key? :chdir given_chdir = File.expand_path(patch[:chdir],workdir) if given_chdir != chdir chdir = given_chdir else logger.hint("You can remove the chdir: #{patch[:chdir].inspect} option for #{patch[:file]}. The given value is the default.", documentation: 'https://github.com/xing/fpm-fry/wiki/Source-patching#chdir' ) end end begin Fry::Exec[*cmd, chdir: chdir, logger: logger] rescue Exec::Failed => e raise CacheFailed.new(e, patch: patch[:file]) end end File.rename(workdir, unpacked_tmpdir) else # base = unpacked_tmpdir if inner.respond_to? :prefix base = File.expand_path(inner.prefix, base) end package.patches.each do |patch| if patch.key? :chdir given_chdir = File.expand_path(patch[:chdir],unpacked_tmpdir) if given_chdir == base logger.hint("You can remove the chdir: #{patch[:chdir].inspect} option for #{patch[:file]}. The given value is the default.", documentation: 'https://github.com/xing/fpm-fry/wiki/Source-patching#chdir' ) end end end end @updated = true end