bagit 0.4.5 → 0.5.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: e7fadd34fdac2ef57b5f9dd0746566eab445503621052ceba3106519e3961cbe
4
- data.tar.gz: 9e80ad8ca552eac4267620e420b3467cefa46cf88955b94697b6e0dfda060ccb
3
+ metadata.gz: e17d65c9af15cfc4638a668291c406670609270c26824fd83634b088ff0a086d
4
+ data.tar.gz: 23aee83a592d8d722946ae9d6c5ad9b5e93f11dab79fdfef83ee0286800243a1
5
5
  SHA512:
6
- metadata.gz: 390236a9a4aa9cf50374d016b5fe14f11ec56c6430cdf6e36ec6160a5ceb95abb49b5c17733ad1fe1b598209bd9c1c9bcf8b14f356fb3d6bd6fabd2f5de91252
7
- data.tar.gz: ff17dd90c78f4c9ba25ca49d2952ca0b87078a27756368f2948dadbd5f4318a5afa43b1569190fefabfa554812c902e6df5e26358b31bf91d2490db032742d94
6
+ metadata.gz: 17dcf7d21f86cb2c92e74505e509344c45b3febd7d137b34cf43fef08d60a01caf49b58bb2ff3bae6da997344de8da801e879b64f54f83d99953c0dd84b93d79
7
+ data.tar.gz: a63f38b5c951c8c6d207fd831fbdb3467a2fd9c19e6b12d1ce88b364ab5e74d42c6303cc48ae68a55e7e851f9c2dad12b5940e08645f4ddfeec104cf5c14a009
data/bagit.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.authors = ["Tom Johnson, Francesco Lazzarino, Jamie Little"]
15
15
  spec.license = "MIT"
16
16
 
17
- spec.required_ruby_version = ">= 2.0", "< 3.2"
17
+ spec.required_ruby_version = ">= 2.0", "< 3.4"
18
18
 
19
19
  spec.add_dependency "validatable", "~> 1.6"
20
20
  spec.add_dependency "docopt", "~> 0.5.0"
data/lib/bagit/bag.rb CHANGED
@@ -8,9 +8,28 @@ require "bagit/string"
8
8
  require "bagit/valid"
9
9
 
10
10
  module BagIt
11
+ class FileFinder
12
+ def self.find(dir)
13
+ raise NotImplementedError
14
+ end
15
+ end
16
+
17
+ class StandardFileFinder < FileFinder
18
+ def self.find(dir)
19
+ Dir[File.join(dir, "**", "*")].select { |f| File.file? f }
20
+ end
21
+ end
22
+
23
+ class StandardWithHiddenFileFinder < FileFinder
24
+ def self.find(dir)
25
+ Dir.glob(File.join(dir, "**", "*"), File::FNM_DOTMATCH).select { |f| File.file? f }
26
+ end
27
+ end
28
+
11
29
  # Represents the state of a bag on a filesystem
12
30
  class Bag
13
31
  attr_reader :bag_dir
32
+ attr_reader :detect_hidden
14
33
 
15
34
  include Validity # Validity functionality
16
35
  include Info # bagit & bag info functionality
@@ -18,8 +37,11 @@ module BagIt
18
37
  include Fetch # fetch related functionality
19
38
 
20
39
  # Make a new Bag based at path
21
- def initialize(path, info = {}, _create = false)
40
+ def initialize(path, info = {}, _create = false, detect_hidden = false)
22
41
  @bag_dir = path
42
+ @detect_hidden = detect_hidden
43
+ @file_finder = @detect_hidden ? StandardWithHiddenFileFinder : StandardFileFinder
44
+
23
45
  # make the dir structure if it doesn't exist
24
46
  FileUtils.mkdir bag_dir unless File.directory? bag_dir
25
47
  FileUtils.mkdir data_dir unless File.directory? data_dir
@@ -37,7 +59,7 @@ module BagIt
37
59
 
38
60
  # Return the paths to each bag file relative to bag_dir
39
61
  def bag_files
40
- Dir[File.join(data_dir, "**", "*")].select { |f| File.file? f }
62
+ @file_finder.find(data_dir)
41
63
  end
42
64
 
43
65
  # Return the paths to each tag file relative to bag_dir
data/lib/bagit/valid.rb CHANGED
@@ -33,7 +33,11 @@ module BagIt
33
33
 
34
34
  empty_manifests.each do |file|
35
35
  logger.error("#{file} is manifested but not present".red)
36
- errors.add :completeness, "#{file} is manifested but not present"
36
+ error_message = "#{file} is manifested but not present"
37
+ if !detect_hidden && file.start_with?(File.join("data", "."))
38
+ error_message += "; consider turning on hidden file detection"
39
+ end
40
+ errors.add :completeness, error_message
37
41
  end
38
42
  tag_empty_manifests.each do |file|
39
43
  logger.error("#{file} is a manifested tag but not present".red)
data/lib/bagit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BagIt
4
- VERSION = "0.4.5"
4
+ VERSION = "0.5.0"
5
5
  end
data/spec/bagit_spec.rb CHANGED
@@ -165,4 +165,31 @@ RSpec.describe BagIt::Bag do
165
165
  end
166
166
  end
167
167
  end
168
+
169
+ describe "bag with hidden files" do
170
+ before do
171
+ @sandbox = Sandbox.new
172
+
173
+ # make the bag
174
+ @bag_path = File.join @sandbox.to_s, "the_bag"
175
+ @bag = described_class.new @bag_path, {}, false, true
176
+
177
+ # add some files
178
+ @bag.add_file(".keep") { |io| io.puts "" }
179
+ @bag.add_file("test.txt") { |io| io.puts "testing testing" }
180
+ end
181
+
182
+ after do
183
+ @sandbox.cleanup!
184
+ end
185
+
186
+ describe "#bag_files" do
187
+ it "returns an array including non-hidden and hidden files" do
188
+ files = @bag.bag_files.map { |f| f.sub(File.join(@bag_path, "data", ""), "") }
189
+ expect(files).to be_a_kind_of(Array)
190
+ expect(files).not_to be_empty
191
+ expect(files).to eq([".keep", "test.txt"])
192
+ end
193
+ end
194
+ end
168
195
  end
@@ -44,13 +44,17 @@ describe BagIt::Bag do
44
44
 
45
45
  it "is invalid if there are files that are in the manifest but not in the bag" do
46
46
  # add a file and then remove it through the back door
47
- @bag.add_file("file-k") { |io| io.puts "time to go" }
47
+ file_name = "file-k"
48
+ @bag.add_file(file_name) { |io| io.puts "time to go" }
48
49
  @bag.manifest!
49
50
 
50
- FileUtils.rm File.join(@bag.bag_dir, "data", "file-k")
51
+ FileUtils.rm File.join(@bag.bag_dir, "data", file_name)
51
52
 
52
53
  @bag.validate_only("true_for/completeness")
53
54
  expect(@bag.errors.on(:completeness)).not_to be_empty
55
+ expect(@bag.errors.on(:completeness)).to include(
56
+ "#{File.join("data", file_name)} is manifested but not present"
57
+ )
54
58
  expect(@bag).not_to be_valid
55
59
  end
56
60
 
@@ -139,4 +143,63 @@ describe BagIt::Bag do
139
143
  end
140
144
  end
141
145
  end
146
+
147
+ describe "a bag with unmanifested hidden files" do
148
+ before do
149
+ @sandbox = Sandbox.new
150
+
151
+ # make a bag with hidden files not manifested
152
+ @source_bag_path = File.join @sandbox.to_s, "the_bag"
153
+ @source_bag = described_class.new @source_bag_path, {}, false, false
154
+ @source_bag.add_file(".keep") { |io| io.puts "" }
155
+ @source_bag.add_file("test.txt") { |io| io.puts "testing testing" }
156
+ @source_bag.manifest!
157
+ end
158
+
159
+ after do
160
+ @sandbox.cleanup!
161
+ end
162
+
163
+ it "fails validation when hidden file detection is on" do
164
+ @aware_bag = described_class.new @source_bag_path, {}, false, true
165
+ expect(@aware_bag).to_not be_valid
166
+ expect(@aware_bag.errors.on(:completeness)).not_to be_empty
167
+ end
168
+
169
+ it "passes validation when hidden file detection is off" do
170
+ @unaware_bag = described_class.new @source_bag_path, {}, false, false
171
+ expect(@unaware_bag).to be_valid
172
+ end
173
+ end
174
+
175
+ describe "a bag with manifested hidden files" do
176
+ before do
177
+ @sandbox = Sandbox.new
178
+
179
+ # make a bag with hidden files manifested
180
+ @source_bag_path = File.join @sandbox.to_s, "the_bag"
181
+ @source_bag = described_class.new @source_bag_path, {}, false, true
182
+ @source_bag.add_file(".keep") { |io| io.puts "" }
183
+ @source_bag.add_file("test.txt") { |io| io.puts "testing testing" }
184
+ @source_bag.manifest!
185
+ end
186
+
187
+ after do
188
+ @sandbox.cleanup!
189
+ end
190
+
191
+ it "passes validation when hidden file detection is on" do
192
+ @aware_bag = described_class.new @source_bag_path, {}, false, true
193
+ expect(@aware_bag).to be_valid
194
+ end
195
+
196
+ it "fails validation when hidden file detection is off, with suggested fix offered" do
197
+ @unaware_bag = described_class.new @source_bag_path, {}, false, false
198
+ expect(@unaware_bag).to_not be_valid
199
+ expect(@unaware_bag.errors.on(:completeness)).not_to be_empty
200
+ expect(@unaware_bag.errors.on(:completeness)).to include(
201
+ "data/.keep is manifested but not present; consider turning on hidden file detection"
202
+ )
203
+ end
204
+ end
142
205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bagit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson, Francesco Lazzarino, Jamie Little
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-26 00:00:00.000000000 Z
11
+ date: 2024-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: validatable
@@ -184,14 +184,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
184
  version: '2.0'
185
185
  - - "<"
186
186
  - !ruby/object:Gem::Version
187
- version: '3.2'
187
+ version: '3.4'
188
188
  required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
193
  requirements: []
194
- rubygems_version: 3.2.3
194
+ rubygems_version: 3.1.4
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: BagIt package generation and validation