Class: DPN::Bagit::Bag
- Inherits:
-
Object
- Object
- DPN::Bagit::Bag
- Defined in:
- lib/dpn/bagit/bag.rb,
lib/dpn/bagit/bag/dpn_info_txt.rb
Overview
A wrapper for an unserialized Bag-It bag on disk. Does not support serialized bags. Once created, a Bag object will not change with changes made to the underlying filesystem bag; in that case, a new Bag object should be created.
Defined Under Namespace
Classes: DPNInfoTxt
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Returns true if the Bag contains no files.
-
#errors ⇒ Array<String>
Returns validation errors.
-
#fixity(algorithm) ⇒ String
Get the net fixity of the Bag.
-
#location ⇒ String
Returns the local file location of the Bag.
-
#size ⇒ Fixnum
Returns the total size of the Bag.
-
#uuid ⇒ String
Returns the uuid of the bag, according to dpn-info.txt.
-
#valid? ⇒ Boolean
Checks that all required files are present, no extraneous files are present, and all file digests match manifests.
Instance Method Details
#empty? ⇒ Boolean
Returns true if the Bag contains no files.
162 163 164 |
# File 'lib/dpn/bagit/bag.rb', line 162 def empty?() return @bag.empty? end |
#errors ⇒ Array<String>
Returns validation errors. The list is not populated until a call to #isValid? has been made.
155 156 157 |
# File 'lib/dpn/bagit/bag.rb', line 155 def errors() return @dpnInfo.getErrors() + @validationErrors end |
#fixity(algorithm) ⇒ String
Get the net fixity of the Bag.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dpn/bagit/bag.rb', line 32 def fixity(algorithm) if @cachedFixity == nil case algorithm when :sha256 digest = Digest::SHA256 path = File.join(@location, "tagmanifest-sha256.txt") if File.exists?(path) @cachedFixity = digest.file(path).hexdigest else @cachedFixity = "" @cachedValidity = false end else raise ArgumentError, "Unknown algorithm." end end return @cachedFixity end |
#location ⇒ String
Returns the local file location of the Bag.
71 72 73 |
# File 'lib/dpn/bagit/bag.rb', line 71 def location() return @location end |
#size ⇒ Fixnum
Returns the total size of the Bag.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dpn/bagit/bag.rb', line 55 def size() if @cachedSize == nil size = 0 Find.find(self.location) do |f| if File.file?(f) or File.directory?(f) size += File.size(f) end end @cachedSize = size end return @cachedSize end |
#uuid ⇒ String
Returns the uuid of the bag, according to dpn-info.txt.
78 79 80 |
# File 'lib/dpn/bagit/bag.rb', line 78 def uuid() return @dpnObjectID end |
#valid? ⇒ Boolean
Checks that all required files are present, no extraneous files are present, and all file digests match manifests.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/dpn/bagit/bag.rb', line 86 def valid?() if @cachedValidity == nil if @bag.valid? == false @validationErrors.push(@bag.errors.) end if File.exists?(@bag.fetch_txt_file) == true @validationErrors.push("The file fetch.txt is present and unsupported.") end if Pathname.new(@bag.bag_dir).basename.to_s != @dpnInfo[:dpnObjectID] @validationErrors.push("The name of the root directory does not match the #{@settings[:bag][:dpn_info][:dpnObjectID][:name]}.") end if File.exists?(@bag.manifest_file("sha256")) == true if File.readable?(@bag.manifest_file("sha256")) == false @validationErrors.push("The file manifest-sha256.txt exists but cannot be read.") end else @validationErrors.push("The file manifest-sha256.txt does not exist.") end if File.exists?(@bag.tagmanifest_file("sha256")) == true if File.readable?(@bag.tagmanifest_file("sha256")) == false @validationErrors.push("The file tagmanifest-sha256.txt exists but cannot be read.") end else @validationErrors.push("The file tagmanifest-sha256.txt does not exist.") end if @dpnInfo[:version].to_i <= 0 @validationErrors.push("Version must be > 0.") end uuidValidator = DPN::Bagit::UUID4Validator.new(true) if uuidValidator.isValid?(@dpnInfo[:dpnObjectID]) == false @validationErrors.push("#{@settings[:bag][:dpn_info][:dpnObjectID][:name]} with value \"#{@dpnInfo[:dpnObjectID]}\" is not a valid UUIDv4.") end if uuidValidator.isValid?(@dpnInfo[:firstVersionObjectID]) == false @validationErrors.push("#{@settings[:bag][:dpn_info][:firstVersionObjectID][:name]} with value \"#{@dpnInfo[:firstVersionObjectID]}\" is not a valid UUIDv4.") end @dpnInfo[:rightsObjectIDs].each do |id| if uuidValidator.isValid?(id) == false @validationErrors.push("#{@settings[:bag][:dpn_info][:rightsObjectIDs][:name]} value of \"#{id}\" is not a valid UUIDv4.") end end @dpnInfo[:interpretiveObjectIDs].each do |id| if uuidValidator.isValid?(id) == false @validationErrors.push("#{@settings[:bag][:dpn_info][:interpretiveObjectIDs][:name]} value of \"#{id}\" is not a valid UUIDv4.") end end if @validationErrors.empty? == true and @dpnInfo.getErrors.empty? == true @cachedValidity = true else @cachedValidity = false end end return @cachedValidity end |