From c09865e646ee32c22cc97fa3bdb771cdcef1c71e Mon Sep 17 00:00:00 2001 From: Andre Meij Date: Fri, 5 Aug 2011 15:37:53 +0200 Subject: [PATCH] - Write files as binary (otherwise UTF8 - ASCII errors can occur) - Check if File exists before trying to delete it (paperclip sometimes deletes files twice) - Check if Directory exists before trying to "cd" into it. --- lib/fog/storage/models/local/file.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/fog/storage/models/local/file.rb b/lib/fog/storage/models/local/file.rb index afd4407ff..992f7c78d 100644 --- a/lib/fog/storage/models/local/file.rb +++ b/lib/fog/storage/models/local/file.rb @@ -38,7 +38,7 @@ module Fog def destroy requires :directory, :key - ::File.delete(path) + ::File.delete(path) if ::File.exists?(path) dirs = path.split(::File::SEPARATOR)[0...-1] dirs.length.times do |index| dir_path = dirs[0..-index].join(::File::SEPARATOR) @@ -50,11 +50,13 @@ module Fog break end pwd = Dir.pwd - Dir.chdir(dir_path) - if Dir.glob('*').empty? - Dir.rmdir(dir_path) + if ::Dir.exists?(dir_path) + Dir.chdir(dir_path) + if Dir.glob('*').empty? + Dir.rmdir(dir_path) + end + Dir.chdir(pwd) end - Dir.chdir(pwd) end true end @@ -80,7 +82,7 @@ module Fog Dir.mkdir(dir_path) end end - file = ::File.new(path, 'w') + file = ::File.new(path, 'wb') if body.is_a?(String) file.write(body) else