From 870d35a8507c8b7a6ada2c34de5c9c8653e53a46 Mon Sep 17 00:00:00 2001 From: David Rajchenbach-Teller Date: Tue, 26 Nov 2013 14:21:03 -0500 Subject: [PATCH] Bug 935792 - ignoreAbsent flag for removeDir() doesn't default to true as intended/documented. r=froydnj --- .../osfile/modules/osfile_shared_front.jsm | 6 ++++-- .../osfile/tests/xpcshell/test_removeDir.js | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/toolkit/components/osfile/modules/osfile_shared_front.jsm b/toolkit/components/osfile/modules/osfile_shared_front.jsm index f6f09dc73d0..084ef1a776b 100644 --- a/toolkit/components/osfile/modules/osfile_shared_front.jsm +++ b/toolkit/components/osfile/modules/osfile_shared_front.jsm @@ -474,8 +474,10 @@ AbstractFile.writeAtomic = */ AbstractFile.removeDir = function(path, options = {}) { let iterator = new OS.File.DirectoryIterator(path); - if (!iterator.exists() && options.ignoreAbsent) { - return; + if (!iterator.exists()) { + if (!("ignoreAbsent" in options) || options.ignoreAbsent) { + return; + } } try { diff --git a/toolkit/components/osfile/tests/xpcshell/test_removeDir.js b/toolkit/components/osfile/tests/xpcshell/test_removeDir.js index af1b2138b31..095b8f0d4fa 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_removeDir.js +++ b/toolkit/components/osfile/tests/xpcshell/test_removeDir.js @@ -36,7 +36,7 @@ add_task(function() { // Remove non-existent directory let exception = null; try { - yield OS.File.removeDir(dir); + yield OS.File.removeDir(dir, {ignoreAbsent: false}); } catch (ex) { exception = ex; } @@ -46,12 +46,13 @@ add_task(function() { // Remove non-existent directory with ignoreAbsent yield OS.File.removeDir(dir, {ignoreAbsent: true}); + yield OS.File.removeDir(dir); - // Remove file + // Remove file with ignoreAbsent: false yield OS.File.writeAtomic(file, "content", { tmpPath: file + ".tmp" }); exception = null; try { - yield OS.File.removeDir(file); + yield OS.File.removeDir(file, {ignoreAbsent: false}); } catch (ex) { exception = ex; } @@ -67,15 +68,14 @@ add_task(function() { // Remove directory that contains one file yield OS.File.makeDir(dir); yield OS.File.writeAtomic(file1, "content", { tmpPath: file1 + ".tmp" }); - //yield OS.File.open(file1, {create:true}); - yield OS.File.removeDir(dir) + yield OS.File.removeDir(dir); do_check_false((yield OS.File.exists(dir))); // Remove directory that contains multiple files yield OS.File.makeDir(dir); yield OS.File.writeAtomic(file1, "content", { tmpPath: file1 + ".tmp" }); yield OS.File.writeAtomic(file2, "content", { tmpPath: file2 + ".tmp" }); - yield OS.File.removeDir(dir) + yield OS.File.removeDir(dir); do_check_false((yield OS.File.exists(dir))); // Remove directory that contains a file and a directory