From add5fc9aaddc76da39cfbcd5afec29d3b6aed373 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Wed, 30 Jan 2002 23:53:12 +0000 Subject: [PATCH] Fix bug # 122571: add ability to determine if a directory is actually a package (for Mac OS 9/X) r=ccarlen sr=ben git-svn-id: svn://10.0.0.236/trunk@113252 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsILocalFileMac.idl | 7 ++++++ mozilla/xpcom/io/nsLocalFileMac.cpp | 35 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/mozilla/xpcom/io/nsILocalFileMac.idl b/mozilla/xpcom/io/nsILocalFileMac.idl index d1a4b7507bd..e0640bc767d 100644 --- a/mozilla/xpcom/io/nsILocalFileMac.idl +++ b/mozilla/xpcom/io/nsILocalFileMac.idl @@ -158,6 +158,13 @@ interface nsILocalFileMac : nsILocalFile */ void openDocWithApp(in nsILocalFile aAppToOpenWith, in boolean aLaunchInBackground); + /** + * isPackage + * + * returns true if a directory is determined to be a package under Mac OS 9/X + * + */ + boolean isPackage(); }; %{C++ diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index f730ac4abbd..294cfd5411c 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -2059,6 +2059,41 @@ nsLocalFile::Exists(PRBool *_retval) return NS_OK; } +NS_IMETHODIMP +nsLocalFile::IsPackage(PRBool *outIsPackage) +{ + NS_ENSURE_ARG(outIsPackage); + *outIsPackage = PR_FALSE; + + // Note: IsDirectory() calls ResolveAndStat() & UpdateCachedCatInfo + PRBool isDir; + nsresult rv = IsDirectory(&isDir); + if (NS_FAILED(rv)) return rv; + + *outIsPackage = ((mCachedCatInfo.dirInfo.ioFlAttrib & kioFlAttribDirMask) && + (mCachedCatInfo.dirInfo.ioDrUsrWds.frFlags & kHasBundle)); + + if ((!*outIsPackage) && isDir) + { + // Believe it or not, folders ending with ".app" are also considered + // to be packages, even if the top-level folder doesn't have bundle set + nsXPIDLCString name; + if (NS_SUCCEEDED(rv = GetLeafName(getter_Copies(name)))) + { + const char *extPtr = strrchr(name, '.'); + if (extPtr) + { + if (!nsCRT::strcasecmp(extPtr, ".app")) + { + *outIsPackage = PR_TRUE; + } + } + } + } + + return NS_OK; +} + NS_IMETHODIMP nsLocalFile::IsWritable(PRBool *outIsWritable) {