bdsync 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bef8cde7cd361296d1aedf0e364c43f4457d4a6b1cf6ef5c82703861b9569cb
4
- data.tar.gz: 3c8d7931ad7a790a93ea75d936f510eaa33229248367fa980b318a2452cb06e1
3
+ metadata.gz: 1aeb789488a7670229fa4a2934989b606fa2ef25434ff47e43f3ac3e427dfd8a
4
+ data.tar.gz: e9ddef916d834bb0bd04b2bb390eba73563ba9e54780100bddf060a04b610650
5
5
  SHA512:
6
- metadata.gz: 3400a2f2ef46c789d8cd4d4354fa64e28ee38b9d00a941c6c837645605d284b8f5e31e5b02cc5709ce42bfa67d6c134c964d9a6af5cabbecc975e915405e320c
7
- data.tar.gz: 19e5a4affe4aad906f3722809fedb1a23dd71dc4e0d1c8fa2b8935d28976cb1cdd478e85b0c72fb90877a283953a830795ae2c40a8a74bbdf5fefc5e31c41f7b
6
+ metadata.gz: fc8b863ee0ad9ef4ba5f5a6e84e1fe5ee4d9aaf807448a25c7cad0d74450a201fdeb10676a325810b6550b1dfd4b8cd95e925a6f982ba75b2fad1e1d8eada2a0
7
+ data.tar.gz: 141a974e6ad5187e5509f769a7f5bd2b644b0bb908748cde83cb3e492a83bafab02d1d8ea746ff9d2692f9ebbbb8be1d84f5c197f37ed7fa77ac4e3abaec568d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bdsync (2.1.2)
4
+ bdsync (2.2.0)
5
5
  colorize (~> 0.8)
6
6
  net-sftp (~> 2.1)
7
7
 
@@ -173,8 +173,12 @@ module Bdsync
173
173
  download_file local_path, remote_path
174
174
  update_file_data relative_path, local_path, remote.mtime
175
175
  else
176
- handle_local_conflict local_path
177
- download_file local_path, remote_path
176
+ # compare file contents, conflict if not equal
177
+ if !is_same_contents local_path, remote_path
178
+ handle_local_conflict local_path
179
+ download_file local_path, remote_path
180
+ end
181
+
178
182
  update_file_data relative_path, local_path, remote.mtime
179
183
  end
180
184
  when :directory
@@ -202,8 +206,12 @@ module Bdsync
202
206
  remote = upload_file local_path, remote_path
203
207
  update_file_data relative_path, local_path, remote.mtime
204
208
  else
205
- handle_remote_conflict remote_path
206
- remote = upload_file local_path, remote_path
209
+ # compare file contents, conflict if not equal
210
+ if !is_same_contents local_path, remote_path
211
+ handle_remote_conflict remote_path
212
+ remote = upload_file local_path, remote_path
213
+ end
214
+
207
215
  update_file_data relative_path, local_path, remote.mtime
208
216
  end
209
217
  when :directory
@@ -260,12 +268,20 @@ module Bdsync
260
268
  update_file_data relative_path, local_path, remote.mtime
261
269
  else
262
270
  if File.mtime(local_path).to_i > remote.mtime
263
- handle_remote_conflict remote_path
264
- remote = upload_file local_path, remote_path
271
+ # compare file contents, conflict if not equal
272
+ if !is_same_contents local_path, remote_path
273
+ handle_remote_conflict remote_path
274
+ remote = upload_file local_path, remote_path
275
+ end
276
+
265
277
  update_file_data relative_path, local_path, remote.mtime
266
278
  else
267
- handle_local_conflict local_path
268
- download_file local_path, remote_path
279
+ # compare file contents, conflict if not equal
280
+ if !is_same_contents local_path, remote_path
281
+ handle_local_conflict local_path
282
+ download_file local_path, remote_path
283
+ end
284
+
269
285
  update_file_data relative_path, local_path, remote.mtime
270
286
  end
271
287
  end
@@ -339,12 +355,20 @@ module Bdsync
339
355
  update_file_data relative_path, local_path, remote.mtime
340
356
  else
341
357
  if File.mtime(local_path).to_i > remote.mtime
342
- handle_remote_conflict remote_path
343
- remote = upload_file local_path, remote_path
358
+ # compare file contents, conflict if not equal
359
+ if !is_same_contents local_path, remote_path
360
+ handle_remote_conflict remote_path
361
+ remote = upload_file local_path, remote_path
362
+ end
363
+
344
364
  update_file_data relative_path, local_path, remote.mtime
345
365
  else
346
- handle_local_conflict local_path
347
- download_file local_path, remote_path
366
+ # compare file contents, conflict if not equal
367
+ if !is_same_contents local_path, remote_path
368
+ handle_local_conflict local_path
369
+ download_file local_path, remote_path
370
+ end
371
+
348
372
  update_file_data relative_path, local_path, remote.mtime
349
373
  end
350
374
  end
@@ -437,5 +461,11 @@ module Bdsync
437
461
  def local_ensure_parent path
438
462
  local_ensure_dir File.dirname path
439
463
  end
464
+
465
+ def is_same_contents local_path, remote_path
466
+ local_file_md5 = Utils.file_md5 local_path
467
+ remote_file_md5 = get_remote_file_md5 remote_path
468
+ local_file_md5 == remote_file_md5
469
+ end
440
470
  end
441
471
  end
@@ -89,5 +89,9 @@ module Bdsync
89
89
  def remote_ensure_parent path
90
90
  local_ensure_parent path
91
91
  end
92
+
93
+ def get_remote_file_md5 path
94
+ Utils.file_md5 path
95
+ end
92
96
  end
93
97
  end
@@ -82,5 +82,11 @@ module Bdsync
82
82
  def remote_ensure_parent path
83
83
  remote_ensure_dir File.dirname path
84
84
  end
85
+
86
+ def get_remote_file_md5 remote_path
87
+ puts "#{Utils.caller_info 1} sftp.session.exec! md5sum #{remote_path}".white
88
+ res = @sftp.session.exec! "md5sum #{remote_path}"
89
+ res.split[0]
90
+ end
85
91
  end
86
92
  end
@@ -22,6 +22,10 @@ module Bdsync
22
22
  Digest::MD5.hexdigest(s)
23
23
  end
24
24
 
25
+ def self.file_md5 file_path
26
+ Digest::MD5.file(file_path).hexdigest
27
+ end
28
+
25
29
  def self.caller_info level
26
30
  info = caller[level].match(%r{([^/]+):(\d+):in `(.+)'})
27
31
  "#{info.captures[0]}:#{info.captures[1]} - #{info.captures[2]}"
@@ -1,3 +1,3 @@
1
1
  module Bdsync
2
- VERSION = "2.1.2"
2
+ VERSION = "2.2.0"
3
3
  end
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.1.2
4
+ version: 2.2.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: 2019-12-30 00:00:00.000000000 Z
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize