Implement nsIFile::IsHidden without FSRefs on Mac OS X. Fixes failures on virtual file system objects. b=491688 r=bsmedberg

This commit is contained in:
Josh Aas 2009-11-02 16:15:40 -05:00
parent c5f31ac9ac
commit 278c4c6e2e
2 changed files with 50 additions and 19 deletions

View File

@ -1038,30 +1038,23 @@ NS_IMETHODIMP nsLocalFile::IsHidden(PRBool *_retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
CHECK_INIT();
NS_ENSURE_ARG_POINTER(_retval);
*_retval = PR_FALSE;
FSRef fsRef;
nsresult rv = GetFSRefInternal(fsRef);
// If the leaf name begins with a '.', consider it invisible
nsAutoString name;
nsresult rv = GetLeafName(name);
if (NS_FAILED(rv))
return rv;
FSCatalogInfo catalogInfo;
HFSUniStr255 leafName;
OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catalogInfo,
&leafName, nsnull, nsnull);
if (err != noErr)
return MacErrorMapper(err);
FileInfo *fInfoPtr = (FileInfo *)(catalogInfo.finderInfo); // Finder flags are in the same place whether we use FileInfo or FolderInfo
if ((fInfoPtr->finderFlags & kIsInvisible) != 0) {
if (name.Length() >= 1 && Substring(name, 0, 1).EqualsLiteral("."))
*_retval = PR_TRUE;
}
else {
// If the leaf name begins with a '.', consider it invisible
if (leafName.length >= 1 && leafName.unicode[0] == UniChar('.'))
*_retval = PR_TRUE;
}
LSItemInfoRecord itemInfo;
LSCopyItemInfoForURL(mBaseURL, kLSRequestBasicFlagsOnly, &itemInfo);
*_retval = !!(itemInfo.flags & kLSItemInfoIsInvisible);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;

View File

@ -0,0 +1,38 @@
const Ci = Components.interfaces;
const Cc = Components.classes;
const NS_OS_TEMP_DIR = "TmpD";
const CWD = do_get_cwd();
function checkOS(os) {
const nsILocalFile_ = "nsILocalFile" + os;
return nsILocalFile_ in Components.interfaces &&
CWD instanceof Components.interfaces[nsILocalFile_];
}
const isWin = checkOS("Win");
const isOS2 = checkOS("OS2");
const isMac = checkOS("Mac");
const isUnix = !(isWin || isOS2 || isMac);
var hiddenUnixFile;
function createUNIXHiddenFile() {
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var tmpDir = dirSvc.get(NS_OS_TEMP_DIR, Ci.nsIFile);
hiddenUnixFile = tmpDir.clone();
hiddenUnixFile.append(".foo");
// we don't care if this already exists because we don't care
// about the file's contents (just the name)
if (!hiddenUnixFile.exists())
hiddenUnixFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
return hiddenUnixFile.exists();
}
function run_test() {
// Skip this test on Windows
if (isWin || isOS2)
return;
do_check_true(createUNIXHiddenFile());
do_check_true(hiddenUnixFile.isHidden());
}