Methods
C
D
M
N
S
T
U
Attributes
[R] source
[R] target
Class Public methods
new(vpath)
# File tool/checksum.rb, line 6
def initialize(vpath)
  @vpath = vpath
end
update(argv)
# File tool/checksum.rb, line 67
def self.update(argv)
  k = new(VPath.new)
  k.source, k.target, *argv = k.def_options.parse(*argv)
  k.update {|k| yield(k, *argv)}
end
Instance Public methods
copy(name)
# File tool/checksum.rb, line 50
def copy(name)
  @vpath.open(name, "rb") {|f|
    IO.copy_stream(f, name)
  }
  true
end
def_options(opt = (require 'optparse'; OptionParser.new))
# File tool/checksum.rb, line 61
def def_options(opt = (require 'optparse'; OptionParser.new))
  @vpath.def_options(opt)
  opt.on("--make=PATH") {|v| @make = v}
  opt
end
make(*args)
# File tool/checksum.rb, line 57
def make(*args)
  system(@make, *args)
end
source=(source)
# File tool/checksum.rb, line 12
def source=(source)
  @source = source
  @checksum = File.basename(source, ".*") + ".chksum"
end
target=(target)
# File tool/checksum.rb, line 17
def target=(target)
  @target = target
end
update()
# File tool/checksum.rb, line 44
def update
  return true if update?
  update! if ret = yield(self)
  ret
end
update!()
# File tool/checksum.rb, line 38
def update!
  open(@checksum, "wb") {|f|
    f.puts("src=\"#{@source}\", len=#{@len}, checksum=#{@sum}")
  }
end
update?()
# File tool/checksum.rb, line 21
def update?
  src = @vpath.read(@source)
  @len = src.length
  @sum = src.sum
  return false unless @vpath.search(File.method(:exist?), @target)
  begin
    data = @vpath.read(@checksum)
  rescue
    return false
  else
    return false unless data[/src="([0-9a-z_.-]+)",/, 1] == @source
    return false unless @len == data[/\blen=(\d+)/, 1].to_i
    return false unless @sum == data[/\bchecksum=(\d+)/, 1].to_i
    return true
  end
end