Method: OcflTools::OcflObject#delete_file
- Defined in:
- lib/ocfl_tools/ocfl_object.rb
#delete_file(file, version) ⇒ Hash
Given a filepath, deletes that file from the given version. If multiple copies of the same file (as identified by a common digest) exist in the version, only the requested filepath is removed.
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/ocfl_tools/ocfl_object.rb', line 287 def delete_file(file, version) # remove filename, may remove digest if that was last file associated with that digest. my_state = get_state(version) # Creates version & copies state from prior version if doesn't exist. unless version == version_id_list.max raise OcflTools::Errors::CannotEditPreviousVersion, "Can't edit prior versions! Only version #{version_id_list.max} can be modified now." end my_digest = get_digest(file, version) # we know it's here b/c self.get_digest would have crapped out if not. my_array = my_state[my_digest] # Get [Array] of files that have this digest in this version. my_array.delete(file) # Delete the array value that matches file. if !my_array.empty? # update the array with (fewer) items. my_state[my_digest] = my_array else # delete the key. my_state.delete(my_digest) end # put results back into State. set_state(version, my_state) end |