From 50597cc80a48f4a192f44723039e11348b4a6c84 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Thu, 11 Oct 2012 00:59:44 +1100 Subject: [PATCH] Don't overwrite existing files with ;s. Closes issue #914. --- common/content/hints.js | 1 + common/locale/en-US/messages.properties | 2 ++ common/modules/buffer.jsm | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/common/content/hints.js b/common/content/hints.js index 96fe44ac..9c39b094 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -746,6 +746,7 @@ var Hints = Module("hints", { this.modes = {}; this.addMode(";", "Focus hint", buffer.closure.focusElement); this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem)); + // TODO: allow for ! override to overwrite existing paths -- where? --djk this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, false)); this.addMode("f", "Focus frame", function (elem) dactyl.focus(elem.ownerDocument.defaultView)); this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, isScrollable); diff --git a/common/locale/en-US/messages.properties b/common/locale/en-US/messages.properties index 795d5150..62659346 100644 --- a/common/locale/en-US/messages.properties +++ b/common/locale/en-US/messages.properties @@ -207,6 +207,8 @@ io.eNotDir = Not a directory io.eNotDir-1 = Not a directory %S io.exists = File exists (add ! to override) io.exists-1 = File %S exists (add ! to override) +# XXX +io.existsNoOverride-1 = File %S exists io.noCommand-1 = Command not found: %S io.noPrevDir = E186: No previous directory io.noSuchDir-1 = E344: Can't find directory %S diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index c8e436bb..267ceed9 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -585,8 +585,9 @@ var Buffer = Module("Buffer", { * Saves a page link to disk. * * @param {HTMLAnchorElement} elem The page link to save. + * @param {boolean} overwrite If true, overwrite any existing file. */ - saveLink: function saveLink(elem) { + saveLink: function saveLink(elem, overwrite) { let { completion, dactyl, io } = this.modules; let self = this; @@ -604,6 +605,8 @@ var Buffer = Module("Buffer", { if (file.exists() && file.isDirectory()) file.append(Buffer.getDefaultNames(elem)[0][0]); + util.assert(!file.exists() || overwrite, _("io.existsNoOverride", file.path)); + try { if (!file.exists()) file.create(File.NORMAL_FILE_TYPE, octal(644));