bdsync 2.2.0 → 2.3.0
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/Gemfile.lock +1 -1
- data/lib/bdsync/core.rb +9 -15
- data/lib/bdsync/lfs.rb +5 -4
- data/lib/bdsync/sftp.rb +41 -9
- data/lib/bdsync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fa64e8243c110577ac96c4266d21f3d7f2f1a2035644d83e52fc6e61db86ac3
|
4
|
+
data.tar.gz: bbd68644aa5817c438992b5e70ba0ab5622e3f8dc2cfa5c0ef3e9a0572d030fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db7bc9a4be128150de8920f014c12cbc3533fdafb1d978945b058e0c9816edc04bf0eabcbaa7f85d412275fcf4958ffc333f22a939955eb792c3514e7c9dbe7c
|
7
|
+
data.tar.gz: f4550efd06ec82dc092345711e5310bf3b03f8c9271df6c31c43b6c060fc13f0f3608ab32f34c9ab63dcc29e6250959dedfe6afd105f0a98fda1b529f97cffa6
|
data/Gemfile.lock
CHANGED
data/lib/bdsync/core.rb
CHANGED
@@ -28,20 +28,18 @@ module Bdsync
|
|
28
28
|
@old_data = load_data
|
29
29
|
@data = {}
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
local_ensure_dir @local_root_path
|
31
|
+
remote_ensure_dir @remote_root_path
|
32
|
+
local_ensure_dir @local_root_path
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
puts "\n==== traverse_remote_path ===="
|
35
|
+
traverse_remote_path @remote_root_path
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
# merge @data to @old_data, and clear @data
|
38
|
+
@old_data.merge! @data
|
39
|
+
@data = {}
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
}
|
41
|
+
puts "\n==== traverse_local_path ===="
|
42
|
+
traverse_local_path @local_root_path
|
45
43
|
|
46
44
|
save_data @data
|
47
45
|
|
@@ -52,10 +50,6 @@ module Bdsync
|
|
52
50
|
}
|
53
51
|
end
|
54
52
|
|
55
|
-
def start_session &block
|
56
|
-
fail NotImplementedError, "A subclass class must be able to #{__method__}!"
|
57
|
-
end
|
58
|
-
|
59
53
|
def load_data
|
60
54
|
puts "\nload #{@data_path}"
|
61
55
|
YAML.load_file @data_path
|
data/lib/bdsync/lfs.rb
CHANGED
@@ -11,10 +11,6 @@ module Bdsync
|
|
11
11
|
Core.options
|
12
12
|
end
|
13
13
|
|
14
|
-
def start_session &block
|
15
|
-
yield
|
16
|
-
end
|
17
|
-
|
18
14
|
# yield object like this
|
19
15
|
# {
|
20
16
|
# name:
|
@@ -93,5 +89,10 @@ module Bdsync
|
|
93
89
|
def get_remote_file_md5 path
|
94
90
|
Utils.file_md5 path
|
95
91
|
end
|
92
|
+
|
93
|
+
# for test
|
94
|
+
def create_remote_file remote_path, content
|
95
|
+
File.write remote_path, content
|
96
|
+
end
|
96
97
|
end
|
97
98
|
end
|
data/lib/bdsync/sftp.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "bdsync/core"
|
2
2
|
require "net/sftp"
|
3
|
+
require "tempfile"
|
3
4
|
|
4
5
|
module Bdsync
|
5
6
|
class Sftp < Core
|
6
7
|
def initialize params
|
7
8
|
@site = params["site"]
|
8
9
|
@user = params["user"]
|
10
|
+
@sftp = Net::SFTP.start(@site, @user)
|
9
11
|
|
10
12
|
super params, "sftp"
|
11
13
|
end
|
@@ -14,19 +16,17 @@ module Bdsync
|
|
14
16
|
Core.options + ["site:", "user:"]
|
15
17
|
end
|
16
18
|
|
17
|
-
def start_session &block
|
18
|
-
Net::SFTP.start(@site, @user) { |sftp|
|
19
|
-
@sftp = sftp
|
20
|
-
yield
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
19
|
def remote_dir_foreach remote_path
|
25
20
|
@sftp.dir.foreach(remote_path) { |entry|
|
26
21
|
yield entry
|
27
22
|
}
|
28
23
|
end
|
29
24
|
|
25
|
+
# Return
|
26
|
+
# OpenStruct.new(
|
27
|
+
# directory?:
|
28
|
+
# mtime:
|
29
|
+
# )
|
30
30
|
def remote_get_object remote_path
|
31
31
|
@sftp.lstat! remote_path
|
32
32
|
rescue Net::SFTP::StatusException
|
@@ -61,8 +61,25 @@ module Bdsync
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def remote_remove_dir remote_path
|
64
|
-
puts "#{Utils.caller_info 1}
|
65
|
-
|
64
|
+
puts "#{Utils.caller_info 1} remote_remove_dir #{remote_path}".white
|
65
|
+
|
66
|
+
remote = remote_get_object remote_path
|
67
|
+
return if !remote || !remote.directory?
|
68
|
+
|
69
|
+
remote_dir_foreach(remote_path) { |entry|
|
70
|
+
next if [".", ".."].include? entry.name
|
71
|
+
|
72
|
+
path = "#{remote_path}/#{entry.name}"
|
73
|
+
remote = entry.attributes
|
74
|
+
|
75
|
+
if remote.directory?
|
76
|
+
remote_remove_dir path
|
77
|
+
else
|
78
|
+
remote_remove_file path
|
79
|
+
end
|
80
|
+
}
|
81
|
+
|
82
|
+
@sftp.rmdir! remote_path
|
66
83
|
end
|
67
84
|
|
68
85
|
def remote_rename remote_path, new_remote_path
|
@@ -88,5 +105,20 @@ module Bdsync
|
|
88
105
|
res = @sftp.session.exec! "md5sum #{remote_path}"
|
89
106
|
res.split[0]
|
90
107
|
end
|
108
|
+
|
109
|
+
# for test
|
110
|
+
def create_remote_file remote_path, content
|
111
|
+
tmpfile = Tempfile.new 'sftp.rb-create_remote_file-'
|
112
|
+
|
113
|
+
begin
|
114
|
+
tmpfile.write content
|
115
|
+
tmpfile.flush
|
116
|
+
|
117
|
+
@sftp.upload! tmpfile.path, remote_path
|
118
|
+
ensure
|
119
|
+
tmpfile.close
|
120
|
+
tmpfile.unlink # deletes the temp file
|
121
|
+
end
|
122
|
+
end
|
91
123
|
end
|
92
124
|
end
|
data/lib/bdsync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bdsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xia Xiongjun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|