Class: FPM::Util::TarWriter

Inherits:
Gem::Package::TarWriter
  • Object
show all
Defined in:
lib/fpm/util/tar_writer.rb

Overview

Like the ::Gem::Package::TarWriter but contains some backports/latest and bug fixes

Instance Method Summary collapse

Instance Method Details



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fpm/util/tar_writer.rb', line 66

def add_symlink(name, target, mode)
  check_closed

  name, prefix = split_name name

  header = ::Gem::Package::TarHeader.new(:name => name, :mode => mode,
                                         :size => 0, :typeflag => "2",
                                         :linkname => target,
                                         :prefix => prefix,
                                         :mtime => Time.now).to_s

  @io.write header

  self
end

#split_name(name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fpm/util/tar_writer.rb', line 35

def split_name(name)
  if name.bytesize > 256 then
    raise ::Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)")
  end

  prefix = ''
  if name.bytesize > 100 then
    parts = name.split('/', -1) # parts are never empty here
    name = parts.pop            # initially empty for names with a trailing slash ("foo/.../bar/")
    prefix = parts.join('/')    # if empty, then it's impossible to split (parts is empty too)
    while !parts.empty? && (prefix.bytesize > 155 || name.empty?)
      name = parts.pop + '/' + name
      prefix = parts.join('/')
    end

    if name.bytesize > 100 or prefix.empty? then
      raise ::Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long name (should be 100 or less)")
    end

    if prefix.bytesize > 155 then
      raise ::Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long base path (should be 155 or less)")
    end
  end

  return name, prefix
end