af 0.3.18.7 → 0.3.18.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -478,31 +478,6 @@ module VMC::Cli::Command
478
478
  err "Can't deploy applications from staging directory: [#{Dir.tmpdir}]"
479
479
  end
480
480
 
481
- def check_unreachable_links(path)
482
- files = Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
483
-
484
- pwd = Pathname.pwd
485
-
486
- abspath = File.expand_path(path)
487
- unreachable = []
488
- files.each do |f|
489
- file = Pathname.new(f)
490
- if file.symlink? && !file.realpath.to_s.start_with?(abspath)
491
- unreachable << file.relative_path_from(pwd)
492
- end
493
- end
494
-
495
- unless unreachable.empty?
496
- root = Pathname.new(path).relative_path_from(pwd)
497
- err "Can't deploy application containing links '#{unreachable}' that reach outside its root '#{root}'"
498
- end
499
- end
500
-
501
- def find_sockets(path)
502
- files = Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
503
- files && files.select { |f| File.socket? f }
504
- end
505
-
506
481
  def upload_app_bits(appname, path, infra)
507
482
  display 'Uploading Application:'
508
483
 
@@ -527,25 +502,20 @@ module VMC::Cli::Command
527
502
  elsif zip_file = Dir.glob('*.zip').first
528
503
  VMC::Cli::ZipUtil.unpack(zip_file, explode_dir)
529
504
  else
530
- check_unreachable_links(path)
531
505
  FileUtils.mkdir(explode_dir)
532
506
 
533
- files = Dir.glob('{*,.[^\.]*}')
507
+ afi = VMC::Cli::FileHelper::AppFogIgnore.from_file("#{path}")
534
508
 
535
- # Do not process .git files
536
- files.delete('.git') if files
537
-
538
- files = afignore("#{path}/.afignore",files)
539
-
540
- FileUtils.cp_r(files, explode_dir)
509
+ files = Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
510
+ check_unreachable_links(path,afi.included_files(files))
541
511
 
542
- find_sockets(explode_dir).each do |s|
543
- File.delete s
544
- end
512
+ copy_files( path, ignore_sockets( afi.included_files(files)), explode_dir )
513
+
545
514
  end
546
515
  end
547
516
  end
548
517
 
518
+
549
519
  # Send the resource list to the cloudcontroller, the response will tell us what it already has..
550
520
  unless @options[:noresources]
551
521
  display ' Checking for available resources: ', false
@@ -1,46 +1,125 @@
1
1
  module VMC::Cli
2
2
  module FileHelper
3
3
 
4
-
5
- def match(pattern,filename)
6
- return false if pattern =~ /^\s*$/ # ignore blank lines
4
+ class AppFogIgnore
7
5
 
8
- return false if pattern =~ /^#/ # lines starting with # are comments
6
+ def initialize(patterns,project_root = "")
7
+ @patterns = patterns + [ ".git/" ]
8
+ @project_root = project_root
9
+ end
9
10
 
10
- if pattern =~ /\/$/
11
- # pattern ending in a slash should ignore directory and all its children
12
- dirname = pattern.sub(/\/$/,'')
13
- return filename == dirname || filename =~ /#{dirname}\/.*$/
11
+ def included_files(filenames)
12
+ exclude_dots_only(filenames).reject do |filename|
13
+ exclude = false
14
+ @patterns.each do |pattern|
15
+ if is_negative_pattern?(pattern)
16
+ exclude = false if negative_match(pattern,filename)
17
+ else
18
+ exclude ||= match(pattern,filename)
19
+ end
20
+ end
21
+ exclude
22
+ end
14
23
  end
15
24
 
16
- if pattern =~ /^!/
17
- return !match(pattern.sub(/^!/,''),filename)
25
+ def exclude_dots_only(filenames)
26
+ filenames.reject do |filename|
27
+ base = File.basename(filename)
28
+ base == "." || base == ".."
29
+ end
18
30
  end
31
+
19
32
 
20
- if pattern =~ /^\//
21
- parts = filename.split('/')
22
- return File.fnmatch(pattern.sub(/^\//,''),parts[0])
33
+
34
+ def excluded_files(filenames)
35
+ filenames - included_files(filenames)
36
+ end
37
+
38
+ def self.from_file(project_root)
39
+ f = "#{project_root}/.afignore"
40
+ if File.exists?(f)
41
+ contents = File.read(f).split("\n")
42
+ AppFogIgnore.new(contents,project_root)
43
+ else
44
+ AppFogIgnore.new([],project_root)
45
+ end
23
46
  end
47
+
48
+ def match(pattern,filename)
49
+
50
+ filename = filename.sub(/^#{@project_root}\//,'') # remove any project directory prefix
51
+
52
+ return false if pattern =~ /^\s*$/ # ignore blank lines
53
+
54
+ return false if pattern =~ /^#/ # lines starting with # are comments
55
+
56
+ return false if pattern =~ /^!/ # lines starting with ! are negated
24
57
 
25
- if pattern.include? '/'
26
- return File.fnmatch(pattern,filename)
58
+ if pattern =~ /\/$/
59
+ # pattern ending in a slash should ignore directory and all its children
60
+ dirname = pattern.sub(/\/$/,'')
61
+ return filename == dirname || filename =~ /#{dirname}\/.*$/
62
+ end
63
+
64
+ if pattern =~ /^\//
65
+ parts = filename.split('/')
66
+ return File.fnmatch(pattern.sub(/^\//,''),parts[0])
67
+ end
68
+
69
+ if pattern.include? '/'
70
+ return File.fnmatch(pattern,filename)
71
+ end
72
+
73
+ File.fnmatch(pattern,filename,File::FNM_PATHNAME)
74
+ end
75
+
76
+ def is_negative_pattern?(pattern)
77
+ pattern =~ /^!/
78
+ end
79
+
80
+ def negative_match(pattern,filename)
81
+ return false unless pattern =~ /^!/
82
+ match(pattern.sub(/^!/,''),filename)
27
83
  end
28
84
 
29
- File.fnmatch(pattern,filename,File::FNM_PATHNAME)
30
85
  end
31
86
 
32
- def reject_patterns(patterns,filenames)
33
- filenames.reject do |filename|
34
- patterns.detect { |pattern| match(pattern,filename)} != nil
87
+ def ignore_sockets(files)
88
+ files.reject { |f| File.socket? f }
89
+ end
90
+
91
+ def check_unreachable_links(path,files)
92
+ pwd = Pathname.new(path)
93
+ abspath = pwd.realpath.to_s
94
+ unreachable = []
95
+ files.each do |f|
96
+ file = Pathname.new(f)
97
+ if file.symlink? && !file.realpath.to_s.start_with?(abspath)
98
+ unreachable << file.relative_path_from(pwd).to_s
99
+ end
100
+ end
101
+
102
+ unless unreachable.empty?
103
+ root = pwd.relative_path_from(pwd).to_s
104
+ err "Can't deploy application containing links '#{unreachable.join(",")}' that reach outside its root '#{root}'"
35
105
  end
36
106
  end
37
107
 
38
- def afignore(ignore_path,files)
39
- if File.exists?(ignore_path)
40
- patterns = File.read(ignore_path).split("\n")
41
- reject_patterns(patterns,files)
42
- else
43
- files
108
+ def copy_files(project_root,files,dest_dir)
109
+ project_root = Pathname.new(project_root)
110
+ files.reject { |f| File.symlink?(f) }.each do |f|
111
+ dest = Pathname.new(f).relative_path_from(project_root)
112
+ if File.directory?(f)
113
+ FileUtils.mkdir_p("#{dest_dir}/#{dest}")
114
+ else
115
+ FileUtils.cp(f,"#{dest_dir}/#{dest}")
116
+ end
117
+ end
118
+ root = Pathname.new(project_root).realpath
119
+ files.select { |f| File.symlink?(f) }.each do |f|
120
+ dest = Pathname.new(f).relative_path_from(project_root)
121
+ p = Pathname.new(f).realpath
122
+ FileUtils.ln_s(p.relative_path_from(root),"#{dest_dir}/#{dest}")
44
123
  end
45
124
  end
46
125
 
@@ -2,6 +2,6 @@ module VMC
2
2
  module Cli
3
3
  # This version number is used as the RubyGem release version.
4
4
  # The internal VMC version number is VMC::VERSION.
5
- VERSION = '0.3.18.7'
5
+ VERSION = '0.3.18.8'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: af
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.18.7
4
+ version: 0.3.18.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_pure