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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/vagrant-scp-sync/action/scp_sync.rb +59 -14
- data/lib/vagrant-scp-sync/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3921e597aab855812426f77e3a91e807643551972b963e04992e04b43172c4
|
4
|
+
data.tar.gz: 1d3fd272ed5e7f3e5b111766a699a62e12ac593e61efcba981a4a4ad98779922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
37
|
-
make_dir =
|
69
|
+
parent_dir = File.dirname(target)
|
70
|
+
make_dir = "mkdir -p #{parent_dir}"
|
38
71
|
end
|
39
72
|
|
40
|
-
|
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,
|
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
|