Bug 1303693 - OS.File.remove(filename, { ignoreAbsent: true }) throws when the parent directory doesn't exist. r=Yoric
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 20 Sep 2016 10:22:15 +1000
changeset 314450 0dbdd9bae77ef9ecfc509824470c4f68e4d81b3e
parent 314449 f4fb6313812c67ee6417482cc3d78d4e952642b7
child 314451 d5a3a0a0bbeb812ff93ef6f02e324b6dccf35527
push id32398
push usermhammond@skippinet.com.au
push dateTue, 20 Sep 2016 09:02:54 +0000
treeherderautoland@0dbdd9bae77e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1303693
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1303693 - OS.File.remove(filename, { ignoreAbsent: true }) throws when the parent directory doesn't exist. r=Yoric MozReview-Commit-ID: HJml1cf430y
toolkit/components/osfile/modules/osfile_win_front.jsm
toolkit/components/osfile/tests/xpcshell/test_remove.js
--- a/toolkit/components/osfile/modules/osfile_win_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_win_front.jsm
@@ -421,17 +421,18 @@
       *
       * @throws {OS.File.Error} In case of I/O error.
       */
      File.remove = function remove(path, options = {}) {
        if (WinFile.DeleteFile(path)) {
          return;
        }
 
-       if (ctypes.winLastError == Const.ERROR_FILE_NOT_FOUND) {
+       if (ctypes.winLastError == Const.ERROR_FILE_NOT_FOUND ||
+           ctypes.winLastError == Const.ERROR_PATH_NOT_FOUND) {
          if ((!("ignoreAbsent" in options) || options.ignoreAbsent)) {
            return;
          }
        } else if (ctypes.winLastError == Const.ERROR_ACCESS_DENIED) {
          // Save winLastError before another ctypes call.
          let lastError = ctypes.winLastError;
          let attributes = WinFile.GetFileAttributes(path);
          if (attributes != Const.INVALID_FILE_ATTRIBUTES) {
--- a/toolkit/components/osfile/tests/xpcshell/test_remove.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_remove.js
@@ -30,8 +30,27 @@ add_task(function* test_ignoreAbsent() {
   try {
     yield OS.File.remove(absent_file_name, {ignoreAbsent: true});
     yield OS.File.remove(absent_file_name);
   } catch (ex) {
     exception = ex;
   }
   Assert.ok(!exception, "OS.File.remove should not throw when not requested.");
 });
+
+add_task(function* test_ignoreAbsent_directory_missing() {
+  let absent_file_name = OS.Path.join("absent_parent", "test.tmp");
+
+  // Removing absent files should throw if "ignoreAbsent" is true.
+  yield Assert.rejects(OS.File.remove(absent_file_name, {ignoreAbsent: false}),
+                       "OS.File.remove throws if there is no such file.");
+
+  // Removing files from absent directories should not throw if "ignoreAbsent"
+  // is true or not defined.
+  let exception = null;
+  try {
+    yield OS.File.remove(absent_file_name, {ignoreAbsent: true});
+    yield OS.File.remove(absent_file_name);
+  } catch (ex) {
+    exception = ex;
+  }
+  Assert.ok(!exception, "OS.File.remove should not throw when not requested.");
+});