lib/zold/copies.rb in zold-0.9.8 vs lib/zold/copies.rb in zold-0.9.9
- old
+ new
@@ -42,11 +42,11 @@
def clean
list = load
list.reject! { |s| s[:time] < Time.now - 24 * 60 * 60 }
save(list)
- Dir.new(@dir).select { |f| f =~ /[0-9]+/ }.each do |f|
+ Dir.new(@dir).select { |f| f =~ /^[0-9]+$/ }.each do |f|
File.delete(File.join(@dir, f)) if list.find { |s| s[:name] == f }.nil?
end
end
def remove(host, port)
@@ -64,10 +64,10 @@
FileUtils.mkdir_p(@dir)
list = load
target = list.find { |s| File.read(File.join(@dir, s[:name])) == content }
if target.nil?
max = Dir.new(@dir)
- .select { |f| f =~ /[0-9]+/ }
+ .select { |f| f =~ /^[0-9]+$/ }
.map(&:to_i)
.max
max = 0 if max.nil?
name = (max + 1).to_s
File.write(File.join(@dir, name), content)