directory-digest 1.0.5 → 1.0.6
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/lib/directory-digest/digest.rb +23 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 122099030f505761a308d07fdef2bbe5e79d8299
|
4
|
+
data.tar.gz: 16bb9961a3851fb1dfaf31ba194ae7bcdeadb629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2c22e61c9ffc3d17842321460095b8c2ecab18c8f777f2bcecb7dc6ef99061dcc4000e3292cab0514aebeb6312fb6f09b3d29f744b5327d9850db0fa9f28211
|
7
|
+
data.tar.gz: de1739a9d67f4967c7b7bdd0f4cabecf383cbb3c86e1c6b3bbb84bbf72a1a35c116275e74e967549a2aa8dc917b1bd4be4d9426fe95f81a02e4d5f9df6b40075
|
@@ -57,8 +57,7 @@ module DirectoryDigest
|
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
60
|
-
def mirror_from(other,
|
61
|
-
log.call("synchronizing #{other.directory} to #{directory}")
|
60
|
+
def mirror_from(other, actions = MirrorActions.new)
|
62
61
|
files_copied = 0
|
63
62
|
files_deleted = 0
|
64
63
|
changes = changes_relative_to(other)
|
@@ -66,25 +65,14 @@ module DirectoryDigest
|
|
66
65
|
source_path = "#{other.directory}#{path}"
|
67
66
|
destination_path = "#{directory}#{path}"
|
68
67
|
destination_directory = File.dirname(destination_path)
|
69
|
-
unless Dir.exist?(destination_directory)
|
70
|
-
|
71
|
-
FileUtils.makedirs(destination_directory)
|
72
|
-
end
|
73
|
-
log.call("copy #{source_path} to #{destination_path}")
|
74
|
-
File.open(source_path, 'rb') do |source_file|
|
75
|
-
File.open(destination_path, 'wb') do |destination_file|
|
76
|
-
destination_file.write(source_file.read(4096)) until source_file.eof?
|
77
|
-
end
|
78
|
-
end
|
68
|
+
actions.create_directory(destination_directory) unless Dir.exist?(destination_directory)
|
69
|
+
actions.copy_file(source_path, destination_path)
|
79
70
|
files_copied += 1
|
80
71
|
end
|
81
72
|
changes[:added].each do |path, _|
|
82
|
-
|
83
|
-
log.call("delete #{destination_path}")
|
84
|
-
File.delete(destination_path)
|
73
|
+
actions.delete_file("#{directory}#{path}")
|
85
74
|
files_deleted += 1
|
86
75
|
end
|
87
|
-
log.call("synchronized - files copied: #{files_copied} - files deleted: #{files_deleted}")
|
88
76
|
{ files_copied: files_copied, files_deleted: files_deleted }
|
89
77
|
end
|
90
78
|
|
@@ -97,4 +85,23 @@ module DirectoryDigest
|
|
97
85
|
Digest.new(json['directory'], json['directory_digest'], json['file_digests'])
|
98
86
|
end
|
99
87
|
end
|
88
|
+
|
89
|
+
# DirectoryDigest::MirrorActions - Provider for standard mirror making activities
|
90
|
+
class MirrorActions
|
91
|
+
def create_directory(directory)
|
92
|
+
FileUtils.makedirs(directory)
|
93
|
+
end
|
94
|
+
|
95
|
+
def copy_file(source, destination)
|
96
|
+
File.open(source, 'rb') do |source_file|
|
97
|
+
File.open(destination, 'wb') do |destination_file|
|
98
|
+
destination_file.write(source_file.read(4096)) until source_file.eof?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def delete_file(filename)
|
104
|
+
File.delete(filename)
|
105
|
+
end
|
106
|
+
end
|
100
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: directory-digest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Heald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|