Sha256: e9b450234b36f1d9eb0b5bebe8a8b7dcfe7bae5e162587cc3f1d161c5e213ce7
Contents?: true
Size: 1.06 KB
Versions: 5
Compression:
Stored size: 1.06 KB
Contents
#!/usr/bin/env ruby module FileCreation ANCIENT_FILE = 'testdata/anc' OLDFILE = "testdata/old" MIDDLE_AGED_FILE = "testdata/mid" NEWFILE = "testdata/new" def create_timed_files(oldfile, *newfiles) return if File.exist?(oldfile) && newfiles.all? { |newfile| File.exist?(newfile) } old_time = create_file(oldfile) newfiles.each do |newfile| while create_file(newfile) <= old_time sleep(0.1) File.delete(newfile) rescue nil end end end def create_dispersed_timed_files(*files) create_file(files.first) (1...files.size).each do |index| while create_file(files[index]) <= File.stat(files[index - 1]).mtime sleep(0.1) File.delete(files[index]) end end end def create_dir(dirname) FileUtils.mkdir_p(dirname) unless File.exist?(dirname) File.stat(dirname).mtime end def create_file(name) create_dir(File.dirname(name)) FileUtils.touch(name) unless File.exist?(name) File.stat(name).mtime end def delete_file(name) File.delete(name) rescue nil end end
Version data entries
5 entries across 5 versions & 1 rubygems