[postr] Verify when a file does not exist (#576969)



commit 30422f4678d1b4ff1d930ae00610fb4d022269d1
Author: Germán Póo-Caamaño <gpoo gnome org>
Date:   Wed Nov 4 18:30:10 2009 -0300

    Verify when a file does not exist (#576969)
    
    When postr is invoked through the shell using a filename as
    argument, it does not check if the file exists.  Hence, the
    program fails.

 src/postr.py |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/src/postr.py b/src/postr.py
index a7d3748..7351064 100644
--- a/src/postr.py
+++ b/src/postr.py
@@ -578,7 +578,14 @@ class Postr(UniqueApp):
         # TODO: MIME type check
 
         # Check the file size
-        filesize = os.path.getsize(filename)
+        try:
+            filesize = os.path.getsize(filename)
+        except os.error:
+            d = ErrorDialog(self.window)
+            d.set_from_string("File at %s does not exist or is currently inaccessible." % filename)
+            d.show_all()
+            return
+
         if filesize > 20 * 1024 * 1024:
             d = ErrorDialog(self.window)
             d.set_from_string("Image %s is too large, images must be no larger than 20MB in size." % filename)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]