Module: CFoundry::UploadHelpers

Defined in:
lib/appfog-vmc-plugin/cfoundry/upload_helpers.rb

Instance Method Summary collapse

Instance Method Details

#prepare_package(path, to) ⇒ Object



4
5
6
7
8
9
10
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
# File 'lib/appfog-vmc-plugin/cfoundry/upload_helpers.rb', line 4

def prepare_package(path, to)
  if path =~ /\.(jar|war|zip)$/
    CFoundry::Zip.unpack(path, to)
  elsif war_file = Dir.glob("#{path}/*.war").first
    CFoundry::Zip.unpack(war_file, to)
  else
    #check_unreachable_links(path)

    FileUtils.mkdir(to)

    files = Dir.glob("#{path}/{*,.[^\.]*}")

    exclude = UPLOAD_EXCLUDE
    if File.exists?("#{path}/.vmcignore")
      exclude += File.read("#{path}/.vmcignore").split(/\n+/)
    end

    # adds additional .afignore
    if File.exists?("#{path}/.afignore")
      exclude += File.read("#{path}/.afignore").split(/\n+/)
    end

    # prevent initial copying if we can, remove sub-files later
    files.reject! do |f|
      exclude.any? do |e|
        File.fnmatch(f.sub(path + "/", ""), e)
      end
    end

    FileUtils.cp_r(files, to)

    find_sockets(to).each do |s|
      File.delete s
    end

    # remove ignored globs more thoroughly
    #
    # note that the above file list only includes toplevel
    # files/directories for cp_r, so this is where sub-files/etc. are
    # removed
    exclude.each do |e|
      Dir.glob("#{to}/#{e}").each do |f|
        FileUtils.rm_rf(f)
      end
    end
  end
end

#prune_empty_directories(path) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/appfog-vmc-plugin/cfoundry/upload_helpers.rb', line 52

def prune_empty_directories(path)
  all_files = Dir["#{path}/**/{*,.*}"]
  all_files.reject! { |fn| fn =~ /\/\.+$/ }

  directories = all_files.select { |x| File.directory?(x) }
  directories.sort! { |a, b| b.size <=> a.size }

  directories.each do |directory|
    entries = Dir.entries(directory) - %w{. ..}
    if entries.empty?
      # Better handling of symlinks
      if !File.symlink?(directory)
        FileUtils.rmdir(directory)
      else
        File.unlink(directory)
      end
    end
  end
end