Skip to content

Instantly share code, notes, and snippets.

@coffeeaddict
Last active December 12, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coffeeaddict/4754723 to your computer and use it in GitHub Desktop.
Save coffeeaddict/4754723 to your computer and use it in GitHub Desktop.
manifesto
# A sample Gemfile
source "https://rubygems.org"
gem "nokogiri"
GEM
remote: https://rubygems.org/
specs:
nokogiri (1.5.6)
PLATFORMS
ruby
DEPENDENCIES
nokogiri
#!/usr/bin/env ruby
#
# create a manifest file
#
# usage manifest.rb /path/to/root/ name_of_xml.xml
require 'bundler/setup'
require 'find'
require 'nokogiri'
require 'digest/sha2'
root = ARGV.shift || raise("Need a root")
xml_file = ARGV.shift || raise("Need an xml file")
builder = Nokogiri::XML::Builder.new do |xml|
xml.files do
Find::find(root) do |inode|
next if FileTest.directory?(inode)
xml.file(size: FileTest.size(inode), sha256: Digest::SHA256.hexdigest(File.read(inode)), name: inode)
end
end
end
File.open(xml_file, File::CREAT|File::TRUNC|File::WRONLY) do |f|
f.puts builder.to_xml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment