bagit 0.4.6 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 258b30416233feee5590250bd84b8ebc84d4c8db3465a6fb30866eecef46d57f
4
- data.tar.gz: adf39f1b00e380fc9768e3760ae563130f715656e0eb59ed73f3acbe86a74ae1
3
+ metadata.gz: e17d65c9af15cfc4638a668291c406670609270c26824fd83634b088ff0a086d
4
+ data.tar.gz: 23aee83a592d8d722946ae9d6c5ad9b5e93f11dab79fdfef83ee0286800243a1
5
5
  SHA512:
6
- metadata.gz: 881dac45875b30c505b3efc881337c6695764ec944f6f0f9af7bdd037dd7a50670c9a975e1617d7df13af135e678f800551310dbd0555a57326f4adec88e1c1d
7
- data.tar.gz: 375a19f57ed7d8752050ccf7e68499dfd1bb29187c23ae21a85113477e9297e42b932fd931f4fd8981e612a8f1a8bd7a7cb87f04c0c7ae3a3606b90bcdd7e3cb
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.3"
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.6"
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.6
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: 2023-08-29 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,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
184
  version: '2.0'
185
185
  - - "<"
186
186
  - !ruby/object:Gem::Version
187
- version: '3.3'
187
+ version: '3.4'
188
188
  required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - ">="