Bug 282432 - Calling asyncOpen on a file channel should notify about file not found errors asynchronously instead of throwing from asyncOpen. r=bz

This commit is contained in:
Oonishi Atsushi 2012-05-09 18:46:12 -04:00
parent 95e442c979
commit e68c211c17

View File

@ -312,18 +312,23 @@ nsFileChannel::MakeFileInputStream(nsIFile *file,
bool isDir; bool isDir;
nsresult rv = file->IsDirectory(&isDir); nsresult rv = file->IsDirectory(&isDir);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
// canonicalize error message if (NS_ERROR_FILE_NOT_FOUND == rv ||
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv) {
rv = NS_ERROR_FILE_NOT_FOUND; // We don't return "Not Found" errors here. Since we could not find
// the file, it's not a directory anyway.
isDir = false;
} else {
return rv; return rv;
} }
}
if (isDir) { if (isDir) {
rv = nsDirectoryIndexStream::Create(file, getter_AddRefs(stream)); rv = nsDirectoryIndexStream::Create(file, getter_AddRefs(stream));
if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) if (NS_SUCCEEDED(rv) && !HasContentTypeHint())
contentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT); contentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
} else { } else {
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file); rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file, -1, -1,
nsIFileInputStream::DEFER_OPEN);
if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) { if (NS_SUCCEEDED(rv) && !HasContentTypeHint()) {
// Use file extension to infer content type // Use file extension to infer content type
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv); nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv);
@ -407,8 +412,14 @@ nsFileChannel::OpenContentStream(bool async, nsIInputStream **result,
if (ContentLength64() < 0) { if (ContentLength64() < 0) {
PRInt64 size; PRInt64 size;
rv = file->GetFileSize(&size); rv = file->GetFileSize(&size);
if (NS_FAILED(rv)) if (NS_FAILED(rv)) {
if (NS_ERROR_FILE_NOT_FOUND == rv ||
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv) {
size = 0;
} else {
return rv; return rv;
}
}
SetContentLength64(size); SetContentLength64(size);
} }
if (!contentType.IsEmpty()) if (!contentType.IsEmpty())