From 17d54039f6b4a505ca83fbfb88b6dcccb9cd9d8f Mon Sep 17 00:00:00 2001 From: Travis Reitter Date: Fri, 10 Sep 2010 12:13:42 -0700 Subject: [PATCH] Add some more detailed validation/error reporting to the importing tool. --- tools/import-pidgin.vala | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/import-pidgin.vala b/tools/import-pidgin.vala index 22790a4..48a6170 100644 --- a/tools/import-pidgin.vala +++ b/tools/import-pidgin.vala @@ -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) -- 2.7.4