moab-versioning 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/moab/storage_object_validator.rb +33 -10
- data/lib/stanford/storage_object_validator.rb +2 -2
- 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: b369a2ecc1e65bdcf4a40dfde46176838912ce2f
|
4
|
+
data.tar.gz: 8e9b829361e700e12220e203204433a1c56e7b55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b076d84c4bc16759c646234d37625068922cdbbbbe68add37bb0922c21d9963441ce7d280bab4f1d5511a078364004b0c59c9d7b4a376f60fe7f37ed8844f674
|
7
|
+
data.tar.gz: 81a48dbd61d60ca5469cba9d330970cb4b929a003bcea55177294f8426eca1d84e223988fdf70ac95ee818e38787992ae2355d3f3fe7d8c1718d8807a78fa803
|
@@ -16,6 +16,8 @@ module Moab
|
|
16
16
|
MANIFEST_INVENTORY_PATH = File.join(MANIFESTS_DIR, "manifestInventory.xml").freeze
|
17
17
|
SIGNATURE_CATALOG_PATH = File.join(MANIFESTS_DIR, "signatureCatalog.xml").freeze
|
18
18
|
|
19
|
+
FORBIDDEN_CONTENT_SUB_DIRS = ([DATA_DIR, MANIFESTS_DIR] + EXPECTED_DATA_SUB_DIRS).freeze
|
20
|
+
|
19
21
|
# error codes
|
20
22
|
INCORRECT_DIR_CONTENTS = 0
|
21
23
|
MISSING_DIR = 1
|
@@ -30,6 +32,7 @@ module Moab
|
|
30
32
|
NO_FILES_IN_METADATA_DIR = 10
|
31
33
|
NO_FILES_IN_CONTENT_DIR = 11
|
32
34
|
CONTENT_SUB_DIRS_DETECTED = 12
|
35
|
+
BAD_SUB_DIR_IN_CONTENT_DIR = 13
|
33
36
|
|
34
37
|
attr_reader :storage_obj_path
|
35
38
|
|
@@ -38,11 +41,11 @@ module Moab
|
|
38
41
|
@directory_entries_hash = {}
|
39
42
|
end
|
40
43
|
|
41
|
-
def validation_errors
|
44
|
+
def validation_errors(allow_content_subdirs=true)
|
42
45
|
errors = []
|
43
46
|
errors.concat check_correctly_named_version_dirs
|
44
47
|
errors.concat check_sequential_version_dirs if errors.empty?
|
45
|
-
errors.concat check_correctly_formed_moab if errors.empty?
|
48
|
+
errors.concat check_correctly_formed_moab(allow_content_subdirs) if errors.empty?
|
46
49
|
errors
|
47
50
|
end
|
48
51
|
|
@@ -61,7 +64,8 @@ module Moab
|
|
61
64
|
VERSIONS_NOT_IN_ORDER => "Should contain only sequential version directories. Current directories: %{addl}",
|
62
65
|
NO_FILES_IN_METADATA_DIR => "Version %{addl}: No files present in metadata dir",
|
63
66
|
NO_FILES_IN_CONTENT_DIR => "Version %{addl}: No files present in content dir",
|
64
|
-
CONTENT_SUB_DIRS_DETECTED => "Version %{addl}: content directory should only contain files, not directories"
|
67
|
+
CONTENT_SUB_DIRS_DETECTED => "Version %{addl}: content directory should only contain files, not directories",
|
68
|
+
BAD_SUB_DIR_IN_CONTENT_DIR => "Version %{addl}: content directory has forbidden sub-directory name: vnnnn or #{FORBIDDEN_CONTENT_SUB_DIRS}"
|
65
69
|
}.freeze
|
66
70
|
end
|
67
71
|
|
@@ -75,11 +79,15 @@ module Moab
|
|
75
79
|
errors = []
|
76
80
|
errors << result_hash(MISSING_DIR, 'no versions exist') unless version_directories.count > 0
|
77
81
|
version_directories.each do |version_dir|
|
78
|
-
errors << result_hash(VERSION_DIR_BAD_FORMAT, version_dir) unless version_dir
|
82
|
+
errors << result_hash(VERSION_DIR_BAD_FORMAT, version_dir) unless version_dir_format?(version_dir)
|
79
83
|
end
|
80
84
|
errors
|
81
85
|
end
|
82
86
|
|
87
|
+
def version_dir_format?(dirname)
|
88
|
+
dirname =~ /^[v]\d{4}$/
|
89
|
+
end
|
90
|
+
|
83
91
|
# call only if the version directories are "correctly named" vdddd
|
84
92
|
def check_sequential_version_dirs
|
85
93
|
errors = []
|
@@ -93,14 +101,14 @@ module Moab
|
|
93
101
|
errors
|
94
102
|
end
|
95
103
|
|
96
|
-
def check_correctly_formed_moab
|
104
|
+
def check_correctly_formed_moab(allow_content_subdirs=true)
|
97
105
|
errors = []
|
98
106
|
version_directories.each do |version_dir|
|
99
107
|
version_path = File.join(storage_obj_path, version_dir)
|
100
108
|
version_error_count = errors.size
|
101
109
|
errors.concat check_version_sub_dirs(version_path, version_dir)
|
102
110
|
errors.concat check_required_manifest_files(version_path, version_dir) if version_error_count == errors.size
|
103
|
-
errors.concat check_data_directory(version_path, version_dir) if version_error_count == errors.size
|
111
|
+
errors.concat check_data_directory(version_path, version_dir, allow_content_subdirs) if version_error_count == errors.size
|
104
112
|
end
|
105
113
|
errors
|
106
114
|
end
|
@@ -119,13 +127,13 @@ module Moab
|
|
119
127
|
errors
|
120
128
|
end
|
121
129
|
|
122
|
-
def check_data_directory(version_path, version)
|
130
|
+
def check_data_directory(version_path, version, allow_content_subdirs=true)
|
123
131
|
errors = []
|
124
132
|
data_dir_path = File.join(version_path, DATA_DIR)
|
125
133
|
data_sub_dirs = directory_entries(data_dir_path)
|
126
134
|
errors.concat check_data_sub_dirs(version, data_sub_dirs)
|
127
135
|
errors.concat check_metadata_dir_files_only(version_path) if errors.empty?
|
128
|
-
errors.concat
|
136
|
+
errors.concat check_optional_content_dir(version_path, allow_content_subdirs) if data_sub_dirs.include?('content') && errors.empty?
|
129
137
|
errors
|
130
138
|
end
|
131
139
|
|
@@ -141,14 +149,25 @@ module Moab
|
|
141
149
|
errors
|
142
150
|
end
|
143
151
|
|
144
|
-
def
|
152
|
+
def check_optional_content_dir(version_path, allow_content_subdirs=true)
|
145
153
|
errors = []
|
146
154
|
content_dir_path = File.join(version_path, DATA_DIR, CONTENT_DIR)
|
147
155
|
errors << result_hash(NO_FILES_IN_CONTENT_DIR, basename(version_path)) if directory_entries(content_dir_path).empty?
|
148
|
-
errors << result_hash(CONTENT_SUB_DIRS_DETECTED, basename(version_path)) if contains_sub_dir?(content_dir_path)
|
156
|
+
errors << result_hash(CONTENT_SUB_DIRS_DETECTED, basename(version_path)) if contains_sub_dir?(content_dir_path) && !allow_content_subdirs
|
157
|
+
if allow_content_subdirs && contains_sub_dir?(content_dir_path) && contains_forbidden_content_sub_dir?(content_dir_path)
|
158
|
+
errors << result_hash(BAD_SUB_DIR_IN_CONTENT_DIR, basename(version_path))
|
159
|
+
end
|
149
160
|
errors
|
150
161
|
end
|
151
162
|
|
163
|
+
def contains_forbidden_content_sub_dir?(path)
|
164
|
+
sub_dirs(path).detect { |sub_dir| content_sub_dir_forbidden?(sub_dir) }
|
165
|
+
end
|
166
|
+
|
167
|
+
def content_sub_dir_forbidden?(dirname)
|
168
|
+
FORBIDDEN_CONTENT_SUB_DIRS.include?(dirname) || version_dir_format?(dirname)
|
169
|
+
end
|
170
|
+
|
152
171
|
def subset?(first_array, second_array)
|
153
172
|
first_array.to_set.subset?(second_array.to_set)
|
154
173
|
end
|
@@ -208,6 +227,10 @@ module Moab
|
|
208
227
|
directory_entries(path).detect { |entry| File.file?(File.join(path, entry)) }
|
209
228
|
end
|
210
229
|
|
230
|
+
def sub_dirs(path)
|
231
|
+
directory_entries(path).select { |entry| File.directory?(File.join(path, entry)) }
|
232
|
+
end
|
233
|
+
|
211
234
|
def basename(path)
|
212
235
|
path.split(File::SEPARATOR)[-1]
|
213
236
|
end
|
@@ -8,9 +8,9 @@ module Stanford
|
|
8
8
|
# keep from stepping on previously defined error code constants.
|
9
9
|
DRUID_MISMATCH = superclass.error_code_to_messages.keys.max + 1
|
10
10
|
|
11
|
-
def validation_errors
|
11
|
+
def validation_errors(allow_content_subdirs=true)
|
12
12
|
errors = []
|
13
|
-
errors.concat super
|
13
|
+
errors.concat super(allow_content_subdirs)
|
14
14
|
errors.concat(identify_druid) if errors.empty?
|
15
15
|
errors
|
16
16
|
end
|
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.
|
4
|
+
version: 4.1.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-
|
14
|
+
date: 2017-12-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: confstruct
|