2009-10-02 15:07:55 -04:00
|
|
|
module FileCreation
|
2011-06-23 18:11:55 -04:00
|
|
|
OLDFILE = "old"
|
|
|
|
NEWFILE = "new"
|
2009-10-02 15:07:55 -04:00
|
|
|
|
|
|
|
def create_timed_files(oldfile, *newfiles)
|
2011-06-23 18:11:55 -04:00
|
|
|
return if (File.exist?(oldfile) &&
|
|
|
|
newfiles.all? { |newfile|
|
|
|
|
File.exist?(newfile) && File.stat(newfile).mtime > File.stat(oldfile).mtime
|
|
|
|
})
|
|
|
|
now = Time.now
|
|
|
|
|
|
|
|
create_file(oldfile, now - 60)
|
|
|
|
|
2009-10-02 15:07:55 -04:00
|
|
|
newfiles.each do |newfile|
|
2011-06-23 18:11:55 -04:00
|
|
|
create_file(newfile, now)
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_dir(dirname)
|
|
|
|
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
|
|
|
|
File.stat(dirname).mtime
|
|
|
|
end
|
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
def create_file(name, file_time=nil)
|
2009-10-02 15:07:55 -04:00
|
|
|
create_dir(File.dirname(name))
|
|
|
|
FileUtils.touch(name) unless File.exist?(name)
|
2011-06-23 18:11:55 -04:00
|
|
|
File.utime(file_time, file_time, name) unless file_time.nil?
|
2009-10-02 15:07:55 -04:00
|
|
|
File.stat(name).mtime
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_file(name)
|
|
|
|
File.delete(name) rescue nil
|
|
|
|
end
|
|
|
|
end
|