#!/usr/bin/ruby # # $Id: ciabot_commitinfo.rb,v 1.2 2004/12/04 03:20:32 shugo Exp $ # Copyright (C) 2004 Shugo Maeda # # This library is distributed under the terms of the Ruby license. # You can freely distribute/modify this library. # # Example of commitinfo: # # ALL $CVSROOT/CVSROOT/ciabot_commitinfo.rb countfile = format("/tmp/cia_commitcount.%s.%d", ENV["USER"], Process.getpgrp) begin open(countfile, "r+") do |f| stat = f.stat if stat.uid != Process.uid || stat.mode & 077 != 0 STDERR.printf("%s: illegal stat - uid=%d gid=%d mode=%o\n", countfile, stat.uid, stat.gid, stat.mode) exit 1 end n = Marshal.load(f) f.rewind Marshal.dump(n + 1, f) f.truncate(f.pos) end rescue Errno::ENOENT open(countfile, File::WRONLY | File::CREAT | File::EXCL, 0600) do |f| Marshal.dump(1, f) end end