OSDN Git Service

picture storerer updated
[pettanr/pettanr.git] / lib / local_picture.rb
index 74f020c..85160df 100644 (file)
@@ -33,26 +33,44 @@ class PictureIO
     end
     
     def exist?(filename, subdir = nil)
-      File.exist?(dir(subdir) + filename)
+      begin
+        File.exist?(dir(subdir) + filename)
+      rescue StandardError
+        false
+      end
     end
     
     def put(bindata, filename, subdir = nil)
       mkdir subdir
-      open(dir(subdir) + filename, 'wb') do |f|
-        f.write bindata
+      begin
+        open(dir(subdir) + filename, 'wb') do |f|
+          f.write bindata
+        end
+        true
+      rescue StandardError
+        false
       end
     end
     
     def get(filename, subdir = nil)
       bindata = ''
-      open(dir(subdir) + filename, 'rb') do |f|
-        bindata += f.read
+      begin
+        open(dir(subdir) + filename, 'rb') do |f|
+          bindata += f.read
+        end
+        bindata
+      rescue StandardError
+        false
       end
-      bindata
     end
     
     def delete(filename, subdir = nil)
-      File.delete(dir(subdir) + filename)
+      begin
+        File.delete(dir(subdir) + filename)
+        true
+      rescue StandardError
+        false
+      end
     end
     
   end