backup_client 0.1.1 → 0.1.3

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: 7f0b6151dbd77af62a934cdd9eb2b1a88ef4960c9449221642736be215b56f68
4
- data.tar.gz: 03c7fec17e8153665a58626d645972833df4f7e224c013b0d2dc90f12df302b0
3
+ metadata.gz: 9751b1230fda523c9219bac0be687234d1c2a1a8130e365730a89292839b925c
4
+ data.tar.gz: e4a0397dcff58ecfa17a49c69439df02817bd9807b0c0ef998510e0f9ba57dc2
5
5
  SHA512:
6
- metadata.gz: aa3b3a2b512b9e6fdac8faba1d59d59a33cafba5b144d1c0eab13722abd491383f1e0cce666f61df34c088e774b73d02a581030a75da3dc30396692a51933a08
7
- data.tar.gz: a1776157690e81e9dfaacf5a624e5b699db6441b93ff359160cab3cd2c4bf50892aa3837ede343b3eb274d30239b9cc4873ff7066f59e0a97cb82eac79ed74e2
6
+ metadata.gz: 74213ec236a3bef9a34a5c8cd8cfc0f469acbe60c1acc2ce9dd1f756ea09d23bc6196ac2c144e73b6af1842c6679d320f179fa5339aeacb57ef841a56a80af40
7
+ data.tar.gz: a96dd3ba2d6e8a8c99ece3cf459586f739f99674ed5d1f77a9b831cc9280f6aa3d0838150d243d3726e3cd61e45b442edfc30589af440efb9a044145c58fe19c
@@ -8,24 +8,25 @@ module BackupClient
8
8
  include ::BackupClient::Helpers::LogHelper
9
9
  include ::BackupClient::Helpers::FtpHelper
10
10
 
11
- def initialize(ftp_client, file, destination_folder)
12
- @ftp_client = ftp_client
13
- @file = file
14
- @destination_folder = destination_folder
11
+ def initialize(ftp_client, local_file_path, remote_folder_path)
12
+ @ftp_client = ftp_client
13
+ @local_file_path = local_file_path
14
+ @remote_folder_path = remote_folder_path
15
15
  end
16
16
 
17
17
  def call
18
- File.open(file, "rb") do |file_handle|
19
- remote_file_path = destination_folder + "/" + File.basename(file)
20
- remote_file_path = remote_file_path.gsub(%r{//+}, "/")
21
- ftp_client.putbinaryfile(file_handle, remote_file_path)
22
- log("Uploaded file #{file} → #{remote_file_path}")
18
+ remote_file_path = [remote_folder_path, local_file_path].join("/").gsub("//", "/")
19
+
20
+ File.open(local_file_path, "rb") do |file|
21
+ ftp_client.putbinaryfile(file, remote_file_path)
23
22
  end
23
+
24
+ log "Uploaded file #{local_file_path} → #{remote_file_path}"
24
25
  end
25
26
 
26
27
  private
27
28
 
28
- attr_reader :ftp_client, :file, :destination_folder
29
+ attr_reader :ftp_client, :local_file_path, :remote_folder_path
29
30
  end
30
31
  end
31
32
  end
@@ -31,16 +31,26 @@ module BackupClient
31
31
 
32
32
  def ftp_processing
33
33
  source_paths.each do |path|
34
- if File.file?(path)
35
- upload_file_ftp(path, destination_path)
36
- elsif File.directory?(path)
37
- upload_dir_ftp(path, destination_path)
34
+ folder = to_unix_path(path)
35
+
36
+ if File.file?(folder)
37
+ upload_file_ftp(folder, destination_path)
38
+ elsif File.directory?(folder)
39
+ upload_dir_ftp(folder, destination_path)
38
40
  else
39
- log "Invalid path: #{path}"
41
+ log "Invalid path: #{folder}"
40
42
  end
41
43
  end
42
44
  end
43
45
 
46
+ def to_unix_path(path)
47
+ if Regexp.new('^[A-Za-z]:\\\\') =~ path
48
+ path.sub(/^[A-Za-z]:\\/, '/').gsub('\\', '/')
49
+ else
50
+ path
51
+ end
52
+ end
53
+
44
54
  def ftp_client
45
55
  @ftp_client ||=
46
56
  begin
@@ -18,15 +18,15 @@ module BackupClient
18
18
  def call
19
19
  log("Processing task #{task["name"]}")
20
20
 
21
- task["providers"].each do |provider_name|
22
- provider = fetch_provider(provider_name)
21
+ task["providers"].each do |task_provider|
22
+ provider = fetch_provider(task_provider)
23
23
  next if provider.nil?
24
24
 
25
- log("Processing provider #{provider_name}")
25
+ log("Processing provider #{task_provider['name']}#{task_provider['type']}")
26
26
 
27
27
  processing_task_for_provider(provider)
28
- rescue StandardError => e
29
- log("Unexpected error: #{e}, #{provider["type"].upcase}: #{provider["name"].upcase}")
28
+ # rescue StandardError => e
29
+ # log(" Unexpected error: #{e}, #{provider["type"].upcase}: #{provider["name"].upcase}")
30
30
  end
31
31
  end
32
32
 
@@ -47,7 +47,7 @@ module BackupClient
47
47
 
48
48
  def upload_to_ftp(provider, source_paths, use_timestamp)
49
49
  ::BackupClient::Components::Ftp::Commands::Upload
50
- .new(source_paths, provider, timestamp: Time.now).call
50
+ .new(provider, source_paths, use_timestamp: use_timestamp, timestamp: Time.now).call
51
51
  end
52
52
 
53
53
  def copy_to_local(provider, local_paths, use_timestamp)
@@ -68,8 +68,10 @@ module BackupClient
68
68
  end
69
69
  end
70
70
 
71
- def fetch_provider(provider_name)
72
- providers[provider_name]
71
+ def fetch_provider(task_provider)
72
+ providers.find do |provider|
73
+ task_provider['name'] == provider['name'] && task_provider['type'] == provider['type']
74
+ end
73
75
  end
74
76
  end
75
77
  end
data/lib/backup_client.rb CHANGED
@@ -17,7 +17,7 @@ Dir.glob("components/**/*.rb").sort.each do |file|
17
17
  end
18
18
 
19
19
  module BackupClient
20
- VERSION = "0.1.1"
20
+ VERSION = "0.1.3"
21
21
 
22
22
  class Processor
23
23
  include ::BackupClient::Helpers::LogHelper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex
@@ -66,7 +66,6 @@ files:
66
66
  - LICENSE.txt
67
67
  - README.md
68
68
  - Rakefile
69
- - backup_client-0.1.0.gem
70
69
  - lib/backup_client.rb
71
70
  - lib/backup_client/components/ftp/commands/create_folder.rb
72
71
  - lib/backup_client/components/ftp/commands/file_upload.rb
Binary file