From a737e50abcbe0de88f270830f525a882617b0e0a Mon Sep 17 00:00:00 2001 From: John Foerch Date: Mon, 15 Apr 2013 22:22:42 -0400 Subject: [PATCH] load_rc: avoid NS_ERROR_FILE_TARGET_DOES_NOT_EXIST in symlink test Previously, if there was no rc, the symlink test on the rc path would throw NS_ERROR_FILE_TARGET_DOES_NOT_EXIST. This patch introduces a catch for that error. file_symlink_p: new util. takes an nsIFile and returns the value of file.isSymlink(), but also catches the error and returns false if the file does not exist. Note that this cannot be tested with file.exists(), because that method automatically resolves symlinks. --- modules/rc.js | 2 +- modules/utils.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/rc.js b/modules/rc.js index 28f0519..0eae25d 100644 --- a/modules/rc.js +++ b/modules/rc.js @@ -20,7 +20,7 @@ function load_rc () { return; path = make_file(rcfile); if (! path.exists()) { - if (path.isSymlink()) + if (file_symlink_p(path)) dumpln("w: broken symlink, \""+rcfile+"\""); else if (pref_has_user_value("conkeror.rcfile")) dumpln("w: preference conkeror.rcfile is set to "+ diff --git a/modules/utils.js b/modules/utils.js index ceea810..c6228dc 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -54,6 +54,24 @@ function make_file_from_chrome (url) { return make_file(file.path); } + +/** + * file_symlink_p takes an nsIFile and returns the value of + * file.isSymlink(), but also catches the error and returns false if the + * file does not exist. Note that this cannot be tested with + * file.exists(), because that method automatically resolves symlinks. + */ +function file_symlink_p (file) { + try { + return file.isSymlink(); + } catch (e if (e instanceof Ci.nsIException) && + e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) + { + return false; + } +} + + function get_document_content_disposition (document_o) { var content_disposition = null; try { -- 2.11.4.GIT