git-linguist: Do not write cache if repo is gone

This commit is contained in:
Vicent Marti
2015-09-28 01:45:04 -07:00
parent 41d438b47e
commit 7c759d4d29

View File

@@ -71,17 +71,20 @@ class GitLinguist
end
def write_cache(object)
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
return unless File.directory? @repo_path
File.open(tmp_path, "wb") do |f|
marshal = Marshal.dump(object)
f.write(Zlib::Deflate.deflate(marshal))
begin
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
File.open(tmp_path, "wb") do |f|
marshal = Marshal.dump(object)
f.write(Zlib::Deflate.deflate(marshal))
end
File.rename(tmp_path, cache_file)
rescue => e
(File.unlink(tmp_path) rescue nil)
raise e
end
File.rename(tmp_path, cache_file)
tmp_path = nil
ensure
(File.unlink(tmp_path) rescue nil) if tmp_path
end
def load_cache