vagrant-scp-sync 0.5.14 → 0.5.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11e117ab4ab00e45911fd5b03030c4d533109adb73eac10cf0de89e813ba6485
4
- data.tar.gz: 29f64a74a37a7fe640b22d8b16a481aa08b67a57322e5f6822d9b6e52eac4790
3
+ metadata.gz: 8c3921e597aab855812426f77e3a91e807643551972b963e04992e04b43172c4
4
+ data.tar.gz: 1d3fd272ed5e7f3e5b111766a699a62e12ac593e61efcba981a4a4ad98779922
5
5
  SHA512:
6
- metadata.gz: 2c1f8ad98eed1f467d3d263e918527d5f326a11561be2ed0224a866aae72eb258b4fa90e91ab1831055672ac5030448860fb11913db8b18558988f68697b64d5
7
- data.tar.gz: 19080ca8a5a4f742f41882cd4fbee4d58e67dcfae5320c2a35a527e7e883f6c8ebbda2421a5d6a85732e7c10c5f8d22ae3c7e316c8a6f41712ca442720426436
6
+ metadata.gz: f1cab41bd06b2c0f9469a85b2d3926625c6bf15dd5a7ef7ba105ead7aa1e07e00545138d01af8b91683cbf78d7f13c33097de8f1df14f2fb541fc177fb75fb39
7
+ data.tar.gz: 5caa59840811a8bdeeabd325c9bb54b231e99568efde4c9cf39ae20f8d54136dcaf6383328cb83b14654129a9a31b43a506e084ec481544cbae92d8c86aa4a1e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.15](https://github.com/STARTcloud/vagrant-scp-sync/compare/v0.5.14...v0.5.15) (2024-12-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * single file sync - lint ([3f77284](https://github.com/STARTcloud/vagrant-scp-sync/commit/3f772846fee7d2a42b7ffa6cfcc4bf4547e09466))
9
+ * single file sync - lint ([029372f](https://github.com/STARTcloud/vagrant-scp-sync/commit/029372fbb906281ee70d0bcae800f71b73f88f73))
10
+
3
11
  ## [0.5.14](https://github.com/STARTcloud/vagrant-scp-sync/compare/v0.5.13...v0.5.14) (2024-12-23)
4
12
 
5
13
 
@@ -22,26 +22,62 @@ module VagrantPlugins
22
22
 
23
23
  delete = scp_opts.include?('--delete')
24
24
 
25
+ # Handle source and target path behaviors
26
+ has_trailing_slash_source = opts[:map].end_with?('/')
27
+ has_trailing_slash_target = opts[:to].end_with?('/')
28
+ is_source_directory = File.directory?(source_files)
29
+
25
30
  if opts[:direction] == :upload || opts[:direction].nil?
26
- source = source_files
27
- target = "#{ssh_info[:username]}@#{ssh_info[:host]}:#{target_files}"
28
- target_dir = File.dirname(target_files)
29
- make_dir = build_ssh_command(ssh_opts, "sudo mkdir -p #{target_dir}", ssh_info)
30
- change_ownership = build_ssh_command(ssh_opts, "sudo chown -R #{opts[:owner]}:#{opts[:group]} #{target_dir}", ssh_info)
31
- change_permissions = build_ssh_command(ssh_opts, "sudo chmod 777 #{target_dir}", ssh_info)
32
- remove_dir = build_ssh_command(ssh_opts, "sudo rm -rf #{target_files}", ssh_info)
31
+ # For upload direction
32
+ target_check = build_ssh_command(ssh_opts, "test -e #{target_files} && echo 'EXISTS' || echo 'NOT_EXISTS'", ssh_info)
33
+ target_type_check = build_ssh_command(ssh_opts, "test -d #{target_files} && echo 'DIR' || echo 'FILE'", ssh_info)
34
+
35
+ # Check if target exists and its type
36
+ target_exists = execute_command_with_output(machine, target_check).strip == 'EXISTS'
37
+ target_is_dir = target_exists && execute_command_with_output(machine, target_type_check).strip == 'DIR'
38
+
39
+ # Determine source path based on trailing slash and directory status
40
+ source = if is_source_directory && has_trailing_slash_source
41
+ "#{source_files}/*" # Copy contents of directory
42
+ else
43
+ source_files # Copy directory itself or single file
44
+ end
45
+
46
+ # Determine target path based on existence and trailing slash
47
+ target_base = "#{ssh_info[:username]}@#{ssh_info[:host]}:#{target_files}"
48
+ target = if target_exists && target_is_dir && !has_trailing_slash_target
49
+ # If target exists as directory but no trailing slash, put source inside it
50
+ "#{target_base}/#{File.basename(source_files)}"
51
+ else
52
+ target_base
53
+ end
54
+
55
+ # Prepare target directory
56
+ parent_dir = File.dirname(target_files)
57
+ make_dir = build_ssh_command(ssh_opts, "sudo mkdir -p #{parent_dir}", ssh_info)
58
+ change_ownership = build_ssh_command(ssh_opts, "sudo chown -R #{opts[:owner]}:#{opts[:group]} #{parent_dir}", ssh_info)
59
+ change_permissions = build_ssh_command(ssh_opts, "sudo chmod 777 #{parent_dir}", ssh_info)
60
+ remove_dir = build_ssh_command(ssh_opts, "sudo rm -rf #{target_files}", ssh_info) if delete
61
+
33
62
  elsif opts[:direction] == :download
63
+ # For download direction
34
64
  source = "#{ssh_info[:username]}@#{ssh_info[:host]}:#{source_files}"
65
+ source = "#{source}/*" if has_trailing_slash_source
66
+
67
+ # Create target directory if needed
35
68
  target = target_files
36
- target_dir = File.dirname(target_files)
37
- make_dir = target_dir == '.' ? nil : "mkdir -p #{target_dir}"
69
+ parent_dir = File.dirname(target)
70
+ make_dir = "mkdir -p #{parent_dir}"
38
71
  end
39
72
 
40
- synchronize = build_scp_command(scp_path, ssh_opts, source, target)
41
- execute_command(machine, remove_dir, delete, nil, opts)
73
+ # Execute commands
74
+ execute_command(machine, remove_dir, delete, nil, opts) if delete
42
75
  execute_command(machine, make_dir, false, nil, opts)
43
- execute_command(machine, change_ownership, false, nil, opts)
44
- execute_command(machine, change_permissions, false, nil, opts)
76
+ execute_command(machine, change_ownership, false, nil, opts) if opts[:direction] == :upload
77
+ execute_command(machine, change_permissions, false, nil, opts) if opts[:direction] == :upload
78
+
79
+ # Build and execute the scp command
80
+ synchronize = build_scp_command(scp_path, ssh_opts, source, target)
45
81
  execute_command(machine, synchronize, true, 'scp_sync_folder', opts)
46
82
  end
47
83
 
@@ -92,13 +128,22 @@ module VagrantPlugins
92
128
  raise_scp_error(message_key, command, result.stderr) if raise_error && !result.exit_code.zero?
93
129
  end
94
130
 
131
+ def self.execute_command_with_output(_machine, command)
132
+ return '' if command.nil?
133
+
134
+ result = Vagrant::Util::Subprocess.execute('sh', '-c', command)
135
+ result.stdout
136
+ end
137
+
95
138
  def self.raise_scp_error(message_key, command, stderr)
96
139
  raise Errors.const_get("SyncedFolderScpSync#{message_key.split('_').map(&:capitalize).join}Error"),
97
140
  command: command,
98
141
  stderr: stderr
99
142
  end
100
143
 
101
- private_class_method :expand_path, :build_ssh_options, :build_scp_options, :build_ssh_command, :build_scp_command, :execute_command, :raise_scp_error
144
+ private_class_method :expand_path, :build_ssh_options, :build_scp_options,
145
+ :build_ssh_command, :build_scp_command, :execute_command,
146
+ :execute_command_with_output, :raise_scp_error
102
147
  end
103
148
  end
104
149
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Vagrant
4
4
  module ScpSync
5
- VERSION = '0.5.14'
5
+ VERSION = '0.5.15'
6
6
  NAME = 'vagrant-scp-sync'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-scp-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Gilbert