Method: Puppet::Modulebuilder::Builder#validate_ustar_path!

Defined in:
lib/puppet/modulebuilder/builder.rb

#validate_ustar_path!(path) ⇒ nil

Checks if the path length will fit into the POSIX.1-1998 (ustar) tar header format.

POSIX.1-2001 (which allows paths of infinite length) was adopted by GNU tar in 2004 and is supported by minitar 0.7 and above. Unfortunately much of the Puppet ecosystem still uses minitar 0.6.1.

POSIX.1-1998 tar format does not allow for paths greater than 256 bytes, or paths that can’t be split into a prefix of 155 bytes (max) and a suffix of 100 bytes (max).

This logic was pretty much copied from the private method Archive::Tar::Minitar::Writer#split_name.

Parameters:

  • path (String)

    the relative path to be added to the tar file.

Returns:

  • (nil)

Raises:

  • (ArgumentError)

    if the path is too long or could not be split.



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/puppet/modulebuilder/builder.rb', line 364

def validate_ustar_path!(path)
  raise ArgumentError, format("The path '%<path>s' is longer than 256 bytes.", path: path) if path.bytesize > 256

  if path.bytesize <= 100
    prefix = ''
  else
    parts = path.split(File::SEPARATOR)
    newpath = parts.pop
    nxt = ''

    loop do
      nxt = parts.pop || ''
      break if newpath.bytesize + 1 + nxt.bytesize >= 100

      newpath = File.join(nxt, newpath)
    end

    prefix = File.join(*parts, nxt)
    path = newpath
  end

  return unless path.bytesize > 100 || prefix.bytesize > 155

  raise ArgumentError, \
        format("'%<path>s' could not be split at a directory separator into two " \
               'parts, the first having a maximum length of 155 bytes and the ' \
               'second having a maximum length of 100 bytes.', path: path)
end