-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make errors in getEntry_ be passed to handler (if specified) #42
base: master
Are you sure you want to change the base?
Changes from all commits
d864255
d07ae63
b44477f
cfcd9bf
c7220c3
56f5a04
351d8a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,27 +295,33 @@ var Filer = new function() { | |
* @param {...string} var_args 1-2 paths to lookup and return entries for. | ||
* These can be paths or filesystem: URLs. | ||
*/ | ||
var getEntry_ = function(callback, var_args) { | ||
var srcStr = arguments[1]; | ||
var destStr = arguments[2]; | ||
var getEntry_ = function(callback, opt_errorHandler, var_args) { | ||
var srcStr = arguments[2]; | ||
var destStr = arguments[3]; | ||
|
||
var errorHandler = opt_errorHandler || function(e) { throw e; }; | ||
|
||
var onError = function(e) { | ||
var error; | ||
if (e.code == FileError.NOT_FOUND_ERR) { | ||
if (destStr) { | ||
throw new Error('"' + srcStr + '" or "' + destStr + | ||
error = new Error('"' + srcStr + '" or "' + destStr + | ||
'" does not exist.'); | ||
} else { | ||
throw new Error('"' + srcStr + '" does not exist.'); | ||
error = new Error('"' + srcStr + '" does not exist.'); | ||
} | ||
} else { | ||
throw new Error('Problem getting Entry for one or more paths.'); | ||
error = new Error('Problem getting Entry for one or more paths.'); | ||
} | ||
error.code = e.code; | ||
errorHandler(error); | ||
return; | ||
}; | ||
|
||
// Build a filesystem: URL manually if we need to. | ||
var src = pathToFsURL_(srcStr); | ||
|
||
if (arguments.length == 3) { | ||
if (arguments.length == 4) { | ||
var dest = pathToFsURL_(destStr); | ||
self.resolveLocalFileSystemURL(src, function(srcEntry) { | ||
self.resolveLocalFileSystemURL(dest, function(destEntry) { | ||
|
@@ -372,7 +378,7 @@ var Filer = new function() { | |
} else { | ||
srcEntry.copyTo(destDir, newName, opt_successCallback, opt_errorHandler); | ||
} | ||
}, src, dest); | ||
}, opt_errorHandler, src, dest); | ||
} | ||
} | ||
|
||
|
@@ -479,13 +485,13 @@ var Filer = new function() { | |
|
||
var callback = function(dirEntry) { | ||
|
||
cwd_ = dirEntry; | ||
//cwd_ = dirEntry; | ||
|
||
// Read contents of current working directory. According to spec, need to | ||
// keep calling readEntries() until length of result array is 0. We're | ||
// guarenteed the same entry won't be returned again. | ||
var entries_ = []; | ||
var reader = cwd_.createReader(); | ||
var reader = dirEntry.createReader(); | ||
|
||
var readEntries = function() { | ||
reader.readEntries(function(results) { | ||
|
@@ -508,7 +514,7 @@ var Filer = new function() { | |
if (dirEntryOrPath.isDirectory) { // passed a DirectoryEntry. | ||
callback(dirEntryOrPath); | ||
} else if (isFsURL_(dirEntryOrPath)) { // passed a filesystem URL. | ||
getEntry_(callback, pathToFsURL_(dirEntryOrPath)); | ||
getEntry_(callback, opt_errorHandler, pathToFsURL_(dirEntryOrPath)); | ||
} else { // Passed a path. Look up DirectoryEntry and proceeed. | ||
// TODO: Find way to use getEntry_(callback, dirEntryOrPath); with cwd_. | ||
cwd_.getDirectory(dirEntryOrPath, {}, callback, opt_errorHandler); | ||
|
@@ -542,7 +548,6 @@ var Filer = new function() { | |
if (folders[0] == '.' || folders[0] == '') { | ||
folders = folders.slice(1); | ||
} | ||
|
||
rootDir.getDirectory(folders[0], {create: true, exclusive: exclusive}, | ||
function (dirEntry) { | ||
if (dirEntry.isDirectory) { // TODO: check shouldn't be necessary. | ||
|
@@ -564,13 +569,11 @@ var Filer = new function() { | |
} | ||
}, | ||
function(e) { | ||
if (e.code == FileError.INVALID_MODIFICATION_ERR) { | ||
e.message = "'" + path + "' already exists"; | ||
if (opt_errorHandler) { | ||
opt_errorHandler(e); | ||
} else { | ||
throw e; | ||
} | ||
e.message = e.message || "'" + path + "' already exists"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still want a check for |
||
if (opt_errorHandler) { | ||
opt_errorHandler(e); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
); | ||
|
@@ -597,10 +600,26 @@ var Filer = new function() { | |
} else { | ||
getEntry_(function(fileEntry) { | ||
fileEntry.file(successCallback, opt_errorHandler); | ||
}, pathToFsURL_(entryOrPath)); | ||
}, opt_errorHandler, pathToFsURL_(entryOrPath)); | ||
} | ||
}; | ||
|
||
/** | ||
* Looks up a FileEntry or DirectoryEntry for a given path. | ||
* | ||
* @param {function(...FileEntry|DirectorEntry)} callback A callback to be | ||
* passed the entry/entries that were fetched. The ordering of the | ||
* entries passed to the callback correspond to the same order passed | ||
* to this method. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Filer.prototype.getEntry = function(path, successCallback, opt_errorHandler) { | ||
if (!fs_) { | ||
throw new Error(FS_INIT_ERROR_MSG); | ||
} | ||
|
||
getEntry_(successCallback, opt_errorHandler, pathToFsURL_(path)); | ||
}; | ||
|
||
/** | ||
* Creates an empty file. | ||
* | ||
|
@@ -681,7 +700,7 @@ var Filer = new function() { | |
if (entryOrPath.isFile || entryOrPath.isDirectory) { | ||
removeIt(entryOrPath); | ||
} else { | ||
getEntry_(removeIt, entryOrPath); | ||
getEntry_(removeIt, opt_errorHandler, entryOrPath); | ||
} | ||
}; | ||
|
||
|
@@ -720,7 +739,7 @@ var Filer = new function() { | |
throw e; | ||
} | ||
} | ||
}, dirEntryOrPath); | ||
}, opt_errorHandler, dirEntryOrPath); | ||
} | ||
}; | ||
|
||
|
@@ -802,7 +821,7 @@ var Filer = new function() { | |
if (entryOrPath.isFile) { | ||
writeFile_(entryOrPath); | ||
} else if (isFsURL_(entryOrPath)) { | ||
getEntry_(writeFile_, entryOrPath); | ||
getEntry_(writeFile_, opt_errorHandler, entryOrPath); | ||
} else { | ||
cwd_.getFile(entryOrPath, {create: true, exclusive: false}, writeFile_, | ||
opt_errorHandler); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?