Backout e662aa8c9389 (Bug 780604), 3979c98e3e9a:5ccb28fc0bee (Bug 780498) for Windows orange
authorPhil Ringnalda <philringnalda@gmail.com>
Tue, 07 Aug 2012 21:26:41 -0700
changeset 104896 6be6808c2a4a291d700d8e83ae570d7693b1dfab
parent 104895 5439489dc320dbe10c3826682983480b712039ae
child 104897 6a732d5ea1e894b84a9d6bd73bb255b37f52a155
push idunknown
push userunknown
push dateunknown
bugs780604, 780498
milestone17.0a1
backs oute662aa8c9389976ba3e67a896d710b3594fa8251
Backout e662aa8c9389 (Bug 780604), 3979c98e3e9a:5ccb28fc0bee (Bug 780498) for Windows orange
toolkit/components/osfile/osfile_unix_front.jsm
toolkit/components/osfile/osfile_win_back.jsm
toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
--- a/toolkit/components/osfile/osfile_unix_front.jsm
+++ b/toolkit/components/osfile/osfile_unix_front.jsm
@@ -330,16 +330,32 @@
          let flags = Const.COPYFILE_DATA;
          if (options.noOverwrite) {
            flags |= Const.COPYFILE_EXCL;
          }
          throw_on_negative("copy",
            UnixFile.copyfile(sourcePath, destPath, null, flags)
          );
        };
+
+       // This implementation uses |copyfile(3)|, from the BSD library.
+       // Adding moving of hierarchies and/or attributes is just a flag
+       // away.
+       File.move = function movefile(sourcePath, destPath, options) {
+         // This implementation uses |copyfile(3)|, from the BSD library.
+         // It can move directory hierarchies.
+         options = options || noOptions;
+         let flags = Const.COPYFILE_DATA | Const.COPYFILE_MOVE;
+         if (options.noOverwrite) {
+           flags |= Const.COPYFILE_EXCL;
+         }
+         throw_on_negative("move",
+           UnixFile.copyfile(sourcePath, destPath, null, flags)
+         );
+       };
      } else {
        // If the OS does not implement file copying for us, we need to
        // implement it ourselves. For this purpose, we need to define
        // a pumping function.
 
        /**
         * Copy bytes from one file to another one.
         *
@@ -453,47 +469,46 @@
                return pump_userland(source, dest, options);
              }
              throw x;
            } finally {
              pipe_read.dispose();
              pipe_write.dispose();
            }
          };
-       } else {
-         // Fallback implementation of pump for other Unix platforms.
-         pump = pump_userland;
-       }
+     } else {
+       // Fallback implementation of pump for other Unix platforms.
+       pump = pump_userland;
+     }
 
-       // Implement |copy| using |pump|.
-       // This implementation would require some work before being able to
-       // copy directories
-       File.copy = function copy(sourcePath, destPath, options) {
-         options = options || noOptions;
-         let source, dest;
-         let result;
-         try {
-           source = File.open(sourcePath);
-           if (options.noOverwrite) {
-             dest = File.open(destPath, {create:true});
-           } else {
-             dest = File.open(destPath, {write:true});
-           }
-           result = pump(source, dest, options);
-         } catch (x) {
-           if (dest) {
-             dest.close();
-           }
-           if (source) {
-             source.close();
-           }
-           throw x;
+     // Implement |copy| using |pump|.
+     // This implementation would require some work before being able to
+     // copy directories
+     File.copy = function copy(sourcePath, destPath, options) {
+       options = options || noOptions;
+       let source, dest;
+       let result;
+       try {
+         source = File.open(sourcePath);
+         if (options.noOverwrite) {
+           dest = File.open(destPath, {create:true});
+         } else {
+           dest = File.open(destPath, {write:true});
          }
-       };
-     } // End of definition of copy
+         result = pump(source, dest, options);
+       } catch (x) {
+         if (dest) {
+           dest.close();
+         }
+         if (source) {
+           source.close();
+         }
+         throw x;
+       }
+     };
 
      // Implement |move| using |rename| (wherever possible) or |copy|
      // (if files are on distinct devices).
      File.move = function move(sourcePath, destPath, options) {
        // An implementation using |rename| whenever possible or
        // |File.pump| when required, for other Unices.
        // It can move directories on one file system, not
        // across file systems
@@ -519,21 +534,23 @@
          return;
 
        // If the error is not EXDEV ("not on the same device"),
        // throw it.
        if (ctypes.errno != Const.EXDEV) {
          throw new File.Error();
        }
 
-       // Otherwise, copy and remove.
-       File.copy(sourcePath, destPath, options);
-       // FIXME: Clean-up in case of copy error?
-       File.remove(sourcePath);
-     };
+         // Otherwise, copy and remove.
+         File.copy(sourcePath, destPath, options);
+         // FIXME: Clean-up in case of copy error?
+         File.remove(sourcePath);
+       };
+
+     } // End of definition of copy/move
 
      /**
       * Iterate on one directory.
       *
       * This iterator will not enter subdirectories.
       *
       * @param {string} path The directory upon which to iterate.
       * @param {*=} options Ignored in this implementation.
--- a/toolkit/components/osfile/osfile_win_back.jsm
+++ b/toolkit/components/osfile/osfile_win_back.jsm
@@ -76,17 +76,26 @@
          new Type("HANDLE",
                   ctypes.voidptr_t);
 
        /**
         * A C integer holding INVALID_HANDLE_VALUE in case of error or
         * a file descriptor in case of success.
         */
        Types.maybe_HANDLE =
-         Types.maybe_HANDLE.withName("maybe_find_HANDLE");
+         new Type("maybe_HANDLE",
+           Types.HANDLE.implementation,
+           function (maybe) {
+             if (ctypes.cast(maybe, ctypes.int).value == invalid_handle) {
+               // Ensure that API clients can effectively compare against
+               // Const.INVALID_HANDLE_VALUE. Without this cast,
+               // == would always return |false|.
+               return invalid_handle;
+             }
+             return ctypes.CDataFinalizer(maybe, _CloseHandle);
            });
 
        /**
         * A C integer holding INVALID_HANDLE_VALUE in case of error or
         * a file descriptor in case of success.
         */
        Types.maybe_find_HANDLE =
          new Type("maybe_find_HANDLE",
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
@@ -187,28 +187,19 @@ function test_move_file()
 
   ok(true, "test_move_file: Copy complete");
 
   // 2. Move
   OS.File.move(tmp_file_name, tmp2_file_name);
 
   ok(true, "test_move_file: Move complete");
 
-  // 3. Check that destination exists
+  // 3. Check
   compare_files("test_move_file", src_file_name, tmp2_file_name);
 
-  // 4. Check that original file does not exist anymore
-  let exn;
-  try {
-    OS.File.open(tmp_file_name);
-  } catch (x) {
-    exn = x;
-  }
-  ok(!!exn, "test_move_file: Original file has been removed");
-
   ok(true, "test_move_file: Cleaning up");
   OS.File.remove(tmp2_file_name);
 }
 
 
 function test_iter_dir()
 {
   ok(true, "test_iter_dir: Starting");