Bug 895025 - Unable to import bookmarks from IE when they contain a .lnk to a folder. r=mak a=sylvestre
authorRui You <ryou@mozilla.com>
Fri, 24 Jan 2014 18:41:08 +0800
changeset 182689 4a2daed7e4cd830c3d48e5169d3432c5cfb8c71d
parent 182688 3a65ec0ec32439002894174bfa7ee36c95c8f09b
child 182690 f7b84245670d99e9ffb81d1a3467f90bdb74de3d
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, sylvestre
bugs895025
milestone29.0a2
Bug 895025 - Unable to import bookmarks from IE when they contain a .lnk to a folder. r=mak a=sylvestre
browser/components/migration/src/IEProfileMigrator.js
--- a/browser/components/migration/src/IEProfileMigrator.js
+++ b/browser/components/migration/src/IEProfileMigrator.js
@@ -219,57 +219,62 @@ Bookmarks.prototype = {
 
   _migrateFolder: function B__migrateFolder(aSourceFolder, aDestFolderId) {
     // TODO (bug 741993): the favorites order is stored in the Registry, at
     // HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites
     // Until we support it, bookmarks are imported in alphabetical order.
     let entries = aSourceFolder.directoryEntries;
     while (entries.hasMoreElements()) {
       let entry = entries.getNext().QueryInterface(Ci.nsIFile);
+      try {
+        // Make sure that entry.path == entry.target to not follow .lnk folder
+        // shortcuts which could lead to infinite cycles.
+        // Don't use isSymlink(), since it would throw for invalid
+        // lnk files pointing to URLs or to unresolvable paths.
+        if (entry.path == entry.target && entry.isDirectory()) {
+          let destFolderId;
+          if (entry.leafName == this._toolbarFolderName &&
+              entry.parent.equals(this._favoritesFolder)) {
+            // Import to the bookmarks toolbar.
+            destFolderId = PlacesUtils.toolbarFolderId;
+            if (!MigrationUtils.isStartupMigration) {
+              destFolderId =
+                MigrationUtils.createImportedBookmarksFolder("IE", destFolderId);
+            }
+          }
+          else {
+            // Import to a new folder.
+            destFolderId =
+              PlacesUtils.bookmarks.createFolder(aDestFolderId, entry.leafName,
+                                                 PlacesUtils.bookmarks.DEFAULT_INDEX);
+          }
 
-      // Make sure that entry.path == entry.target to not follow .lnk folder
-      // shortcuts which could lead to infinite cycles.
-      if (entry.isDirectory() && entry.path == entry.target) {
-        let destFolderId;
-        if (entry.leafName == this._toolbarFolderName &&
-            entry.parent.equals(this._favoritesFolder)) {
-          // Import to the bookmarks toolbar.
-          destFolderId = PlacesUtils.toolbarFolderId;
-          if (!MigrationUtils.isStartupMigration) {
-            destFolderId =
-              MigrationUtils.createImportedBookmarksFolder("IE", destFolderId);
+          if (entry.isReadable()) {
+            // Recursively import the folder.
+            this._migrateFolder(entry, destFolderId);
           }
         }
         else {
-          // Import to a new folder.
-          destFolderId =
-            PlacesUtils.bookmarks.createFolder(aDestFolderId, entry.leafName,
-                                               PlacesUtils.bookmarks.DEFAULT_INDEX);
-        }
+          // Strip the .url extension, to both check this is a valid link file,
+          // and get the associated title.
+          let matches = entry.leafName.match(/(.+)\.url$/i);
+          if (matches) {
+            let fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].
+                              getService(Ci.nsIFileProtocolHandler);
+            let uri = fileHandler.readURLFile(entry);
+            let title = matches[1];
 
-        if (entry.isReadable()) {
-          // Recursively import the folder.
-          this._migrateFolder(entry, destFolderId);
+            PlacesUtils.bookmarks.insertBookmark(aDestFolderId,
+                                                 uri,
+                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
+                                                 title);
+          }
         }
-      }
-      else {
-        // Strip the .url extension, to both check this is a valid link file,
-        // and get the associated title.
-        let matches = entry.leafName.match(/(.+)\.url$/i);
-        if (matches) {
-          let fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].
-                            getService(Ci.nsIFileProtocolHandler);
-          let uri = fileHandler.readURLFile(entry);
-          let title = matches[1];
-
-          PlacesUtils.bookmarks.insertBookmark(aDestFolderId,
-                                               uri,
-                                               PlacesUtils.bookmarks.DEFAULT_INDEX,
-                                               title);
-        }
+      } catch (ex) {
+        Components.utils.reportError("Unable to import IE favorite (" + entry.leafName + "): " + ex);
       }
     }
   }
 };
 
 function History() {
 }