vagrant-google 1.0.0 → 2.0.0.rc0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,106 +0,0 @@
1
- # Copyright 2013 Google Inc. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require "log4r"
15
- require "vagrant/util/subprocess"
16
- require "vagrant/util/scoped_hash_override"
17
- require "vagrant/util/which"
18
-
19
- module VagrantPlugins
20
- module Google
21
- module Action
22
- # This middleware uses `rsync` to sync the folders over to the
23
- # Google instance.
24
- class SyncFolders
25
- include Vagrant::Util::ScopedHashOverride
26
-
27
- def initialize(app, env)
28
- @app = app
29
- @logger = Log4r::Logger.new("vagrant_google::action::sync_folders")
30
- end
31
-
32
- def call(env) # rubocop:disable Metrics/MethodLength
33
- @app.call(env)
34
-
35
- ssh_info = env[:machine].ssh_info
36
-
37
- env[:machine].config.vm.synced_folders.each do |id, data|
38
- data = scoped_hash_override(data, :google)
39
-
40
- # Ignore disabled shared folders
41
- next if data[:disabled]
42
-
43
- unless Vagrant::Util::Which.which('rsync')
44
- env[:ui].warn(I18n.t('vagrant_google.rsync_not_found_warning'))
45
- break
46
- end
47
-
48
- hostpath = File.expand_path(data[:hostpath], env[:root_path])
49
- guestpath = data[:guestpath]
50
-
51
- # Make sure there is a trailing slash on the host path to
52
- # avoid creating an additional directory with rsync
53
- hostpath = "#{hostpath}/" if hostpath !~ /\/$/
54
-
55
- # on windows rsync.exe requires cygdrive-style paths
56
- if Vagrant::Util::Platform.windows?
57
- hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
58
- end
59
-
60
- env[:ui].info(I18n.t("vagrant_google.rsync_folder",
61
- :hostpath => hostpath,
62
- :guestpath => guestpath))
63
-
64
- # Create the guest path
65
- env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
66
- env[:machine].communicate.sudo(
67
- "chown #{ssh_info[:username]} '#{guestpath}'"
68
- )
69
-
70
- # patch from https://github.com/tmatilai/vagrant-aws/commit/4a043a96076c332220ec4ec19470c4af5597dd51
71
- def ssh_key_options(ssh_info)
72
- # Ensure that `private_key_path` is an Array (for Vagrant < 1.4)
73
- Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
74
- end
75
-
76
- #collect rsync excludes specified :rsync__excludes=>['path1',...] in synced_folder options
77
- excludes = ['.vagrant/', *Array(data[:rsync__excludes])]
78
-
79
- # Rsync over to the guest path using the SSH info
80
- command = [
81
- "rsync", "--verbose", "--archive", "-z",
82
- *excludes.map{|e| ['--exclude', e]}.flatten,
83
- "-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}",
84
- hostpath,
85
- "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"
86
- ]
87
-
88
- # we need to fix permissions when using rsync.exe on windows, see
89
- # http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
90
- if Vagrant::Util::Platform.windows?
91
- command.insert(1, "--chmod", "ugo=rwX")
92
- end
93
-
94
- r = Vagrant::Util::Subprocess.execute(*command)
95
- if r.exit_code.nonzero?
96
- raise Errors::RsyncError,
97
- :guestpath => guestpath,
98
- :hostpath => hostpath,
99
- :stderr => r.stderr
100
- end
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end