我需要从 zip 存档中提取单个文件。以下工作在某一时刻工作,然后停止。我已经尝试以最基本的方式从头开始重新编写它几次,但它仍然找不到我正在搜索的文件。
def restore(file)
#pulls specified file from last commit
found = []
#files.each do |file|
print "Restoring #{file}"
puts
Zip::ZipFile.open(".fuzz/commits/#{last_commit}.zip") do |zip_file|
zip_file.each do |f|
if f == file.strip
if File.exists?(file)
FileUtils.mv(file, "#{file}.temp")
end
FileUtils.cp(f, Dir.pwd)
found << file
if File.exists?("#{file}.temp")
FileUtils.rm_rf("#{file}.temp")
end
else
puts "#{file} is not #{f}" #added this to make sure that 'file' was being read correctly and matched correctly.
end
end
end
print "\r"
if found.empty? == false
puts "#{found} restored."
else
puts "No files were restored"
end
#end
end
“#{file} is not #{f} 显示两个文件,但仍然认为没有匹配项。过去一天我已经为此绞尽脑汁了。我希望我刚刚变得愚蠢并且我缺少明显的缺陷/错字。