Commit 769532b2 authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

Fix restoring after a crash.

When opened selected a USB volume in Files app, and crashed, the Files app is tried to be restored with the previous path. However, the volume may not yet be available. In such case, parent is considered. However, parent is /removable, which resolving causes an error, resulting in throwing an exception and going into a wrong state.

In such situation, we should fallback, and this is what this patch does. If the parent is not resolvable, then the fallback is used as the next current directory instead.

Moreover, after recent refactoring a regression has been introduced. When resolving a parent of the initial directory fails, then a wrong variable name was used, what caused a JS error.

TEST=Tested manually on Pixel.
BUG=331587

Review URL: https://codereview.chromium.org/124933002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243538 0039d316-1c4b-4281-b951-d872f2087c98
parent a29eb756
......@@ -1488,7 +1488,7 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
}
if (candidateEntry) {
// The entry is directry. Use it.
// The entry is directory. Use it.
if (candidateEntry.isDirectory) {
nextCurrentDirEntry = candidateEntry;
callback();
......@@ -1509,19 +1509,40 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
}
// If the entry doesn't exist, most probably because the path contains a
// suggested name. Therefore try to open its parent.
// suggested name. Therefore try to open its parent. However, the parent
// may also not exist. In such situation, fallback.
var pathNodes = candidateFullPath.split('/');
suggestedName = pathNodes.pop();
var baseName = pathNodes.pop();
var parentPath = pathNodes.join('/');
this.volumeManager_.resolveAbsolutePath(
parentPath,
function(parentEntry) {
nextCurrentDirEntry = parentEntry;
suggestedName = baseName;
callback();
},
callback); // In case of an error, continue.
}.bind(this));
// If the directory is not set at this stage, fallback to the default
// mount point.
queue.run(function(callback) {
// Cancel this sequence if the current directory has already changed,
// or the next current directory is already set.
if (tracker.hasChanged || nextCurrentDirEntry) {
callback();
return;
}
this.volumeManager_.resolveAbsolutePath(
PathUtil.DEFAULT_MOUNT_POINT,
function(fallbackEntry) {
nextCurrentDirEntry = fallbackEntry;
callback();
},
function() {
error = new Error('Failed to setup an initial directory: ' +
nextCurrentDirPath);
// Fallback directory not available? Throw an error.
error = new Error('Unable to resolve the fallback directory: ' +
PathUtil.DEFAULT_MOUNT_POINT);
callback();
});
}.bind(this));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment