Sha256: 8b398040ce6c719e4c75ac935f078081982ad8612e1d68155aac81e45db190b6

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

module PluginTool
  
  # NOTE: Also update packing.rb if this changes
  ALLOWED_PLUGIN_DIRS = ['js', 'static', 'template', 'test', 'data']
  
  def self.generate_manifest(directory)
    manifest = Hash.new
    Dir.glob("#{directory}/**/*").sort.each do |pathname|
      # Ignore directories
      next unless File.file? pathname
      # Ignore Emacs backup files
      next if pathname =~ /\~\z/
      # Check file
      filename = pathname.slice(directory.length + 1, pathname.length)
      raise "Bad filename for #{filename}" unless filename =~ /\A([a-zA-Z0-9_\/\-]+\/)?([a-z0-9_-]+\.[a-z0-9]+)\z/
      dir = $1
      name = $2
      if dir != nil
        dir = dir.gsub(/\/\z/,'')
        raise "Bad directory #{dir}" unless dir =~ /\A([a-zA-Z0-9_\-]+)[a-zA-Z0-9_\/\-]*\z/
        raise "Bad root directory #{$1}" unless ALLOWED_PLUGIN_DIRS.include?($1)
      end
      # Get hash of file
      digest = File.open(pathname) { |f| Digest::SHA256.hexdigest(f.read) }
      # And add to manifest
      manifest[filename] = digest
    end
    manifest
  end
  
  def self.determine_manifest_changes(from, to)
    changes = []
    from.each_key do |name|
      changes << [name, :delete] unless to.has_key?(name)
    end
    to.each do |name,hash|
      changes << [name, hash] unless from[name] == hash
    end
    changes
  end
  
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
haplo-2.1.0-java lib/manifest.rb
oneis-2.0.6-java lib/manifest.rb
oneis-2.0.5-java lib/manifest.rb
oneis-2.0.4-java lib/manifest.rb
oneis-2.0.3-java lib/manifest.rb
oneis-2.0.2-java lib/manifest.rb
oneis-2.0.1-java lib/manifest.rb