mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
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:
parent
e6a700a873
commit
7fdeac46a5
@ -312,10 +312,14 @@ nsFileChannel::MakeFileInputStream(nsIFile *file,
|
||||
bool isDir;
|
||||
nsresult rv = file->IsDirectory(&isDir);
|
||||
if (NS_FAILED(rv)) {
|
||||
// canonicalize error message
|
||||
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
|
||||
rv = NS_ERROR_FILE_NOT_FOUND;
|
||||
return rv;
|
||||
if (NS_ERROR_FILE_NOT_FOUND == rv ||
|
||||
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDir) {
|
||||
@ -323,7 +327,8 @@ nsFileChannel::MakeFileInputStream(nsIFile *file,
|
||||
if (NS_SUCCEEDED(rv) && !HasContentTypeHint())
|
||||
contentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
|
||||
} 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()) {
|
||||
// Use file extension to infer content type
|
||||
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv);
|
||||
@ -407,8 +412,14 @@ nsFileChannel::OpenContentStream(bool async, nsIInputStream **result,
|
||||
if (ContentLength64() < 0) {
|
||||
PRInt64 size;
|
||||
rv = file->GetFileSize(&size);
|
||||
if (NS_FAILED(rv))
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
SetContentLength64(size);
|
||||
}
|
||||
if (!contentType.IsEmpty())
|
||||
|
Loading…
Reference in New Issue
Block a user