s3diff 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/s3diff/comparator.rb +9 -1
- data/lib/s3diff/local_file.rb +22 -2
- data/lib/s3diff/s3_file.rb +17 -4
- data/lib/s3diff/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e40ffd6ec8145f05a3ded8e43eb042381898f81
|
4
|
+
data.tar.gz: e95b2172ceca0bc40cd249f02787e74a074ebcad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dab1c303df16276ad546c60cb6f55af8343d341ac167e61e7d7688185aafad3b84e26c60275191cf81572d5020c09be58847867a4e74ed62db22346b2ae4e483
|
7
|
+
data.tar.gz: fb4bb3c096a6961e167debd1f24ced1905d2dbf91c09ba16170f2022ab002c5c23de1a05023e1228a5685e635f0119a3dab38a11ed565664ee3adfcabb8f1caf
|
data/lib/s3diff/comparator.rb
CHANGED
@@ -8,8 +8,16 @@ module S3diff
|
|
8
8
|
@file2 = file_object(file2)
|
9
9
|
end
|
10
10
|
|
11
|
+
def both_exist?
|
12
|
+
@both_exist ||= begin
|
13
|
+
puts "#{@file1.original_path} is not exist." unless @file1.exist?
|
14
|
+
puts "#{@file2.original_path} is not exist." unless @file2.exist?
|
15
|
+
@file1.exist? && @file2.exist?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
def same_etag?
|
12
|
-
@file1.etag == @file2.etag
|
20
|
+
both_exist? && @file1.etag == @file2.etag
|
13
21
|
end
|
14
22
|
|
15
23
|
def same?
|
data/lib/s3diff/local_file.rb
CHANGED
@@ -7,15 +7,35 @@ module S3diff
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def etag
|
10
|
-
Digest::MD5.file(@file_path).to_s
|
10
|
+
Digest::MD5.file(@file_path).to_s if exist?
|
11
11
|
end
|
12
12
|
|
13
13
|
def size
|
14
|
-
File.size(@file_path)
|
14
|
+
File.size(@file_path) if exist?
|
15
15
|
end
|
16
16
|
|
17
17
|
def path
|
18
|
+
if exist?
|
19
|
+
original_path
|
20
|
+
else
|
21
|
+
cache_file.path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def original_path
|
18
26
|
@file_path
|
19
27
|
end
|
28
|
+
|
29
|
+
def exist?
|
30
|
+
File.exist?(@file_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def cache_file
|
36
|
+
@cache_file ||= begin
|
37
|
+
Tempfile.new("")
|
38
|
+
end
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
data/lib/s3diff/s3_file.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "tempfile"
|
2
|
+
require "ostruct"
|
2
3
|
|
3
4
|
module S3diff
|
4
5
|
class S3File
|
@@ -8,27 +9,39 @@ module S3diff
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def etag
|
11
|
-
head.etag.delete(%("))
|
12
|
+
head.etag.delete(%(")) if exist?
|
12
13
|
end
|
13
14
|
|
14
15
|
def size
|
15
|
-
head.content_length
|
16
|
+
head.content_length if exist?
|
16
17
|
end
|
17
18
|
|
18
19
|
def path
|
19
20
|
cache_file.path
|
20
21
|
end
|
21
22
|
|
23
|
+
def original_path
|
24
|
+
@uri
|
25
|
+
end
|
26
|
+
|
27
|
+
def exist?
|
28
|
+
!head.nil?
|
29
|
+
end
|
30
|
+
|
22
31
|
private
|
23
32
|
|
24
33
|
def head
|
25
|
-
@head ||=
|
34
|
+
@head ||= begin
|
35
|
+
@s3c.head_object(@uri)
|
36
|
+
rescue Aws::S3::Errors::NotFound
|
37
|
+
nil
|
38
|
+
end
|
26
39
|
end
|
27
40
|
|
28
41
|
def cache_file
|
29
42
|
@cache_file ||= begin
|
30
43
|
f = Tempfile.new("")
|
31
|
-
@s3c.get_object(@uri, f)
|
44
|
+
@s3c.get_object(@uri, f) if exist?
|
32
45
|
f.flush
|
33
46
|
f
|
34
47
|
end
|
data/lib/s3diff/version.rb
CHANGED