Bug 1450154: Clone file objects before checking lastModifiedTime. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 29 Mar 2018 17:23:14 -0700
changeset 775102 e7513ed056434f7bd9120ae16b166415769aee0f
parent 775082 7fdb14ac881161d8dc429460d0aa373f4bbd9f39
child 775105 5479f783fead20223aa61581055b5809bbe10529
child 775106 e77a95724850975bf23fc4266ac560dc87027ff8
push id104603
push usermaglione.k@gmail.com
push dateFri, 30 Mar 2018 00:38:48 +0000
reviewersaswan
bugs1450154
milestone61.0a1
Bug 1450154: Clone file objects before checking lastModifiedTime. r?aswan MozReview-Commit-ID: CnIT0bqUaPZ
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_install.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -364,17 +364,19 @@ function getFile(path, base = null) {
  *
  * @param {nsIFile} file
  *        The file to retrieve the modification time for.
  * @returns {double}
  *        The file's modification time, in seconds since the Unix epoch.
  */
 function tryGetMtime(file) {
   try {
-    return file.lastModifiedTime;
+    // Clone the file object so we always get the actual mtime, rather
+    // than whatever value it may have cached.
+    return file.clone().lastModifiedTime;
   } catch (e) {
     return 0;
   }
 }
 
 /**
  * Returns the path to `file` relative to the directory `dir`, or an
  * absolute path to the file if no directory is passed, or the file is
--- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js
@@ -423,22 +423,18 @@ add_task(async function test_4() {
   notEqual(a2, null);
   equal(a2.type, "extension");
   equal(a2.version, "3.0");
   equal(a2.name, "Real Test 3");
   ok(a2.isActive);
   ok(isExtensionInBootstrappedList(profileDir, a2.id));
   ok(XPIS.test_install2_2.exists());
   do_check_in_crash_annotation(a2.id, a2.version);
-  // Windows currently has timing issues, and sees the add-on as changed
-  // after restart.
-  if (AppConstants.platform !== "win") {
-    equal(a2.sourceURI.spec,
-          "http://example.com/addons/test_install2_2.xpi");
-  }
+  equal(a2.sourceURI.spec,
+        "http://example.com/addons/test_install2_2.xpi");
   ok(!a2.foreignInstall);
 
   equal(a2.installDate.getTime(), gInstallDate);
   // Update date should be later (or the same if this test is too fast)
   ok(a2.installDate <= a2.updateDate);
 
   a2.uninstall();
 });