Add some more detailed validation/error reporting to the importing tool.
authorTravis Reitter <travis.reitter@collabora.co.uk>
Fri, 10 Sep 2010 19:13:42 +0000 (12:13 -0700)
committerTravis Reitter <travis.reitter@collabora.co.uk>
Fri, 10 Sep 2010 19:13:42 +0000 (12:13 -0700)
tools/import-pidgin.vala

index 22790a4..48a6170 100644 (file)
@@ -41,6 +41,33 @@ public class Folks.Importers.Pidgin : Folks.Importer
               ".purple", "blist.xml", null);
         }
 
+      var file = File.new_for_path (filename);
+      if (!file.query_exists ())
+        {
+          throw new ImportError.MALFORMED_INPUT ("File %s does not exist.",
+              filename);
+        }
+
+      FileInfo file_info;
+      try
+        {
+          file_info = yield file.query_info_async (
+              FILE_ATTRIBUTE_ACCESS_CAN_READ, FileQueryInfoFlags.NONE,
+              Priority.DEFAULT);
+        }
+      catch (GLib.Error e)
+        {
+          throw new ImportError.MALFORMED_INPUT (
+              "Failed to get information about file %s: %s", filename,
+              e.message);
+        }
+
+      if (!file_info.get_attribute_boolean (FILE_ATTRIBUTE_ACCESS_CAN_READ))
+        {
+          throw new ImportError.MALFORMED_INPUT ("File %s is not readable.",
+              filename);
+        }
+
       Xml.Doc* xml_doc = Parser.parse_file (filename);
 
       if (xml_doc == null)