From 4ea79344a03bbcd28cac781d1ca1fe913884ccf5 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Wed, 25 Sep 2002 12:23:39 +0000 Subject: [PATCH] Bug 118203 - nsLocalFile implementation for Mach-0. r=pinkerton, sdagley/sr=sfraser git-svn-id: svn://10.0.0.236/trunk@130418 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/lib/mac/MoreFiles/Makefile.in | 24 +-- mozilla/modules/libreg/src/reg.c | 130 +++++++++++++-- mozilla/modules/libreg/src/vr_stubs.c | 134 +++++++++++++--- mozilla/modules/libreg/src/vr_stubs.h | 2 +- mozilla/profile/src/nsProfileAccess.cpp | 14 +- mozilla/xpcom/io/Makefile.in | 25 +-- .../xpcom/io/nsAppFileLocationProvider.cpp | 34 ++-- mozilla/xpcom/io/nsDirectoryService.cpp | 150 +++++++++++++----- mozilla/xpcom/io/nsDirectoryService.h | 5 +- mozilla/xpcom/io/nsDirectoryServiceDefs.h | 16 +- mozilla/xpcom/io/nsILocalFileMac.idl | 58 ++++++- mozilla/xpcom/io/nsLocalFile.h | 6 +- mozilla/xpcom/io/nsLocalFileCommon.cpp | 12 +- mozilla/xpcom/io/nsLocalFileMac.cpp | 94 ++++++++++- mozilla/xpinstall/src/nsInstallFolder.cpp | 2 +- 15 files changed, 550 insertions(+), 156 deletions(-) diff --git a/mozilla/lib/mac/MoreFiles/Makefile.in b/mozilla/lib/mac/MoreFiles/Makefile.in index 1ba4600b11b..ea491bf4013 100644 --- a/mozilla/lib/mac/MoreFiles/Makefile.in +++ b/mozilla/lib/mac/MoreFiles/Makefile.in @@ -35,29 +35,13 @@ LIBRARY_NAME = macmorefiles_s REQUIRES = CSRCS = \ - DirectoryCopy.c \ - FileCopy.c \ - FSpCompat.c \ - FullPath.c \ - IterateDirectory.c \ - MoreDesktopMgr.c \ - MoreFiles.c \ - MoreFilesExtras.c \ - MoreFilesSearch.c \ + MoreFilesX.c \ + FSCopyObject.c \ $(NULL) EXPORTS += \ - DirectoryCopy.h \ - FileCopy.h \ - FSpCompat.h \ - FullPath.h \ - IterateDirectory.h \ - MoreDesktopMgr.h \ - MoreFiles.h \ - MoreFilesExtras.h \ - MoreFilesSearch.h \ - Optimization.h \ - OptimizationEnd.h \ + MoreFilesX.h \ + FSCopyObject.h \ $(NULL) # we don't want the shared lib, but we want to force the creation of a diff --git a/mozilla/modules/libreg/src/reg.c b/mozilla/modules/libreg/src/reg.c index 5a2f767853f..8d5c2124725 100644 --- a/mozilla/modules/libreg/src/reg.c +++ b/mozilla/modules/libreg/src/reg.c @@ -74,8 +74,10 @@ #include "reg.h" #include "NSReg.h" -#if defined(XP_MAC) || defined(XP_MACOSX) +#if defined(XP_MAC) #define MAX_PATH 512 +#elif defined(XP_MACOSX) +#define MAX_PATH PATH_MAX #elif defined(XP_UNIX) #ifndef MAX_PATH #define MAX_PATH 1024 @@ -150,7 +152,74 @@ char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength); #include #include #include -#include "FullPath.h" + +#ifdef XP_MACOSX + #include "MoreFilesX.h" +#else + #include "FullPath.h" +#endif + +static void copyCStringToPascal(Str255 dest, const char *src) +{ + size_t copyLen = strlen(src); + if (copyLen > 255) + copyLen = 255; + BlockMoveData(src, &dest[1], copyLen); + dest[0] = copyLen; +} + +#ifdef XP_MACOSX +static OSErr isFileInTrash(FSRef *fsRef, PRBool *inTrash) +{ + OSErr err; + FSCatalogInfo catalogInfo; + + if (fsRef == NULL || inTrash == NULL) + return paramErr; + *inTrash = PR_FALSE; + + err = FSGetCatalogInfo(fsRef, kFSCatInfoVolume, &catalogInfo, NULL, NULL, NULL); + if (err == noErr) + { + FSRef trashFSRef, currFSRef, parentFSRef; + err = FSFindFolder(catalogInfo.volume, kTrashFolderType, false, &trashFSRef); + if (err == noErr) + { + /* FSRefGetParentRef returns noErr and a zeroed FSRef when it reaches the top */ + for (currFSRef = *fsRef; + (FSGetParentRef(&currFSRef, &parentFSRef) == noErr && FSRefValid(&parentFSRef)); + currFSRef = parentFSRef) + { + if (FSCompareFSRefs(&parentFSRef, &trashFSRef) == noErr) + { + *inTrash = PR_TRUE; + break; + } + } + } + } + return err; +} +#else +static OSErr isFileInTrash(FSSpec *fileSpec, PRBool *inTrash) +{ + OSErr err; + short vRefNum; + long dirID; + + if (fileSpec == NULL || inTrash == NULL) + return paramErr; + *inTrash = PR_FALSE; + + /* XXX - Only works if the file is in the top level of the trash dir */ + err = FindFolder(fileSpec->vRefNum, kTrashFolderType, false, &vRefNum, &dirID); + if (err == noErr) + if (dirID == fileSpec->parID) /* File is inside the trash */ + *inTrash = PR_TRUE; + + return err; +} +#endif /* returns an alias as a malloc'd pointer. * On failure, *alias is NULL @@ -158,16 +227,26 @@ char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength); void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length) { OSErr err; + Str255 pascalName; + FSRef fsRef; FSSpec fs; AliasHandle macAlias; *alias = NULL; *length = 0; - c2pstr((char*)fileName); - err = FSMakeFSSpec(0, 0, (unsigned char *)fileName, &fs); - p2cstr((unsigned char *)fileName); + +#ifdef XP_MACOSX + err = FSPathMakeRef((const UInt8*)fileName, &fsRef, NULL); + if ( err != noErr ) + return; + err = FSNewAlias(NULL, &fsRef, &macAlias); +#else + copyCStringToPascal(pascalName, fileName); + err = FSMakeFSSpec(0, 0, pascalName, &fs); if ( err != noErr ) return; err = NewAlias(NULL, &fs, &macAlias); +#endif + if ( (err != noErr) || ( macAlias == NULL )) return; *length = GetHandleSize( (Handle) macAlias ); @@ -190,14 +269,16 @@ void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length) char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength) { OSErr err; - short vRefNum; - long dirID; AliasHandle h = NULL; Handle fullPath = NULL; short fullPathLength; char * cpath = NULL; + PRBool inTrash; + FSRef fsRef; + FSCatalogInfo catalogInfo; + UInt8 pathBuf[MAX_PATH]; FSSpec fs; - Boolean ignore; /* Change flag, it would be nice to change the alias on disk + Boolean wasChanged; /* Change flag, it would be nice to change the alias on disk if the file location changed */ @@ -214,17 +295,32 @@ char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength) XP_MEMCPY( *h, alias, aliasLength ); HUnlock( (Handle) h); - - err = ResolveAlias(NULL, h, &fs, &ignore); +#ifdef XP_MACOSX + err = FSResolveAlias(NULL, h, &fsRef, &wasChanged); + if (err != noErr) + goto fail; + + /* if the alias has changed and the file is now in the trash, + assume that user has deleted it and that we do not want to look at it */ + if (wasChanged && (isFileInTrash(&fsRef, &inTrash) == noErr) && inTrash) + goto fail; + err = FSRefMakePath(&fsRef, pathBuf, sizeof(pathBuf)); + if (err != noErr) + goto fail; + fullPathLength = XP_STRLEN(pathBuf); + cpath = (char*) XP_ALLOC(fullPathLength + 1); + if ( cpath == NULL) + goto fail; + XP_MEMCPY(cpath, pathBuf, fullPathLength + 1); +#else + err = ResolveAlias(NULL, h, &fs, &wasChanged); if (err != noErr) goto fail; - /* if the file is inside the trash, assume that user has deleted - it and that we do not want to look at it */ - err = FindFolder(fs.vRefNum, kTrashFolderType, false, &vRefNum, &dirID); - if (err == noErr) - if (dirID == fs.parID) /* File is inside the trash */ - goto fail; + /* if the alias has changed and the file is now in the trash, + assume that user has deleted it and that we do not want to look at it */ + if (wasChanged && (isFileInTrash(&fs, &inTrash) == noErr) && inTrash) + goto fail; /* Get the full path and create a char * out of it */ @@ -240,7 +336,7 @@ char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength) XP_MEMCPY(cpath, *fullPath, fullPathLength); cpath[fullPathLength] = 0; HUnlock( fullPath ); - +#endif /* Drop through */ fail: if (h != NULL) diff --git a/mozilla/modules/libreg/src/vr_stubs.c b/mozilla/modules/libreg/src/vr_stubs.c index fea0411ae76..0266bacc18f 100644 --- a/mozilla/modules/libreg/src/vr_stubs.c +++ b/mozilla/modules/libreg/src/vr_stubs.c @@ -53,7 +53,7 @@ #include "vr_stubs.h" -#if defined(XP_MAC) || defined(XP_MACOSX) +#if defined(XP_MAC) #include #include #include @@ -62,10 +62,27 @@ #include "FullPath.h" /* For FSpLocationFromFullPath() */ #endif +#if defined(XP_MACOSX) +#include +#include +#endif + #ifdef XP_BEOS #include #endif +#ifdef XP_MACOSX +/* So that we're not dependent on the size of chars in a wide string literal */ +static const UniChar kOSXRegParentName[] = + { 'M', 'o', 'z', 'i', 'l', 'l', 'a' }; +static const UniChar kOSXRegName[] = + { 'G', 'l', 'o', 'b', 'a', 'l', '.', 'r', 'e', 'g', 's' }; +static const UniChar kOSXVersRegName[] = + { 'V', 'e', 'r', 's', 'i', 'o', 'n', 's', '.', 'r', 'e', 'g', 's' }; + +#define UNICHAR_ARRAY_LEN(s) (sizeof(s) / sizeof(UniChar)) +#endif + #define DEF_REG "/.mozilla/registry" #define WIN_REG "\\mozregistry.dat" #define MAC_REG "\pMozilla Registry" @@ -215,51 +232,71 @@ int FAR PASCAL _export WEP(int nParam) #if defined(XP_MAC) || defined(XP_MACOSX) #include -#include "FullPath.h" #ifdef STANDALONE_REGISTRY extern XP_File vr_fileOpen(const char *name, const char * mode) { XP_File fh = NULL; struct stat st; - OSErr anErr; - FSSpec newFSSpec; #ifdef STANDALONE_REGISTRY errno = 0; /* reset errno (only if we're using stdio) */ #endif - anErr = FSpLocationFromFullPath(strlen(name), name, &newFSSpec); - - if (anErr == -43) - { - /* if file doesn't exist */ - anErr = FSpCreate(&newFSSpec, 'MOSS', 'REGS', smSystemScript); - } - else - { - /* there is not much to do here. if we got noErr, the file exists. If we did not get - noErr or -43, we are pretty hosed. - */ - } - if ( name != NULL ) { if ( stat( name, &st ) == 0 ) - fh = fopen( name, XP_FILE_UPDATE_BIN ); /* If/when we switch to MSL C Lib (gromit uses this), we might have to take out the Macro per bug #62382 */ + fh = fopen( name, XP_FILE_UPDATE_BIN ); else { /* should never get here! */ fh = fopen( name, XP_FILE_TRUNCATE_BIN ); } } -#ifdef STANDALONE_REGISTRY - if (anErr != noErr) - errno = anErr; -#endif return fh; } #endif /*STANDALONE_REGISTRY*/ +#if defined (XP_MACOSX) +extern void vr_findGlobalRegName() +{ + OSErr err; + FSRef foundRef; + + err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef); + if (err == noErr) + { + FSRef parentRef; + err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName, + kTextEncodingUnknown, &parentRef); + if (err == fnfErr) + { + err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName, + kFSCatInfoNone, NULL, &parentRef, NULL, NULL); + } + if (err == noErr) + { + FSRef regRef; + err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName, + kTextEncodingUnknown, ®Ref); + if (err == fnfErr) + { + FSCatalogInfo catalogInfo; + FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 }; + BlockMoveData(&fileInfo, &(catalogInfo.finderInfo), sizeof(FileInfo)); + err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName, + kFSCatInfoFinderInfo, &catalogInfo, ®Ref, NULL); + } + if (err == noErr) + { + UInt8 pathBuf[PATH_MAX]; + err = FSRefMakePath(®Ref, pathBuf, sizeof(pathBuf)); + if (err == noErr) + globalRegName = XP_STRDUP(pathBuf); + } + } + } +} +#else extern void vr_findGlobalRegName() { FSSpec regSpec; @@ -270,7 +307,7 @@ extern void vr_findGlobalRegName() err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID); - if (!err) + if (err == noErr) { err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_REG, ®Spec); @@ -314,7 +351,50 @@ extern void vr_findGlobalRegName() } } } +#endif /* XP_MACOSX */ +#ifdef XP_MACOSX +extern char* vr_findVerRegName() +{ + OSErr err; + FSRef foundRef; + + err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef); + if (err == noErr) + { + FSRef parentRef; + err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName, + kTextEncodingUnknown, &parentRef); + if (err == fnfErr) + { + err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName, + kFSCatInfoNone, NULL, &parentRef, NULL, NULL); + } + if (err == noErr) + { + FSRef regRef; + err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName, + kTextEncodingUnknown, ®Ref); + if (err == fnfErr) + { + FSCatalogInfo catalogInfo; + FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 }; + BlockMoveData(&fileInfo, &(catalogInfo.finderInfo), sizeof(FileInfo)); + err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName, + kFSCatInfoFinderInfo, &catalogInfo, ®Ref, NULL); + } + if (err == noErr) + { + UInt8 pathBuf[PATH_MAX]; + err = FSRefMakePath(®Ref, pathBuf, sizeof(pathBuf)); + if (err == noErr) + verRegName = XP_STRDUP(pathBuf); + } + } + } + return verRegName; +} +#else extern char* vr_findVerRegName() { FSSpec regSpec; @@ -329,7 +409,7 @@ extern char* vr_findVerRegName() err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID); - if (!err) + if (err == noErr) { err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_VERREG, ®Spec); @@ -375,11 +455,12 @@ extern char* vr_findVerRegName() return verRegName; } - +#endif /* OS_MACOSX */ /* Moves and renames a file or directory. Returns 0 on success, -1 on failure (errno contains mac error code). */ +#ifndef XP_MACOSX extern int nr_RenameFile(char *from, char *to) { OSErr err = -1; @@ -422,6 +503,7 @@ extern int nr_RenameFile(char *from, char *to) #endif return (err == noErr ? 0 : -1); } +#endif #ifdef STANDALONE_REGISTRY diff --git a/mozilla/modules/libreg/src/vr_stubs.h b/mozilla/modules/libreg/src/vr_stubs.h index 7c7fc242bb1..c67e3563654 100644 --- a/mozilla/modules/libreg/src/vr_stubs.h +++ b/mozilla/modules/libreg/src/vr_stubs.h @@ -272,7 +272,7 @@ typedef int XP_Bool; typedef struct stat XP_StatStruct; #define XP_Stat(file,data) stat((file),(data)) -#if defined(XP_MAC) || defined(XP_MACOSX) +#if defined(XP_MAC) extern int nr_RenameFile(char *from, char *to); #else XP_BEGIN_PROTOS diff --git a/mozilla/profile/src/nsProfileAccess.cpp b/mozilla/profile/src/nsProfileAccess.cpp index 24da8fdc96f..97c1d3c41c7 100644 --- a/mozilla/profile/src/nsProfileAccess.cpp +++ b/mozilla/profile/src/nsProfileAccess.cpp @@ -1022,7 +1022,7 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName, PRBool fromImport) rv = GetPlatformCharset(charSet); if (NS_FAILED(rv)) return rv; -#if defined(XP_PC) || defined(XP_MAC) +#if defined(XP_PC) || defined(XP_MAC) || defined(XP_MACOSX) NS_ASSERTION(registryName, "Invalid registryName"); nsCOMPtr registryFile; @@ -1069,7 +1069,7 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName, PRBool fromImport) // There is some problem I guess in sending a space as itself // NOTE: This needs to be done BEFORE the test for existence. -#if defined(XP_MAC) +#if defined(XP_MAC) || defined(XP_MACOSX) // 4.x profiles coming from japanese machine are already in unicode. // So, there is no need to decode into unicode further. NS_ConvertUCS2toUTF8 temp(profile); @@ -1361,7 +1361,7 @@ nsresult ProfileStruct::InternalizeLocation(nsIRegistry *aRegistry, nsRegistryKe if (NS_FAILED(rv)) return rv; regLocationData = profLoc; -#if defined(XP_MAC) +#if defined(XP_MAC) || defined(XP_MACOSX) // 4.x profiles coming from japanese machine are already in unicode. // So, there is no need to decode into unicode further. @@ -1395,7 +1395,7 @@ nsresult ProfileStruct::InternalizeLocation(nsIRegistry *aRegistry, nsRegistryKe if (NS_FAILED(rv)) return rv; regLocationData = regData; -#ifdef XP_MAC +#if defined(XP_MAC) || defined(XP_MACOSX) // For a brief time, this was a unicode path PRInt32 firstColon = regLocationData.FindChar(PRUnichar(':')); if (firstColon == -1) @@ -1427,7 +1427,7 @@ nsresult ProfileStruct::ExternalizeLocation(nsIRegistry *aRegistry, nsRegistryKe { nsAutoString regData; -#if XP_MAC +#if defined(XP_MAC) || defined(XP_MACOSX) PRBool leafCreated; nsCAutoString descBuf; @@ -1476,7 +1476,7 @@ nsresult ProfileStruct::InternalizeMigratedFromLocation(nsIRegistry *aRegistry, getter_Copies(regData)); if (NS_SUCCEEDED(rv)) { -#ifdef XP_MAC +#if defined(XP_MAC) || defined(XP_MACOSX) rv = NS_NewLocalFile(nsString(), PR_TRUE, getter_AddRefs(tempLocal)); if (NS_SUCCEEDED(rv)) { @@ -1501,7 +1501,7 @@ nsresult ProfileStruct::ExternalizeMigratedFromLocation(nsIRegistry *aRegistry, if (migratedFrom) { -#if XP_MAC +#if defined(XP_MAC) || defined(XP_MACOSX) rv = migratedFrom->GetPersistentDescriptor(regData); #else nsAutoString path; diff --git a/mozilla/xpcom/io/Makefile.in b/mozilla/xpcom/io/Makefile.in index d1670114a0e..86f4b8695a2 100644 --- a/mozilla/xpcom/io/Makefile.in +++ b/mozilla/xpcom/io/Makefile.in @@ -32,6 +32,10 @@ LIBRARY_NAME = xpcomio_s REQUIRES = string \ $(NULL) +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +REQUIRES += macmorefiles +endif + CPPSRCS = \ nsAppFileLocationProvider.cpp \ nsBinaryStream.cpp \ @@ -60,17 +64,16 @@ CPPSRCS = \ ifeq ($(MOZ_WIDGET_TOOLKIT),os2) CPPSRCS += nsLocalFileOS2.cpp -#else -#ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -#CPPSRCS += nsLocalFileMac.cpp -#CSRCS += macDirectoryCopy.c +else +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +CPPSRCS += nsLocalFileOSX.cpp else ifeq ($(MOZ_WIDGET_TOOLKIT),windows) CPPSRCS += nsLocalFileWin.cpp else CPPSRCS += nsLocalFileUnix.cpp endif # windows -#endif +endif # mac endif # OS2 EXPORTS = \ @@ -96,15 +99,15 @@ EXPORTS = \ ifeq ($(MOZ_WIDGET_TOOLKIT),os2) EXPORTS += nsLocalFileOS2.h else -#ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -#EXPORTS += nsLocalFileMac.h nsILocalFileMac.h -#else +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +EXPORTS += nsLocalFileOSX.h +else ifeq ($(MOZ_WIDGET_TOOLKIT),windows) EXPORTS += nsLocalFileWin.h else EXPORTS += nsLocalFileUnix.h endif # windows -#endif +endif # mac endif # os2 XPIDLSRCS = \ @@ -128,6 +131,10 @@ XPIDLSRCS = \ nsIObservableOutputStream.idl \ $(NULL) +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +XPIDLSRCS += nsILocalFileMac.idl +endif + SDK_XPIDLSRCS = \ nsIDirectoryService.idl \ nsIFile.idl \ diff --git a/mozilla/xpcom/io/nsAppFileLocationProvider.cpp b/mozilla/xpcom/io/nsAppFileLocationProvider.cpp index 035f28c4d4b..21771695af6 100755 --- a/mozilla/xpcom/io/nsAppFileLocationProvider.cpp +++ b/mozilla/xpcom/io/nsAppFileLocationProvider.cpp @@ -33,7 +33,7 @@ #include "prenv.h" #include "nsCRT.h" -#if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */ +#if defined(XP_MAC) || defined(XP_MACOSX) #include #include #include @@ -60,7 +60,7 @@ // WARNING: These hard coded names need to go away. They need to // come from localizable resources -#if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */ +#if defined(XP_MAC) || defined(XP_MACOSX) #define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application Registry") #define ESSENTIAL_FILES NS_LITERAL_CSTRING("Essential Files") #elif defined(XP_WIN) || defined(XP_OS2) @@ -70,7 +70,7 @@ #endif // define default product directory -#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_OS2) || defined(XP_BEOS) +#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX) || defined(XP_OS2) || defined(XP_BEOS) #define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING("Mozilla") #elif defined (XP_UNIX) #define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING(".mozilla") @@ -80,7 +80,7 @@ #define NS_ENV_PLUGINS_DIR "EnvPlugins" // env var MOZ_PLUGIN_PATH #define NS_USER_PLUGINS_DIR "UserPlugins" -#if defined(XP_MAC) +#if defined(XP_MAC) || defined(XP_MACOSX) #define NS_MACOSX_USER_PLUGIN_DIR "OSXUserPlugins" #define NS_MACOSX_LOCAL_PLUGIN_DIR "OSXLocalPlugins" #define NS_MAC_CLASSIC_PLUGIN_DIR "MacSysPlugins" @@ -137,7 +137,7 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile *_retval = nsnull; *persistant = PR_TRUE; -#if defined (XP_MAC) +#if defined (XP_MAC) || defined(XP_MACOSX) short foundVRefNum; long foundDirID; FSSpec fileSpec; @@ -201,7 +201,7 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile if (NS_SUCCEEDED(rv)) rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME); } -#if defined(XP_MAC) +#if defined(XP_MAC) || defined(XP_MACOSX) else if (nsCRT::strcmp(prop, NS_MACOSX_USER_PLUGIN_DIR) == 0) { if (!(::FindFolder(kUserDomain, @@ -327,7 +327,7 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFi PRBool exists; nsCOMPtr localDir; -#if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */ +#if defined(XP_MAC) nsCOMPtr directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -336,7 +336,16 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFi err = ::Gestalt(gestaltSystemVersion, &response); const char *prop = (!err && response >= 0x00001000) ? NS_MAC_USER_LIB_DIR : NS_MAC_DOCUMENTS_DIR; rv = directoryService->Get(prop, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) return rv; +#elif defined(XP_MACOSX) + FSRef fsRef; + OSErr err = ::FSFindFolder(kUserDomain, kDomainLibraryFolderType, kCreateFolder, &fsRef); + if (err) return NS_ERROR_FAILURE; + NS_NewLocalFile(nsString(), PR_TRUE, getter_AddRefs(localDir)); + if (!localDir) return NS_ERROR_FAILURE; + nsCOMPtr localDirMac(do_QueryInterface(localDir)); + rv = localDirMac->InitWithFSRef(&fsRef); + if (NS_FAILED(rv)) return rv; #elif defined(XP_OS2) nsCOMPtr directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); @@ -450,7 +459,12 @@ class nsAppDirectoryEnumerator : public nsISimpleEnumerator while (!mNext && *mCurrentKey) { PRBool dontCare; - (void)mProvider->GetFile(*mCurrentKey++, &dontCare, getter_AddRefs(mNext)); + nsCOMPtr testFile; + (void)mProvider->GetFile(*mCurrentKey++, &dontCare, getter_AddRefs(testFile)); + // Don't return a file which does not exist. + PRBool exists; + if (testFile && NS_SUCCEEDED(testFile->Exists(&exists)) && exists) + mNext = testFile; } *result = mNext != nsnull; return NS_OK; @@ -494,7 +508,7 @@ nsAppFileLocationProvider::GetFiles(const char *prop, nsISimpleEnumerator **_ret if (!nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR_LIST)) { -#ifdef XP_MAC +#if defined(XP_MAC) || defined(XP_MACOSX) static const char* osXKeys[] = { NS_APP_PLUGINS_DIR, NS_MACOSX_USER_PLUGIN_DIR, NS_MACOSX_LOCAL_PLUGIN_DIR, nsnull }; static const char* os9Keys[] = { NS_APP_PLUGINS_DIR, NS_MAC_CLASSIC_PLUGIN_DIR, nsnull }; static const char** keys; diff --git a/mozilla/xpcom/io/nsDirectoryService.cpp b/mozilla/xpcom/io/nsDirectoryService.cpp index 2a1e53f8734..e213746b55b 100644 --- a/mozilla/xpcom/io/nsDirectoryService.cpp +++ b/mozilla/xpcom/io/nsDirectoryService.cpp @@ -48,9 +48,6 @@ #include #include #include -#ifdef XP_MACOSX -#include "prenv.h" -#endif #elif defined(XP_WIN) #include #include @@ -61,6 +58,16 @@ #include #include #include "prenv.h" +#ifdef XP_MACOSX +#include +#include +#include +#include +#include +#include +#include +#include +#endif #elif defined(XP_OS2) #define MAX_PATH _MAX_PATH #elif defined(XP_BEOS) @@ -97,9 +104,9 @@ // For Windows platform, We are choosing Appdata folder as HOME #if defined (XP_WIN) #define HOME_DIR NS_WIN_APPDATA_DIR -#elif defined (XP_MAC) +#elif defined (XP_MAC) || defined (XP_MACOSX) #define HOME_DIR NS_MAC_HOME_DIR -#elif defined (XP_UNIX) || defined(XP_MACOSX) +#elif defined (XP_UNIX) #define HOME_DIR NS_UNIX_HOME_DIR #elif defined (XP_OS2) #define HOME_DIR NS_OS2_HOME_DIR @@ -119,6 +126,9 @@ nsresult nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) //---------------------------------------------------------------------------------------- { + NS_ENSURE_ARG_POINTER(aFile); + *aFile = nsnull; + // Set the component registry location: if (!mService) return NS_ERROR_FAILURE; @@ -192,46 +202,43 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) return NS_OK; } } -#if defined(DEBUG) && defined(XP_MACOSX) - else +#elif defined(XP_MACOSX) + // Works even if we're not bundled. + CFBundleRef appBundle = CFBundleGetMainBundle(); + if (appBundle != nsnull) { - // In the absence of a good way to get the executable directory let - // us try this for unix: - // - if MOZILLA_FIVE_HOME is defined, that is it - char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME"); - if (moz5) + CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle); + if (bundleURL != nsnull) { - printf( "nsDirectoryService::MOZILLA_FIVE_HOME is set to %s\n", moz5 ); - Str255 pascalpath; - FSSpec ioSpec; - - int srcLength = strlen(moz5); - pascalpath[0] = srcLength; - memcpy(&pascalpath[1], moz5, srcLength); - err = ::FSMakeFSSpec(0, 0, pascalpath, &ioSpec); - - nsCOMPtr localFileMac = do_QueryInterface((nsIFile*)localFile); - if (localFileMac) + CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL); + if (parentURL) { - localFileMac->InitWithFSSpec(&ioSpec); - *aFile = localFile; - return NS_OK; - } - } - else - { - static PRBool firstWarning = PR_TRUE; - - if(firstWarning) { - // Warn that MOZILLA_FIVE_HOME not set, once. - printf("***Warning: MOZILLA_FIVE_HOME not set.\n"); - firstWarning = PR_FALSE; + CFStringRef path = CFURLCopyFileSystemPath(parentURL, kCFURLPOSIXPathStyle); + if (path) + { + char buffer[512]; + if (CFStringGetCString(path, buffer, sizeof(buffer), kCFStringEncodingUTF8)) + { +#ifdef DEBUG_conrad + printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer); +#endif + rv = localFile->InitWithNativePath(nsDependentCString(buffer)); + if (NS_SUCCEEDED(rv)) + *aFile = localFile; + } + CFRelease(path); + } + CFRelease(parentURL); } + CFRelease(bundleURL); } } -#endif /* DEBUG && XP_MACOSX */ + + NS_ASSERTION(*aFile, "nsDirectoryService - Could not determine CurrentProcessDir.\n"); + if (*aFile) + return NS_OK; -#elif defined(XP_UNIX) || defined(XP_MACOSX) +#elif defined(XP_UNIX) // In the absence of a good way to get the executable directory let // us try this for unix: @@ -360,6 +367,9 @@ nsIAtom* nsDirectoryService::sInternetSearchDirectory = nsnull; nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; nsIAtom* nsDirectoryService::sDefaultDownloadDirectory = nsnull; nsIAtom* nsDirectoryService::sUserLibDirectory = nsnull; +#elif defined (XP_MACOSX) +nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; +nsIAtom* nsDirectoryService::sDefaultDownloadDirectory = nsnull; #elif defined (XP_WIN) nsIAtom* nsDirectoryService::sSystemDirectory = nsnull; nsIAtom* nsDirectoryService::sWindowsDirectory = nsnull; @@ -387,7 +397,7 @@ nsIAtom* nsDirectoryService::sCommon_Startup = nsnull; nsIAtom* nsDirectoryService::sCommon_Desktopdirectory = nsnull; nsIAtom* nsDirectoryService::sAppdata = nsnull; nsIAtom* nsDirectoryService::sPrinthood = nsnull; -#elif defined (XP_UNIX) || defined(XP_MACOSX) +#elif defined (XP_UNIX) nsIAtom* nsDirectoryService::sLocalDirectory = nsnull; nsIAtom* nsDirectoryService::sLibDirectory = nsnull; nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; @@ -462,6 +472,9 @@ nsDirectoryService::Init() nsDirectoryService::sHomeDirectory = NS_NewAtom(NS_MAC_HOME_DIR); nsDirectoryService::sDefaultDownloadDirectory = NS_NewAtom(NS_MAC_DEFAULT_DOWNLOAD_DIR); nsDirectoryService::sUserLibDirectory = NS_NewAtom(NS_MAC_USER_LIB_DIR); +#elif defined (XP_MACOSX) + nsDirectoryService::sHomeDirectory = NS_NewAtom(NS_MAC_HOME_DIR); + nsDirectoryService::sDefaultDownloadDirectory = NS_NewAtom(NS_MAC_DEFAULT_DOWNLOAD_DIR); #elif defined (XP_WIN) nsDirectoryService::sSystemDirectory = NS_NewAtom(NS_OS_SYSTEM_DIR); nsDirectoryService::sWindowsDirectory = NS_NewAtom(NS_WIN_WINDOWS_DIR); @@ -489,7 +502,7 @@ nsDirectoryService::Init() nsDirectoryService::sCommon_Desktopdirectory = NS_NewAtom(NS_WIN_COMMON_DESKTOP_DIRECTORY); nsDirectoryService::sAppdata = NS_NewAtom(NS_WIN_APPDATA_DIR); nsDirectoryService::sPrinthood = NS_NewAtom(NS_WIN_PRINTHOOD); -#elif defined (XP_UNIX) || defined(XP_MACOSX) +#elif defined (XP_UNIX) nsDirectoryService::sLocalDirectory = NS_NewAtom(NS_UNIX_LOCAL_DIR); nsDirectoryService::sLibDirectory = NS_NewAtom(NS_UNIX_LIB_DIR); nsDirectoryService::sHomeDirectory = NS_NewAtom(NS_UNIX_HOME_DIR); @@ -551,7 +564,11 @@ nsDirectoryService::~nsDirectoryService() NS_IF_RELEASE(nsDirectoryService::sDocumentsDirectory); NS_IF_RELEASE(nsDirectoryService::sInternetSearchDirectory); NS_IF_RELEASE(nsDirectoryService::sHomeDirectory); + NS_IF_RELEASE(nsDirectoryService::sDefaultDownloadDirectory); NS_IF_RELEASE(nsDirectoryService::sUserLibDirectory); +#elif defined (XP_MACOSX) + NS_IF_RELEASE(nsDirectoryService::sHomeDirectory); + NS_IF_RELEASE(nsDirectoryService::sDefaultDownloadDirectory); #elif defined (XP_WIN) NS_IF_RELEASE(nsDirectoryService::sSystemDirectory); NS_IF_RELEASE(nsDirectoryService::sWindowsDirectory); @@ -579,7 +596,7 @@ nsDirectoryService::~nsDirectoryService() NS_IF_RELEASE(nsDirectoryService::sCommon_Desktopdirectory); NS_IF_RELEASE(nsDirectoryService::sAppdata); NS_IF_RELEASE(nsDirectoryService::sPrinthood); -#elif defined (XP_UNIX) || defined(XP_MACOSX) +#elif defined (XP_UNIX) NS_IF_RELEASE(nsDirectoryService::sLocalDirectory); NS_IF_RELEASE(nsDirectoryService::sLibDirectory); NS_IF_RELEASE(nsDirectoryService::sHomeDirectory); @@ -929,7 +946,54 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { nsSpecialSystemDirectory fileSpec(nsSpecialSystemDirectory::Mac_UserLibDirectory); rv = NS_FileSpecToIFile(&fileSpec, getter_AddRefs(localFile)); - } + } +#elif defined (XP_MACOSX) + else if (inAtom == nsDirectoryService::sHomeDirectory) + { + OSErr err; + FSRef fsRef; + err = ::FSFindFolder(kUserDomain, kDomainTopLevelFolderType, kCreateFolder, &fsRef); + if (err == noErr) + { + NS_NewLocalFile(nsString(), PR_TRUE, getter_AddRefs(localFile)); + nsCOMPtr localMacFile(do_QueryInterface(localFile)); + if (localMacFile) + rv = localMacFile->InitWithFSRef(&fsRef); + } + } + else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory) + { + NS_NewLocalFile(nsString(), PR_TRUE, getter_AddRefs(localFile)); + nsCOMPtr localMacFile(do_QueryInterface(localFile)); + + if (localMacFile) + { + OSErr err; + ICInstance icInstance; + + err = ::ICStart(&icInstance, 'XPCM'); + if (err == noErr) + { + ICAttr attrs; + ICFileSpec icFileSpec; + long size = kICFileSpecHeaderSize; + err = ::ICGetPref(icInstance, kICDownloadFolder, &attrs, &icFileSpec, &size); + if (err == noErr || (err == icTruncatedErr && size >= kICFileSpecHeaderSize)) + { + rv = localMacFile->InitWithFSSpec(&icFileSpec.fss); + } + ::ICStop(icInstance); + } + + if NS_FAILED(rv) + { // We got an error getting the DL folder from IC so try finding the user's Desktop folder + FSRef fsRef; + err = ::FSFindFolder(kUserDomain, kSystemDesktopFolderType, kCreateFolder, &fsRef); + if (err == noErr) + rv = localMacFile->InitWithFSRef(&fsRef); + } + } + } #elif defined (XP_WIN) else if (inAtom == nsDirectoryService::sSystemDirectory) { @@ -1061,7 +1125,7 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret nsSpecialSystemDirectory fileSpec(nsSpecialSystemDirectory::Win_Printhood); rv = NS_FileSpecToIFile(&fileSpec, getter_AddRefs(localFile)); } -#elif defined (XP_UNIX) || defined(XP_MACOSX) +#elif defined (XP_UNIX) else if (inAtom == nsDirectoryService::sLocalDirectory) { diff --git a/mozilla/xpcom/io/nsDirectoryService.h b/mozilla/xpcom/io/nsDirectoryService.h index 7b0d54699a7..221e39291a0 100644 --- a/mozilla/xpcom/io/nsDirectoryService.h +++ b/mozilla/xpcom/io/nsDirectoryService.h @@ -104,6 +104,9 @@ private: static nsIAtom *sHomeDirectory; static nsIAtom *sDefaultDownloadDirectory; static nsIAtom *sUserLibDirectory; +#elif defined (XP_MACOSX) + static nsIAtom *sHomeDirectory; + static nsIAtom *sDefaultDownloadDirectory; #elif defined (XP_WIN) static nsIAtom *sSystemDirectory; static nsIAtom *sWindowsDirectory; @@ -131,7 +134,7 @@ private: static nsIAtom *sCommon_Desktopdirectory; static nsIAtom *sAppdata; static nsIAtom *sPrinthood; -#elif defined (XP_UNIX) || defined(XP_MACOSX) +#elif defined (XP_UNIX) static nsIAtom *sLocalDirectory; static nsIAtom *sLibDirectory; static nsIAtom *sHomeDirectory; diff --git a/mozilla/xpcom/io/nsDirectoryServiceDefs.h b/mozilla/xpcom/io/nsDirectoryServiceDefs.h index 0532d34b2cb..cc387ddea49 100755 --- a/mozilla/xpcom/io/nsDirectoryServiceDefs.h +++ b/mozilla/xpcom/io/nsDirectoryServiceDefs.h @@ -72,14 +72,7 @@ #define NS_OS_SYSTEM_DIR "SysD" #endif -// for MacOSX we need the UNIX entries, plus the MAC entries -#if defined (XP_UNIX) || defined(XP_MACOSX) - #define NS_UNIX_LOCAL_DIR "Locl" - #define NS_UNIX_LIB_DIR "LibD" - #define NS_UNIX_HOME_DIR "Home" -#endif - -#if defined(XP_MAC) || defined(XP_MACOSX) +#if defined(XP_MAC) #define NS_MAC_DESKTOP_DIR "Desk" #define NS_MAC_TRASH_DIR "Trsh" #define NS_MAC_STARTUP_DIR "Strt" @@ -95,6 +88,9 @@ #define NS_MAC_HOME_DIR "Home" #define NS_MAC_DEFAULT_DOWNLOAD_DIR "DfltDwnld" #define NS_MAC_USER_LIB_DIR "ULibDir" // Only available under OS X +#elif defined (XP_MACOSX) + #define NS_MAC_HOME_DIR "Home" + #define NS_MAC_DEFAULT_DOWNLOAD_DIR "DfltDwnld" #elif defined (XP_WIN) #define NS_WIN_WINDOWS_DIR "WinD" #define NS_WIN_HOME_DIR "Home" @@ -121,6 +117,10 @@ #define NS_WIN_COMMON_DESKTOP_DIRECTORY "CmDeskP" #define NS_WIN_APPDATA_DIR "AppData" #define NS_WIN_PRINTHOOD "PrntHd" +#elif defined (XP_UNIX) + #define NS_UNIX_LOCAL_DIR "Locl" + #define NS_UNIX_LIB_DIR "LibD" + #define NS_UNIX_HOME_DIR "Home" #elif defined (XP_OS2) #define NS_OS2_DIR "OS2Dir" #define NS_OS2_HOME_DIR "Home" diff --git a/mozilla/xpcom/io/nsILocalFileMac.idl b/mozilla/xpcom/io/nsILocalFileMac.idl index 8f0fab22100..302d40dffd4 100644 --- a/mozilla/xpcom/io/nsILocalFileMac.idl +++ b/mozilla/xpcom/io/nsILocalFileMac.idl @@ -40,21 +40,49 @@ %{C++ #include +#include %} native OSType(OSType); native FSSpec(FSSpec); -[ref] native FSSpecRef(FSSpec); [ptr] native FSSpecPtr(FSSpec); - + native FSRef(FSRef); +[ptr] native FSRefPtr(FSRef); + native CFURLRef(CFURLRef); [uuid(614c3010-1dd2-11b2-be04-bcd57a64ffc9)] interface nsILocalFileMac : nsILocalFile { + /** + * initWithCFURL + * + * Init this object with a CFURLRef + * + * NOTE: Supported only for XP_MACOSX or TARGET_CARBON + * NOTE: If the path of the CFURL is /a/b/c, at least a/b must exist beforehand. + * + * @param aCFURL the CoreFoundation URL + * + */ + void initWithCFURL(in CFURLRef aCFURL); + + /** + * initWithFSRef + * + * Init this object with an FSRef + * + * NOTE: Supported only for XP_MACOSX or TARGET_CARBON + * + * @param aFSRef the native file spec + * + */ + void initWithFSRef([const] in FSRefPtr aFSRef); + /** * initWithFSSpec * * Init this object with an FSSpec + * Legacy method - leaving in place for now * * @param aFileSpec the native file spec * @@ -72,7 +100,24 @@ interface nsILocalFileMac : nsILocalFile * */ void initToAppWithCreatorCode(in OSType aAppCreator); - + + /** + * getFSRef + * + * Returns the FSRef of the file object. + * + * NOTE: Observes the state of the followLinks attribute. + * If the file object is an alias and followLinks is TRUE, returns + * the target of the alias. If followLinks is FALSE, returns + * the unresolved alias file. + * + * NOTE: Supported only for XP_MACOSX or TARGET_CARBON + * + * @return + * + */ + FSRef getFSRef(); + /** * getFSSpec * @@ -170,8 +215,11 @@ interface nsILocalFileMac : nsILocalFile %{C++ extern "C" { -NS_EXPORT const char* NS_TruncNodeName(const char *aNode, char *outBuf); -NS_EXPORT nsresult NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followSymlinks, nsILocalFileMac* *result); +#ifndef XP_MACOSX +NS_EXPORT const char* NS_TruncNodeName(const char *aNode, char *outBuf); +#endif + +NS_EXPORT nsresult NS_NewLocalFileWithFSSpec(const FSSpec* inSpec, PRBool followSymlinks, nsILocalFileMac* *result); } %} diff --git a/mozilla/xpcom/io/nsLocalFile.h b/mozilla/xpcom/io/nsLocalFile.h index 88789dbcc17..3e7408eb0bf 100644 --- a/mozilla/xpcom/io/nsLocalFile.h +++ b/mozilla/xpcom/io/nsLocalFile.h @@ -51,9 +51,11 @@ // on this. #ifdef XP_WIN #include "nsLocalFileWin.h" -#elif defined(XP_MAC) && !defined(XP_MACOSX) +#elif defined(XP_MACOSX) +#include "nsLocalFileOSX.h" +#elif defined(XP_MAC) #include "nsLocalFileMac.h" -#elif defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_MACOSX) +#elif defined(XP_UNIX) || defined(XP_BEOS) #include "nsLocalFileUnix.h" #elif defined(XP_OS2) #include "nsLocalFileOS2.h" diff --git a/mozilla/xpcom/io/nsLocalFileCommon.cpp b/mozilla/xpcom/io/nsLocalFileCommon.cpp index bb1668688b3..05130b62738 100644 --- a/mozilla/xpcom/io/nsLocalFileCommon.cpp +++ b/mozilla/xpcom/io/nsLocalFileCommon.cpp @@ -56,7 +56,7 @@ void NS_ShutdownLocalFile() nsLocalFile::GlobalShutdown(); } -#if !defined(XP_MAC) +#if !defined(XP_MAC) && !defined(XP_MACOSX) NS_IMETHODIMP nsLocalFile::InitWithFile(nsILocalFile *aFile) { @@ -70,8 +70,11 @@ nsLocalFile::InitWithFile(nsILocalFile *aFile) } #endif -// should work on Macintosh, Unix, and Win32. -#define kMaxFilenameLength 31 +#if defined(XP_MAC) +#define kMaxFilenameLength 31 +#else +#define kMaxFilenameLength 255 +#endif NS_IMETHODIMP nsLocalFile::CreateUnique(PRUint32 type, PRUint32 attributes) @@ -95,8 +98,7 @@ nsLocalFile::CreateUnique(PRUint32 type, PRUint32 attributes) leafName.SetLength(lastDot - leafName.get()); // strip suffix and dot. } - // 27 should work on Macintosh, Unix, and Win32. - const int maxRootLength = 27 - strlen(suffix) - 1; + const int maxRootLength = (kMaxFilenameLength - 4) - strlen(suffix) - 1; if ((int)leafName.Length() > (int)maxRootLength) leafName.SetLength(maxRootLength); diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index 1205b495da2..7d35a969e02 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -3130,6 +3130,82 @@ nsLocalFile::IsSpecial(PRBool *_retval) // Implementation of Mac specific finctions from nsILocalFileMac +NS_IMETHODIMP nsLocalFile::InitWithCFURL(CFURLRef aCFURL) +{ + nsresult rv = NS_ERROR_FAILURE; + +#if TARGET_CARBON + NS_ENSURE_ARG(aCFURL); + + // CFURLGetFSRef can only succeed if the entire path exists. + FSRef fsRef; + if (::CFURLGetFSRef(aCFURL, &fsRef) == PR_TRUE) + rv = InitWithFSRef(&fsRef); + else + { + CFURLRef parentURL = ::CFURLCreateCopyDeletingLastPathComponent(NULL, aCFURL); + if (!parentURL) + return NS_ERROR_FAILURE; + + // Get the FSRef from the parent and the FSSpec from that + FSRef parentFSRef; + FSSpec parentFSSpec; + if (::CFURLGetFSRef(parentURL, &parentFSRef) == noErr && + ::FSGetCatalogInfo(&parentFSRef, kFSCatInfoNone, + nsnull, nsnull, &parentFSSpec, nsnull) == noErr) + { + // Get the leaf name of the file and turn it into a string HFS can use. + CFStringRef fileNameRef = ::CFURLCopyLastPathComponent(aCFURL); + if (fileNameRef) + { + TextEncoding theEncoding; + if (::UpgradeScriptInfoToTextEncoding(smSystemScript, + kTextLanguageDontCare, + kTextRegionDontCare, + NULL, + &theEncoding) != noErr) + theEncoding = kTextEncodingMacRoman; + + char origName[256]; + char truncBuf[32]; + if (::CFStringGetCString(fileNameRef, origName, sizeof(origName), theEncoding)) + { + MakeDirty(); + mSpec = parentFSSpec; + mAppendedPath = NS_TruncNodeName(origName, truncBuf); + rv = NS_OK; + } + ::CFRelease(fileNameRef); + } + } + ::CFRelease(parentURL); + } +#endif + + return rv; +} + + +NS_IMETHODIMP nsLocalFile::InitWithFSRef(const FSRef * aFSRef) +{ + nsresult rv = NS_ERROR_FAILURE; + +#if TARGET_CARBON + NS_ENSURE_ARG(aFSRef); + + FSSpec fsSpec; + OSErr err = ::FSGetCatalogInfo(aFSRef, kFSCatInfoNone, nsnull, + nsnull, &fsSpec, nsnull); + if (err == noErr) + rv = InitWithFSSpec(&fsSpec); + else + rv = MacErrorMapper(err); +#endif + + return rv; +} + + NS_IMETHODIMP nsLocalFile::InitWithFSSpec(const FSSpec *fileSpec) { MakeDirty(); @@ -3181,6 +3257,22 @@ NS_IMETHODIMP nsLocalFile::InitToAppWithCreatorCode(OSType aAppCreator) return InitWithFSSpec(&appSpec); } +NS_IMETHODIMP nsLocalFile::GetFSRef(FSRef *_retval) +{ + nsresult rv = NS_ERROR_FAILURE; + +#if TARGET_CARBON + NS_ENSURE_ARG_POINTER(_retval); + + FSSpec fsSpec; + rv = GetFSSpec(&fsSpec); + if (NS_SUCCEEDED(rv)) + rv = MacErrorMapper(::FSpMakeFSRef(&fsSpec, _retval)); +#endif + + return rv; +} + NS_IMETHODIMP nsLocalFile::GetFSSpec(FSSpec *fileSpec) { NS_ENSURE_ARG(fileSpec); @@ -3556,7 +3648,7 @@ NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result } nsresult -NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followLinks, nsILocalFileMac* *result) +NS_NewLocalFileWithFSSpec(const FSSpec* inSpec, PRBool followLinks, nsILocalFileMac* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) diff --git a/mozilla/xpinstall/src/nsInstallFolder.cpp b/mozilla/xpinstall/src/nsInstallFolder.cpp index f1b4758f9e5..a398137eef2 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.cpp +++ b/mozilla/xpinstall/src/nsInstallFolder.cpp @@ -462,7 +462,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe break; #endif -#ifdef XP_UNIX +#if defined(XP_UNIX) && !defined(XP_MACOSX) case 400: /////////////////////////////////////////////////////////// Unix Local { nsCOMPtr directoryService =