Module: Fixi

Defined in:
lib/fixi.rb,
lib/fixi/version.rb

Defined Under Namespace

Modules: Command Classes: Index

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.command(name) ⇒ Object

Get an instance of the command with the given name



8
9
10
11
# File 'lib/fixi.rb', line 8

def self.command(name)
  return nil unless Command.const_defined? name.capitalize
  Command.const_get(name.capitalize).new
end

.digests(checksums) ⇒ Object

Validate the given comma-separated list of checksum algorithms and return and array of matching Digest implementations



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fixi.rb', line 15

def self.digests(checksums)
  digests = []
  checksums.split(",").each do |checksum|
    begin
      digests << Digest(checksum.upcase).new
    rescue LoadError
      raise "No such algorithm: #{checksum}"
    end
  end
  digests
end

.hexdigests(digests, file) ⇒ Object

Read the file once while computing any number of digests



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fixi.rb', line 28

def self.hexdigests(digests, file)
  File.open(file, "rb") {|f|
    buf = ""
    while f.read(16384, buf)
      digests.each {|digest| digest.update buf}
    end
  }
  hds = []
  digests.each {|digest|
    hd = digest.hexdigest
    hds << hd
  }
  hds
end

.set_metadata(path, stat) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/fixi.rb', line 43

def self.(path, stat)
  File.utime(stat.atime, stat.mtime, path)
  begin
    File.chown(stat.uid, stat.gid, path)
  rescue Errno::EPERM
    File.chmod(stat.mode & 01777, path)
  else
    File.chmod(stat.mode, path)
  end
end