moab-versioning 2.5.1 → 3.0.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/lib/moab/storage_object_validator.rb +80 -27
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cbc9f88a390634b7acc77dacc9839b89849835b
|
4
|
+
data.tar.gz: 815ef9d707ebeea48a711ca985a6a7a28e82c784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c002027ea5b5047ae4024e9f914e8949a652bc067f49e3cff3dee02b8b602f1111c5086a951af9ad2d8c82935da9aa88bbc72eaf75c68d598e0d9bb404845540
|
7
|
+
data.tar.gz: 19a800a7e7b20acb2e14726ce5127d96f30ae05ed3eced4d6a50ae6c7b016298163caa2beb6bcbdab07a8a4868cae7b5fa21e6458b1ad03a7236751d030a8d43
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require 'moab'
|
2
|
+
require 'set'
|
2
3
|
|
3
4
|
module Moab
|
4
5
|
# Given a druid path, are the contents actually a well-formed Moab?
|
5
6
|
# Shameless green: repetitious code included.
|
6
7
|
class StorageObjectValidator
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
METADATA_DIR = "metadata".freeze
|
10
|
+
CONTENT_DIR = "content".freeze
|
11
|
+
EXPECTED_DATA_SUB_DIRS = [CONTENT_DIR, METADATA_DIR].freeze
|
12
|
+
IMPLICIT_DIRS = ['.', '..', '.keep'].freeze # unlike Find.find, Dir.entries returns the current/parent dirs
|
13
|
+
DATA_DIR = "data".freeze
|
14
|
+
EXPECTED_VERSION_SUB_DIRS = [DATA_DIR, "manifests"].freeze
|
12
15
|
MANIFEST_INVENTORY_PATH = 'manifests/manifestInventory.xml'.freeze
|
13
16
|
SIGNATURE_CATALOG_PATH = 'manifests/signatureCatalog.xml'.freeze
|
14
17
|
|
@@ -19,9 +22,13 @@ module Moab
|
|
19
22
|
VERSION_DIR_BAD_FORMAT = 3
|
20
23
|
NO_SIGNATURE_CATALOG = 4
|
21
24
|
NO_MANIFEST_INVENTORY = 5
|
22
|
-
|
25
|
+
NO_FILES_IN_MANIFEST_DIR= 6
|
23
26
|
VERSIONS_NOT_IN_ORDER = 7
|
24
|
-
|
27
|
+
METADATA_SUB_DIRS_DETECTED = 8
|
28
|
+
FILES_IN_VERSION_DIR = 9
|
29
|
+
NO_FILES_IN_METADATA_DIR = 10
|
30
|
+
NO_FILES_IN_CONTENT_DIR = 11
|
31
|
+
CONTENT_SUB_DIRS_DETECTED = 12
|
25
32
|
|
26
33
|
attr_reader :storage_obj_path
|
27
34
|
|
@@ -48,8 +55,12 @@ module Moab
|
|
48
55
|
FILES_IN_VERSION_DIR => "Top level should contain only sequential version directories. Also contains files: %{addl}",
|
49
56
|
NO_SIGNATURE_CATALOG => "Version: %{addl} Missing signatureCatalog.xml",
|
50
57
|
NO_MANIFEST_INVENTORY => "Version: %{addl} Missing manifestInventory.xml",
|
51
|
-
|
52
|
-
|
58
|
+
NO_FILES_IN_MANIFEST_DIR => "Version: %{addl} No files present in manifest dir",
|
59
|
+
METADATA_SUB_DIRS_DETECTED => "Should only contain files, but directories were present in the metadata directory",
|
60
|
+
VERSIONS_NOT_IN_ORDER => "Should contain only sequential version directories. Current directories: %{addl}",
|
61
|
+
NO_FILES_IN_METADATA_DIR => "Version: %{addl} No files present in metadata dir",
|
62
|
+
NO_FILES_IN_CONTENT_DIR => "Version: %{addl} No files present in content dir",
|
63
|
+
CONTENT_SUB_DIRS_DETECTED => "Should only contain files, but directories were present in the content directory"
|
53
64
|
}.freeze
|
54
65
|
end
|
55
66
|
|
@@ -63,6 +74,7 @@ module Moab
|
|
63
74
|
|
64
75
|
def check_correctly_named_version_dirs
|
65
76
|
errors = []
|
77
|
+
errors << result_hash(MISSING_DIR, 'no versions exist') unless version_directories.count > 0
|
66
78
|
version_directories.each do |version_dir|
|
67
79
|
errors << result_hash(VERSION_DIR_BAD_FORMAT) unless version_dir =~ /^[v]\d{4}$/
|
68
80
|
end
|
@@ -88,34 +100,75 @@ module Moab
|
|
88
100
|
version_directories.each do |version_dir|
|
89
101
|
version_path = "#{storage_obj_path}/#{version_dir}"
|
90
102
|
version_sub_dirs = sub_dirs(version_path)
|
91
|
-
|
92
|
-
errors.concat
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
103
|
+
version_error_count = errors.size
|
104
|
+
errors.concat check_version_sub_dirs(version_sub_dirs, version_dir)
|
105
|
+
errors.concat check_required_manifest_files(version_path, version_dir) if version_error_count == errors.size
|
106
|
+
errors.concat check_data_directory(version_path, version_dir) if version_error_count == errors.size
|
107
|
+
end
|
108
|
+
errors
|
109
|
+
end
|
110
|
+
|
111
|
+
def check_version_sub_dirs(version_sub_dirs, version)
|
112
|
+
errors = []
|
113
|
+
version_sub_dir_count = version_sub_dirs.size
|
114
|
+
if version_sub_dir_count == EXPECTED_VERSION_SUB_DIRS.size
|
115
|
+
errors.concat expected_dirs(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
|
116
|
+
elsif version_sub_dir_count > EXPECTED_VERSION_SUB_DIRS.size
|
117
|
+
errors.concat found_unexpected(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
|
118
|
+
elsif version_sub_dir_count < EXPECTED_VERSION_SUB_DIRS.size
|
119
|
+
errors.concat missing_dir(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
|
101
120
|
end
|
121
|
+
errors
|
122
|
+
end
|
102
123
|
|
124
|
+
def check_data_directory(version_path, version)
|
125
|
+
errors = []
|
126
|
+
data_dir_path = "#{version_path}/#{DATA_DIR}"
|
127
|
+
data_sub_dirs = sub_dirs(data_dir_path)
|
128
|
+
errors.concat check_data_sub_dirs(version, data_sub_dirs)
|
129
|
+
errors.concat check_metadata_dir_files_only(version_path) if errors.empty?
|
130
|
+
errors.concat check_optional_content_dir_files_only(version_path) if data_sub_dirs.include?('content') && errors.empty?
|
103
131
|
errors
|
104
132
|
end
|
105
133
|
|
106
|
-
def
|
134
|
+
def check_data_sub_dirs(version, data_sub_dirs)
|
107
135
|
errors = []
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
errors.concat found_unexpected(
|
113
|
-
|
114
|
-
errors.concat missing_dir(sub_dirs, version, required_sub_dirs)
|
136
|
+
if data_sub_dirs.size > EXPECTED_DATA_SUB_DIRS.size
|
137
|
+
errors.concat found_unexpected(data_sub_dirs, version, EXPECTED_DATA_SUB_DIRS)
|
138
|
+
else
|
139
|
+
errors.concat missing_dir(data_sub_dirs, version, [METADATA_DIR]) unless data_sub_dirs.include?(METADATA_DIR)
|
140
|
+
errors.concat found_unexpected(data_sub_dirs, version, EXPECTED_DATA_SUB_DIRS) unless subset?(data_sub_dirs,
|
141
|
+
EXPECTED_DATA_SUB_DIRS)
|
115
142
|
end
|
116
143
|
errors
|
117
144
|
end
|
118
145
|
|
146
|
+
def check_optional_content_dir_files_only(version_path)
|
147
|
+
errors = []
|
148
|
+
dir_list = []
|
149
|
+
content_dir_path = "#{version_path}/#{DATA_DIR}/#{CONTENT_DIR}"
|
150
|
+
content_sub_dirs = sub_dirs(content_dir_path)
|
151
|
+
content_sub_dirs.each { |item| dir_list << File.directory?("#{content_dir_path}/#{item}") }
|
152
|
+
errors << result_hash(NO_FILES_IN_CONTENT_DIR) if directory_entries(content_dir_path).empty?
|
153
|
+
errors << result_hash(CONTENT_SUB_DIRS_DETECTED) if dir_list.include?(true)
|
154
|
+
errors
|
155
|
+
end
|
156
|
+
|
157
|
+
def subset?(first_array, second_array)
|
158
|
+
first_array.to_set.subset?(second_array.to_set)
|
159
|
+
end
|
160
|
+
|
161
|
+
def check_metadata_dir_files_only(version_path)
|
162
|
+
errors = []
|
163
|
+
dir_list = []
|
164
|
+
metadata_dir_path = "#{version_path}/#{DATA_DIR}/#{METADATA_DIR}"
|
165
|
+
metadata_sub_dirs = sub_dirs(metadata_dir_path)
|
166
|
+
metadata_sub_dirs.each { |item| dir_list << File.directory?("#{metadata_dir_path}/#{item}") }
|
167
|
+
errors << result_hash(NO_FILES_IN_METADATA_DIR) if directory_entries(metadata_dir_path).empty?
|
168
|
+
errors << result_hash(METADATA_SUB_DIRS_DETECTED) if dir_list.include?(true)
|
169
|
+
errors
|
170
|
+
end
|
171
|
+
|
119
172
|
# This method removes the implicit '.' and '..' directories.
|
120
173
|
# Returns an array of strings.
|
121
174
|
def directory_entries(path)
|
@@ -174,7 +227,7 @@ module Moab
|
|
174
227
|
elsif !has_manifest_inventory && has_signature_catalog
|
175
228
|
result_hash(NO_MANIFEST_INVENTORY, version)
|
176
229
|
else
|
177
|
-
result_hash(
|
230
|
+
result_hash(NO_FILES_IN_MANIFEST_DIR, version)
|
178
231
|
end
|
179
232
|
errors << result if result
|
180
233
|
errors
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moab-versioning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darren Weber
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-11-
|
14
|
+
date: 2017-11-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: confstruct
|
@@ -301,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
301
301
|
version: '0'
|
302
302
|
requirements: []
|
303
303
|
rubyforge_project:
|
304
|
-
rubygems_version: 2.6.
|
304
|
+
rubygems_version: 2.6.11
|
305
305
|
signing_key:
|
306
306
|
specification_version: 4
|
307
307
|
summary: Ruby implementation of digital object versioning toolkit used by the SULAIR
|