Module: Archive::Tar

Included in:
Reader, Writer
Defined in:
lib/archive/tar.rb

Defined Under Namespace

Classes: Format, NoSuchEntryError, Reader, Stat, StreamReader, Writer, WriterError

Constant Summary collapse

VERSION =
"1.5.0"

Instance Method Summary collapse

Instance Method Details

#join_path(*files) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/archive/tar.rb', line 62

def join_path(*files)
  absolute = files[0][0] == "/"
  files = files.map do |element|
    normalize_path element
  end
  
  new_path = files.join("/")
  new_path = "/" + new_path if absolute
  
  new_path
end

#normalize_path(path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/archive/tar.rb', line 27

def normalize_path(path)
  path = path.gsub("\\", "/")

  while path[-1] == "/"
    path = path[0..-2]
  end
  
  while path[0] == "/"
    path = path[1..-1]
  end
  
  solve_path(path.gsub(/[\/]{2,}/, "/"))
end

#solve_path(path) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/archive/tar.rb', line 41

def solve_path(path)
  path_parts = path.split("/")
  realpath = []
  
  path_parts.each do |i|
    if i == "."
      next
    end
    
    if i == ".."
      realpath = realpath[1..-2]
      realpath = [] if realpath == nil
      next
    end
    
    realpath << i
  end
  
  realpath.join("/")
end