-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from projecthydra-labs/use_marshal_vs_yaml
Use Marshal to serialize minter state rather than YAML
- Loading branch information
Showing
4 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ require 'rspec/core/rake_task' | |
|
||
task default: :spec | ||
RSpec::Core::RakeTask.new | ||
|
||
import './lib/tasks/noid_tasks.rake' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'active_fedora/noid' | ||
require 'noid' | ||
require 'yaml' | ||
|
||
namespace :active_fedora do | ||
namespace :noid do | ||
desc 'Migrate minter state file from YAML to Marshal' | ||
task :migrate_statefile do | ||
statefile = ENV.fetch('AFNOID_STATEFILE', ActiveFedora::Noid.config.statefile) | ||
raise "File not found: #{statefile}\nAborting" unless File.exist?(statefile) | ||
puts "Migrating #{statefile} from YAML to Marshal serialization..." | ||
File.open(statefile, File::RDWR | File::CREAT, 0644) do |f| | ||
f.flock(File::LOCK_EX) | ||
begin | ||
yaml_state = YAML.load(f) | ||
rescue Psych::SyntaxError | ||
raise "File not valid YAML: #{statefile}\nAborting." | ||
end | ||
minter = Noid::Minter.new(yaml_state) | ||
f.rewind | ||
new_state = Marshal.dump(minter.dump) | ||
f.write(new_state) | ||
f.flush | ||
f.truncate(f.pos) | ||
end | ||
puts "Done!" | ||
end | ||
end | ||
end |