From 152baeb1b34fed636b666a7bf64c184961569976 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Fri, 8 Nov 2002 15:03:06 +0000 Subject: [PATCH] Bug 177059 Mach-0 nsLocalFile::GetFileSize sometimes fails for directories. Patch by sfraser. r=ccarlen/sr=bryner git-svn-id: svn://10.0.0.236/trunk@133401 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsLocalFileOSX.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mozilla/xpcom/io/nsLocalFileOSX.cpp b/mozilla/xpcom/io/nsLocalFileOSX.cpp index 61508ba0f9e..2eba958bfe5 100644 --- a/mozilla/xpcom/io/nsLocalFileOSX.cpp +++ b/mozilla/xpcom/io/nsLocalFileOSX.cpp @@ -766,6 +766,7 @@ NS_IMETHODIMP nsLocalFile::SetLastModifiedTimeOfLink(PRInt64 aLastModifiedTimeOf NS_IMETHODIMP nsLocalFile::GetFileSize(PRInt64 *aFileSize) { NS_ENSURE_ARG_POINTER(aFileSize); + *aFileSize = 0; FSRef fsRef; nsresult rv = GetFSRefInternal(fsRef); @@ -773,12 +774,15 @@ NS_IMETHODIMP nsLocalFile::GetFileSize(PRInt64 *aFileSize) return rv; FSCatalogInfo catalogInfo; - OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoDataSizes, &catalogInfo, + OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags + kFSCatInfoDataSizes, &catalogInfo, nsnull, nsnull, nsnull); if (err != noErr) return MacErrorMapper(err); - - *aFileSize = catalogInfo.dataLogicalSize; + + // FSGetCatalogInfo can return a bogus size for directories sometimes, so only + // rely on the answer for files + if ((catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0) + *aFileSize = catalogInfo.dataLogicalSize; return NS_OK; }