Class: FPM::Source::Dir

Inherits:
FPM::Source show all
Defined in:
lib/fpm/source/dir.rb

Instance Attribute Summary

Attributes inherited from FPM::Source

#paths, #root

Instance Method Summary collapse

Methods inherited from FPM::Source

#[], #[]=, #dependencies, #get_source, #initialize, #metadata, #package

Constructor Details

This class inherits a constructor from FPM::Source

Instance Method Details

#get_metadataObject



7
8
9
# File 'lib/fpm/source/dir.rb', line 7

def 
  self[:name] = File.basename(File.expand_path(root))
end

#make_tarball!(tar_path, builddir) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fpm/source/dir.rb', line 11

def make_tarball!(tar_path, builddir)
  if self[:prefix]
    # Trim leading '/' from prefix
    self[:prefix] = self[:prefix][1..-1] if self[:prefix] =~ /^\//

    # Prefix all files with a path if given.
    @paths.each do |path|
      # Trim @root (--chdir)
      if @root != "." and path.start_with?(@root)
        path = path[@root.size .. -1]
      end

      # Copy to self[:prefix] (aka --prefix)
      if File.directory?(path)
        # Turn 'path' into 'path/' so rsync copies it properly.
        path = "#{path}/" if path[-1,1] != "/"
        dest = "#{builddir}/tarbuild/#{self[:prefix]}/#{path}"
      else
        dest = "#{builddir}/tarbuild/#{self[:prefix]}/#{File.dirname(path)}"
      end

      ::FileUtils.mkdir_p(dest)
      rsync = ["rsync", "-a", path, dest]
      p rsync if $DEBUG
      safesystem(*rsync)

      # FileUtils.cp_r is pretty silly about how it copies files in some
      # cases (funky permissions, etc)
      # Use rsync instead..
      #FileUtils.cp_r(path, dest)
    end

    # Prefix paths with 'prefix' if necessary.
    if self[:prefix]
      @paths = @paths.collect { |p| File.join("/", self[:prefix], p) }
    end

    ::Dir.chdir("#{builddir}/tarbuild") do
      safesystem("ls #{builddir}/tarbuild") if $DEBUG
      tar(tar_path, ".")
    end
  else
    tar(tar_path, paths)
  end

  # TODO(sissel): Make a helper method.
  safesystem(*["gzip", "-f", tar_path])
end