From 714da09a59eec42167f045876eeec7925f4953cc Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 24 Jan 2000 21:28:28 +0000 Subject: [PATCH] Landing nsIFile. git-svn-id: svn://10.0.0.236/trunk@58490 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/build/mac/NGLayoutBuildList.pm | 4 +- .../html/document/src/nsHTMLDocument.cpp | 9 +- mozilla/htmlparser/src/nsParserModule.cpp | 8 +- mozilla/intl/chardet/src/nsCharDetModule.cpp | 8 +- .../compatibility/src/nsI18nCompatibility.cpp | 2 + .../intl/locale/src/unix/nsCollationUnix.cpp | 2 +- .../intl/locale/src/unix/nsLocaleModule.cpp | 8 +- mozilla/intl/strres/src/nsStringBundle.cpp | 4 +- mozilla/intl/uconv/src/nsUConvModule.cpp | 16 +- mozilla/intl/uconv/ucvcn/nsUCvCnModule.cpp | 8 +- mozilla/intl/uconv/ucvibm/nsUCvIBMModule.cpp | 8 +- mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp | 8 +- mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp | 8 +- .../intl/uconv/ucvlatin/nsUCvLatinModule.cpp | 8 +- mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp | 8 +- mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp | 8 +- .../unicharutil/src/nsUcharUtilModule.cpp | 2 + .../xpconnect/loader/mozJSComponentLoader.cpp | 137 +- .../xpconnect/loader/mozJSComponentLoader.h | 15 +- .../tests/components/xpctest_module.cpp | 2 + mozilla/layout/build/nsLayoutDLF.cpp | 6 +- mozilla/layout/build/nsLayoutModule.cpp | 8 +- mozilla/layout/build/nsLayoutModule.h | 4 +- .../html/document/src/nsHTMLDocument.cpp | 9 +- mozilla/lib/mac/NSStdLib/NSStdLib.exp | 2 + mozilla/lib/mac/NSStdLib/NSStdLib.mcp | Bin 314391 -> 314391 bytes mozilla/mailnews/base/build/nsMsgFactory.cpp | 12 +- .../db/msgdb/build/nsMsgDBFactory.cpp | 13 +- mozilla/mailnews/imap/build/nsImapFactory.cpp | 12 +- .../import/eudora/src/nsEudoraFactory.cpp | 5 +- .../mailnews/import/oexpress/nsOEFactory.cpp | 13 +- .../mailnews/import/outlook/src/MapiMessage.h | 2 +- .../mailnews/import/src/nsImportFactory.cpp | 4 +- .../import/text/src/nsTextFactory.cpp | 2 +- .../local/build/nsMsgLocalFactory.cpp | 14 +- mozilla/mailnews/mime/build/nsMimeModule.cpp | 14 +- mozilla/modules/libimg/gifcom/nsGIFModule.cpp | 12 +- mozilla/modules/libimg/jpgcom/nsJPGModule.cpp | 12 +- mozilla/modules/libimg/pngcom/nsPNGModule.cpp | 12 +- mozilla/modules/libjar/nsIZipReader.idl | 6 +- mozilla/modules/libjar/nsJAR.cpp | 29 +- mozilla/modules/libjar/nsJAR.h | 5 +- mozilla/modules/libjar/nsJARChannel.cpp | 103 +- mozilla/modules/libjar/nsJARChannel.h | 8 +- mozilla/modules/libjar/nsZipArchive.cpp | 110 +- mozilla/modules/libjar/nsZipArchive.h | 23 +- mozilla/modules/libreg/xpcom/nsIRegistry.idl | 2 + mozilla/modules/libreg/xpcom/nsRegistry.cpp | 88 +- mozilla/netwerk/base/public/Makefile.in | 1 + mozilla/netwerk/base/public/makefile.win | 1 + mozilla/netwerk/base/public/nsIChannel.idl | 43 + .../base/public/nsIFileTransportService.idl | 11 +- mozilla/netwerk/base/public/nsIIOService.idl | 16 +- mozilla/netwerk/base/public/nsIURL.idl | 13 + mozilla/netwerk/base/public/nsNetUtil.h | 1 - mozilla/netwerk/base/src/Makefile.in | 1 + mozilla/netwerk/base/src/makefile.win | 2 + .../base/src/nsDirectoryIndexStream.cpp | 116 +- .../netwerk/base/src/nsDirectoryIndexStream.h | 12 +- mozilla/netwerk/base/src/nsFileTransport.cpp | 119 +- mozilla/netwerk/base/src/nsFileTransport.h | 11 +- .../base/src/nsFileTransportService.cpp | 5 +- mozilla/netwerk/base/src/nsIOService.cpp | 36 - mozilla/netwerk/base/src/nsStdURL.cpp | 77 +- mozilla/netwerk/base/src/nsStdURL.h | 24 +- mozilla/netwerk/build/nsNetModule.cpp | 11 +- .../cache/filecache/nsDiskCacheRecord.h | 2 +- mozilla/netwerk/macbuild/netwerk.mcp | Bin 63272 -> 63272 bytes mozilla/netwerk/macbuild/netwerkIDL.mcp | Bin 45908 -> 45908 bytes .../protocol/about/src/nsAboutBloat.cpp | 40 +- .../netwerk/protocol/file/public/MANIFEST_IDL | 2 - .../netwerk/protocol/file/public/Makefile.in | 2 - .../netwerk/protocol/file/public/makefile.win | 2 - .../file/public/nsIFileProtocolHandler.idl | 15 +- .../protocol/file/src/nsFileChannel.cpp | 430 +---- .../netwerk/protocol/file/src/nsFileChannel.h | 20 +- .../file/src/nsFileProtocolHandler.cpp | 38 +- .../protocol/file/src/nsFileProtocolHandler.h | 10 +- .../file/src/nsFileProtocolModule.cpp | 7 +- .../protocol/http/src/nsHTTPEncodeStream.cpp | 6 +- .../protocol/http/src/nsHTTPEncodeStream.h | 7 +- .../protocol/http/src/nsHTTPHandler.cpp | 39 +- .../netwerk/protocol/jar/src/nsJARChannel.cpp | 103 +- .../netwerk/protocol/jar/src/nsJARChannel.h | 8 +- mozilla/netwerk/test/TestFileInput.cpp | 57 +- mozilla/netwerk/test/TestFileInput2.cpp | 287 ++-- mozilla/netwerk/test/TestFileTransport.cpp | 39 +- mozilla/netwerk/test/TestRawCache.cpp | 2 +- .../parser/htmlparser/src/nsParserModule.cpp | 8 +- mozilla/view/src/nsViewFactory.cpp | 28 +- mozilla/widget/src/gtk/nsClipboard.cpp | 1 + mozilla/widget/src/gtk/nsSound.cpp | 2 + mozilla/xpcom/base/nsDebug.cpp | 30 + mozilla/xpcom/base/nsError.h | 52 +- mozilla/xpcom/base/nsISupportsUtils.h | 60 +- mozilla/xpcom/build/nsXPComInit.cpp | 77 +- mozilla/xpcom/components/makefile.win | 1 + .../xpcom/components/nsComponentManager.cpp | 148 +- mozilla/xpcom/components/nsComponentManager.h | 8 +- .../components/nsComponentManagerUtils.h | 13 +- mozilla/xpcom/components/nsGenericFactory.cpp | 9 +- .../xpcom/components/nsIComponentLoader.idl | 6 +- .../xpcom/components/nsIComponentManager.idl | 17 +- mozilla/xpcom/components/nsIGenericFactory.h | 6 +- mozilla/xpcom/components/nsIModule.idl | 10 +- mozilla/xpcom/components/nsIRegistry.idl | 2 + mozilla/xpcom/components/nsIServiceManager.h | 3 +- .../components/nsNativeComponentLoader.cpp | 189 ++- .../components/nsNativeComponentLoader.h | 24 +- mozilla/xpcom/components/nsRegistry.cpp | 88 +- mozilla/xpcom/components/nsRepository.cpp | 8 +- mozilla/xpcom/components/xcDll.cpp | 171 +- mozilla/xpcom/components/xcDll.h | 33 +- mozilla/xpcom/glue/nsComponentManagerUtils.h | 13 +- mozilla/xpcom/glue/nsDebug.cpp | 30 + mozilla/xpcom/glue/nsGenericFactory.cpp | 9 +- mozilla/xpcom/glue/nsIGenericFactory.h | 6 +- mozilla/xpcom/glue/nsISupportsUtils.h | 60 +- mozilla/xpcom/io/MANIFEST | 3 + mozilla/xpcom/io/MANIFEST_IDL | 2 + mozilla/xpcom/io/Makefile.in | 29 +- mozilla/xpcom/io/makefile.win | 17 +- mozilla/xpcom/io/nsDirectoryService.cpp | 269 +++- mozilla/xpcom/io/nsDirectoryService.h | 24 +- mozilla/xpcom/io/nsFileSpecImpl.cpp | 11 +- mozilla/xpcom/io/nsFileStream.cpp | 1 - mozilla/xpcom/io/nsIBaseStream.idl | 18 - mozilla/xpcom/io/nsIFile.idl | 84 +- mozilla/xpcom/io/nsILocalFile.idl | 60 +- mozilla/xpcom/io/nsILocalFileMac.h | 77 + mozilla/xpcom/io/nsLocalFile.h | 2 + mozilla/xpcom/io/nsLocalFileMac.cpp | 1404 +++++++++++------ mozilla/xpcom/io/nsLocalFileMac.h | 44 +- mozilla/xpcom/io/nsLocalFileUnix.cpp | 704 +++++++-- mozilla/xpcom/io/nsLocalFileUnix.h | 16 +- mozilla/xpcom/io/nsLocalFileWin.cpp | 372 +++-- mozilla/xpcom/io/nsLocalFileWin.h | 4 +- mozilla/xpcom/macbuild/XPCOMIDL.mcp | Bin 80714 -> 77986 bytes mozilla/xpcom/macbuild/xpcomPPC.mcp | Bin 141554 -> 141554 bytes mozilla/xpcom/tests/Makefile.in | 1 + mozilla/xpcom/tests/TestServMgr.cpp | 2 +- mozilla/xpcom/tests/makefile.win | 46 +- mozilla/xpcom/tests/nsIFileTest.cpp | 49 +- mozilla/xpcom/tests/services/Makefile.in | 1 + mozilla/xpcom/tests/services/makefile.win | 2 +- mozilla/xpcom/tests/utils/cp.js | 8 +- mozilla/xpcom/tests/utils/ls.js | 2 +- mozilla/xpcom/tools/registry/regxpcom.cpp | 24 +- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 1 + .../bookmarks/src/nsBookmarksService.cpp | 9 +- .../directory/nsDirectoryViewer.cpp | 7 +- .../history/src/nsGlobalHistory.cpp | 9 +- .../public/nsIAppShellComponentImpl.h | 10 +- .../regviewer/nsRegistryDataSource.cpp | 8 +- .../related/src/nsRelatedLinksHandler.cpp | 7 +- .../search/src/nsRegisterSearch.cpp | 7 +- .../components/shistory/src/nsSHistory.cpp | 2 +- .../components/xfer/src/nsStreamXferOp.cpp | 12 +- mozilla/xpinstall/src/nsInstall.cpp | 18 +- mozilla/xpinstall/src/nsSoftwareUpdate.cpp | 7 +- mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp | 12 +- mozilla/xpinstall/stub/xpistub.cpp | 37 +- 162 files changed, 4387 insertions(+), 2566 deletions(-) create mode 100644 mozilla/xpcom/io/nsILocalFileMac.h diff --git a/mozilla/build/mac/NGLayoutBuildList.pm b/mozilla/build/mac/NGLayoutBuildList.pm index 33feedffc72..f4f0c1df7c3 100644 --- a/mozilla/build/mac/NGLayoutBuildList.pm +++ b/mozilla/build/mac/NGLayoutBuildList.pm @@ -788,7 +788,7 @@ sub BuildClientDist() _InstallFromManifest(":mozilla:netwerk:socket:base:MANIFEST_IDL", "$distdirectory:idl:"); _InstallFromManifest(":mozilla:netwerk:protocol:about:public:MANIFEST_IDL", "$distdirectory:idl:"); _InstallFromManifest(":mozilla:netwerk:protocol:data:public:MANIFEST_IDL", "$distdirectory:idl:"); - _InstallFromManifest(":mozilla:netwerk:protocol:file:public:MANIFEST_IDL", "$distdirectory:idl:"); + #_InstallFromManifest(":mozilla:netwerk:protocol:file:public:MANIFEST_IDL", "$distdirectory:idl:"); _InstallFromManifest(":mozilla:netwerk:protocol:http:public:MANIFEST_IDL", "$distdirectory:idl:"); _InstallFromManifest(":mozilla:netwerk:protocol:http:public:MANIFEST", "$distdirectory:netwerk:"); _InstallFromManifest(":mozilla:netwerk:protocol:jar:public:MANIFEST_IDL", "$distdirectory:idl:"); @@ -1131,7 +1131,7 @@ sub BuildIDLProjects() # protocols BuildIDLProject(":mozilla:netwerk:protocol:about:macbuild:aboutIDL.mcp","about"); BuildIDLProject(":mozilla:netwerk:protocol:data:macbuild:dataIDL.mcp","data"); - BuildIDLProject(":mozilla:netwerk:protocol:file:macbuild:fileIDL.mcp","file"); + #BuildIDLProject(":mozilla:netwerk:protocol:file:macbuild:fileIDL.mcp","file"); BuildIDLProject(":mozilla:netwerk:protocol:ftp:macbuild:ftpIDL.mcp","ftp"); BuildIDLProject(":mozilla:netwerk:protocol:http:macbuild:httpIDL.mcp","http"); BuildIDLProject(":mozilla:netwerk:protocol:jar:macbuild:jarIDL.mcp","jar"); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 4c2ed4b8f3e..c9e1021ab8c 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -79,7 +79,7 @@ #include "nsGenericDOMNodeList.h" #include "nsICSSLoader.h" #include "nsIHTTPChannel.h" -#include "nsIFileChannel.h" +#include "nsIFile.h" #include "nsIEventListenerManager.h" #include "nsISelectElement.h" @@ -497,8 +497,11 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, nsCOMPtr fileChannel = do_QueryInterface(aChannel); if (fileChannel) { PRTime modDate; - - rv = fileChannel->GetModDate(&modDate); + + nsCOMPtr file; + rv = fileChannel->GetFile(getter_AddRefs(file)); + if (NS_FAILED(rv)) { return rv; } + rv = file->GetLastModificationDate(&modDate); if (NS_FAILED(rv)) { return rv; } PRExplodedTime prtime; char buf[100]; diff --git a/mozilla/htmlparser/src/nsParserModule.cpp b/mozilla/htmlparser/src/nsParserModule.cpp index 4798fab986e..73e4f21a4de 100644 --- a/mozilla/htmlparser/src/nsParserModule.cpp +++ b/mozilla/htmlparser/src/nsParserModule.cpp @@ -20,6 +20,8 @@ * Contributor(s): * Pierre Phaneuf */ +#include "nsString.h" +#include "nspr.h" #include "nsCOMPtr.h" #include "nsIGenericFactory.h" #include "nsIModule.h" @@ -292,7 +294,7 @@ nsParserModule::GetClassObject(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -316,7 +318,7 @@ nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsParserModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { Components* cp = gComponents; @@ -350,7 +352,7 @@ nsParserModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) static nsParserModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/intl/chardet/src/nsCharDetModule.cpp b/mozilla/intl/chardet/src/nsCharDetModule.cpp index 05c589ce66c..6fb58c008ec 100644 --- a/mozilla/intl/chardet/src/nsCharDetModule.cpp +++ b/mozilla/intl/chardet/src/nsCharDetModule.cpp @@ -26,6 +26,8 @@ #include "nsCOMPtr.h" #include "nsIModule.h" +#include "nspr.h" +#include "nsString.h" #include "pratom.h" #include "nsCharDetDll.h" #include "nsISupports.h" @@ -286,7 +288,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsCharDetModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -395,7 +397,7 @@ nsCharDetModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsCharDetModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -432,7 +434,7 @@ nsCharDetModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) static nsCharDetModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/intl/compatibility/src/nsI18nCompatibility.cpp b/mozilla/intl/compatibility/src/nsI18nCompatibility.cpp index 33d3962f321..afbddfefd1b 100644 --- a/mozilla/intl/compatibility/src/nsI18nCompatibility.cpp +++ b/mozilla/intl/compatibility/src/nsI18nCompatibility.cpp @@ -30,6 +30,8 @@ #include "nsIServiceManager.h" #include "nsII18nCompatibility.h" #include "nsI18nCompatibility.h" +#include "nsIFile.h" +#include "nsFileSpec.h" static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); static NS_DEFINE_CID(kI18nCompatibilityCID, NS_I18NCOMPATIBILITY_CID); diff --git a/mozilla/intl/locale/src/unix/nsCollationUnix.cpp b/mozilla/intl/locale/src/unix/nsCollationUnix.cpp index dbb9b299b23..798bdc006d1 100644 --- a/mozilla/intl/locale/src/unix/nsCollationUnix.cpp +++ b/mozilla/intl/locale/src/unix/nsCollationUnix.cpp @@ -30,7 +30,7 @@ #include "nsIPlatformCharset.h" #include "nsIPosixLocale.h" #include "nsCOMPtr.h" - +#include "nsFileSpec.h" /* for nsAutoString */ #define DEBUG_UNIX_COLLATION static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID); diff --git a/mozilla/intl/locale/src/unix/nsLocaleModule.cpp b/mozilla/intl/locale/src/unix/nsLocaleModule.cpp index 2dbd2bbae79..33b6e3bd422 100644 --- a/mozilla/intl/locale/src/unix/nsLocaleModule.cpp +++ b/mozilla/intl/locale/src/unix/nsLocaleModule.cpp @@ -19,6 +19,8 @@ * * Contributor(s): */ +#include "nspr.h" +#include "nsString.h" #include "nsCOMPtr.h" #include "nsIModule.h" #include "nsIComponentManager.h" @@ -230,7 +232,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsLocaleModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -261,7 +263,7 @@ nsLocaleModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsLocaleModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -298,7 +300,7 @@ nsLocaleModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) static nsLocaleModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/intl/strres/src/nsStringBundle.cpp b/mozilla/intl/strres/src/nsStringBundle.cpp index 3865fb2294c..1be389d0384 100644 --- a/mozilla/intl/strres/src/nsStringBundle.cpp +++ b/mozilla/intl/strres/src/nsStringBundle.cpp @@ -22,7 +22,7 @@ #define NS_IMPL_IDS #include "nsID.h" - +#include "nsFileSpec.h" #include "nsString2.h" #include "nsIPersistentProperties.h" #include "nsIStringBundle.h" @@ -650,4 +650,6 @@ static nsModuleComponentInfo components[] = { { "String Bundle", NS_STRINGBUNDLESERVICE_CID, NS_STRINGBUNDLE_PROGID, nsStringBundleServiceConstructor} }; + NS_IMPL_NSGETMODULE("nsStringBundleModule", components) + diff --git a/mozilla/intl/uconv/src/nsUConvModule.cpp b/mozilla/intl/uconv/src/nsUConvModule.cpp index 89850ce87e0..16ffbf64330 100644 --- a/mozilla/intl/uconv/src/nsUConvModule.cpp +++ b/mozilla/intl/uconv/src/nsUConvModule.cpp @@ -33,7 +33,8 @@ #include "nsCharsetMenu.h" #include "rdf.h" #include "nsUConvDll.h" - +#include "nsFileSpec.h" +#include "nsIFile.h" //---------------------------------------------------------------------- // Global functions and data [declaration] @@ -175,7 +176,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsUConvModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -201,16 +202,13 @@ nsUConvModule::RegisterSelf(nsIComponentManager *aCompMgr, cp++; } - // XXX also unregister this stuff when time comes - rv = NS_RegisterConverterManagerData(); - return rv; } NS_IMETHODIMP nsUConvModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) + nsIFile* aPath, + const char* registryLocation) { #ifdef DEBUG printf("*** Unregistering uconv components\n"); @@ -246,8 +244,8 @@ nsUConvModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) static nsUConvModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, - nsIModule** return_cobj) + nsIFile* aPath, + nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/intl/uconv/ucvcn/nsUCvCnModule.cpp b/mozilla/intl/uconv/ucvcn/nsUCvCnModule.cpp index 3097c46b0d6..08e52ba1102 100644 --- a/mozilla/intl/uconv/ucvcn/nsUCvCnModule.cpp +++ b/mozilla/intl/uconv/ucvcn/nsUCvCnModule.cpp @@ -22,6 +22,8 @@ #define NS_IMPL_IDS +#include "nspr.h" +#include "nsString.h" #include "pratom.h" #include "nsCOMPtr.h" #include "nsIFactory.h" @@ -202,7 +204,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -346,7 +348,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -410,7 +412,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/uconv/ucvibm/nsUCvIBMModule.cpp b/mozilla/intl/uconv/ucvibm/nsUCvIBMModule.cpp index a699f4cb692..50ad1c61c42 100644 --- a/mozilla/intl/uconv/ucvibm/nsUCvIBMModule.cpp +++ b/mozilla/intl/uconv/ucvibm/nsUCvIBMModule.cpp @@ -36,6 +36,8 @@ #define NS_IMPL_IDS #include "pratom.h" +#include "nspr.h" +#include "nsString.h" #include "nsCOMPtr.h" #include "nsIFactory.h" #include "nsIRegistry.h" @@ -224,7 +226,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -368,7 +370,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -432,7 +434,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp b/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp index a2132b77b3f..585d5ed675c 100644 --- a/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp +++ b/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp @@ -22,6 +22,8 @@ #define NS_IMPL_IDS +#include "nspr.h" +#include "nsString.h" #include "pratom.h" #include "nsCOMPtr.h" #include "nsIFactory.h" @@ -236,7 +238,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -380,7 +382,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -444,7 +446,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp b/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp index 6255397b7d8..4bada40f4c3 100644 --- a/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp +++ b/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp @@ -22,6 +22,8 @@ #define NS_IMPL_IDS +#include "nspr.h" +#include "nsString.h" #include "pratom.h" #include "nsCOMPtr.h" #include "nsIFactory.h" @@ -170,7 +172,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -314,7 +316,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -378,7 +380,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp b/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp index 37fe2e02ce7..19601beebe4 100644 --- a/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp +++ b/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp @@ -23,6 +23,8 @@ #define NS_IMPL_IDS #include "pratom.h" +#include "nspr.h" +#include "nsString.h" #include "nsCOMPtr.h" #include "nsIFactory.h" #include "nsIRegistry.h" @@ -865,7 +867,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -1009,7 +1011,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -1073,7 +1075,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp b/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp index 452fc117445..33c786c5270 100644 --- a/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp +++ b/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp @@ -22,6 +22,8 @@ #define NS_IMPL_IDS +#include "nspr.h" +#include "nsString.h" #include "pratom.h" #include "nsCOMPtr.h" #include "nsIFactory.h" @@ -160,7 +162,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -304,7 +306,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -368,7 +370,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp b/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp index e65aec356f0..51441bf5583 100644 --- a/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp +++ b/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp @@ -22,6 +22,8 @@ #define NS_IMPL_IDS +#include "nspr.h" +#include "nsString.h" #include "pratom.h" #include "nsCOMPtr.h" #include "nsIFactory.h" @@ -250,7 +252,7 @@ public: static nsConverterModule * gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -394,7 +396,7 @@ NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -458,7 +460,7 @@ done: } NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { // XXX also delete the stuff I added to the registry diff --git a/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp b/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp index d7fb08516fb..a727d6e4d6c 100644 --- a/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp +++ b/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp @@ -30,6 +30,8 @@ #include "nsEntityConverter.h" #include "nsSaveAsCharset.h" #include "nsUUDll.h" +#include "nsFileSpec.h" +#include "nsIFile.h" // Functions used to create new instances of a given object by the // generic factory. diff --git a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp index b573be6c7bb..877217f2132 100644 --- a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -23,6 +23,7 @@ #include "nsCOMPtr.h" #include "nsISupports.h" #include "nsIModule.h" +#include "nsILocalFile.h" #include "mozJSComponentLoader.h" #include "nsIGenericFactory.h" #include "nsIJSRuntimeService.h" @@ -32,7 +33,6 @@ #include "nsIAllocator.h" #include "nsIRegistry.h" #include "nsXPIDLString.h" - const char mozJSComponentLoaderProgID[] = "moz.jsloader.1"; const char jsComponentTypeName[] = "text/javascript"; /* XXX export properly from libxpcom, for now this will let Mac build */ @@ -282,13 +282,13 @@ mozJSComponentLoader::ReallyInit() NS_IMETHODIMP mozJSComponentLoader::AutoRegisterComponents(PRInt32 when, - nsIFileSpec *aDirectory) + nsIFile *aDirectory) { return RegisterComponentsInDir(when, aDirectory); } nsresult -mozJSComponentLoader::RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir) +mozJSComponentLoader::RegisterComponentsInDir(PRInt32 when, nsIFile *dir) { nsresult rv; PRBool isDir; @@ -299,38 +299,42 @@ mozJSComponentLoader::RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir) if (!isDir) return NS_ERROR_INVALID_ARG; - nsCOMPtr dirIterator; - rv = mCompMgr->CreateInstanceByProgID(NS_DIRECTORYITERATOR_PROGID, NULL, - NS_GET_IID(nsIDirectoryIterator), - getter_AddRefs(dirIterator)); - if (NS_FAILED(rv)) - return rv; - if (NS_FAILED(rv = dirIterator->Init(dir, PR_FALSE))) - return rv; + // Create a directory iterator + nsCOMPtr dirIterator; + rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator)); - nsCOMPtr dirEntry; - PRBool more; - if (NS_FAILED(rv = dirIterator->Exists(&more))) - return rv; - while(more) { - rv = dirIterator->GetCurrentSpec(getter_AddRefs(dirEntry)); - if (NS_FAILED(rv)) - return rv; - - if (NS_FAILED(rv = dirEntry->IsDirectory(&isDir))) - return rv; + if (NS_FAILED(rv)) return rv; + + // whip through the directory to register every file + nsIFile *dirEntry = NULL; + PRBool more = PR_FALSE; - if (!isDir) { - PRBool registered; - rv = AutoRegisterComponent(when, dirEntry, ®istered); - } else { - rv = RegisterComponentsInDir(when, dirEntry); + rv = dirIterator->HasMoreElements(&more); + if (NS_FAILED(rv)) return rv; + while (more == PR_TRUE) + { + rv = dirIterator->GetNext((nsISupports**)&dirEntry); + if (NS_SUCCEEDED(rv)) + { + rv = dirEntry->IsDirectory(&isDir); + if (NS_SUCCEEDED(rv)) + { + if (isDir == PR_TRUE) + { + // This is a directory. Grovel for components into the directory. + rv = RegisterComponentsInDir(when, dirEntry); + } + else + { + PRBool registered; + // This is a file. Try to register it. + rv = AutoRegisterComponent(when, dirEntry, ®istered); + } + } + NS_RELEASE(dirEntry); } - - if (NS_FAILED(rv = dirIterator->Next())) - return rv; - if (NS_FAILED(rv = dirIterator->Exists(&more))) - return rv; + rv = dirIterator->HasMoreElements(&more); + if (NS_FAILED(rv)) return rv; } return NS_OK; @@ -338,7 +342,7 @@ mozJSComponentLoader::RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir) nsresult mozJSComponentLoader::SetRegistryInfo(const char *registryLocation, - nsIFileSpec *component) + nsIFile *component) { if (!mRegistry.get()) return NS_OK; // silent failure @@ -354,14 +358,15 @@ mozJSComponentLoader::SetRegistryInfo(const char *registryLocation, if (NS_FAILED(rv)) return rv; - PRUint32 modDate; - if (NS_FAILED(rv = component->GetModDate(&modDate)) || - NS_FAILED(rv = mRegistry->SetInt(key, lastModValueName, modDate))) + PRInt64 modDate; + + if (NS_FAILED(rv = component->GetLastModificationDate(&modDate)) || + NS_FAILED(rv = mRegistry->SetLongLong(key, lastModValueName, &modDate))) return rv; - PRUint32 fileSize; + PRInt64 fileSize; if (NS_FAILED(rv = component->GetFileSize(&fileSize)) || - NS_FAILED(rv = mRegistry->SetInt(key, fileSizeValueName, fileSize))) + NS_FAILED(rv = mRegistry->SetLongLong(key, fileSizeValueName, &fileSize))) return rv; #ifdef DEBUG_shaver_off @@ -374,7 +379,7 @@ mozJSComponentLoader::SetRegistryInfo(const char *registryLocation, PRBool mozJSComponentLoader::HasChanged(const char *registryLocation, - nsIFileSpec *component) + nsIFile *component) { /* if we don't have a registry handle, force registration of component */ @@ -386,19 +391,19 @@ mozJSComponentLoader::HasChanged(const char *registryLocation, return PR_TRUE; /* check modification date */ - PRInt32 regTime; - if (NS_FAILED(mRegistry->GetInt(key, lastModValueName, ®Time))) + PRInt64 regTime, lastTime; + if (NS_FAILED(mRegistry->GetLongLong(key, lastModValueName, ®Time))) return PR_TRUE; - PRBool changed; - if (NS_FAILED(component->ModDateChanged(regTime, &changed)) || changed) + + if (NS_FAILED(component->GetLastModificationDate(&lastTime)) || LL_NE(lastTime, regTime)) return PR_TRUE; /* check file size */ - PRInt32 regSize; - if (NS_FAILED(mRegistry->GetInt(key, fileSizeValueName, ®Size))) + PRInt64 regSize; + if (NS_FAILED(mRegistry->GetLongLong(key, fileSizeValueName, ®Size))) return PR_TRUE; - PRUint32 size = 0; - if (NS_FAILED(component->GetFileSize(&size)) || ((int32)size != regSize)) + PRInt64 size; + if (NS_FAILED(component->GetFileSize(&size)) || LL_NE(size,regSize) ) return PR_TRUE; return PR_FALSE; @@ -406,7 +411,7 @@ mozJSComponentLoader::HasChanged(const char *registryLocation, NS_IMETHODIMP mozJSComponentLoader::AutoRegisterComponent(PRInt32 when, - nsIFileSpec *component, + nsIFile *component, PRBool *registered) { nsresult rv; @@ -451,7 +456,7 @@ mozJSComponentLoader::AutoRegisterComponent(PRInt32 when, } nsresult -mozJSComponentLoader::AttemptRegistration(nsIFileSpec *component, +mozJSComponentLoader::AttemptRegistration(nsIFile *component, PRBool deferred) { nsXPIDLCString registryLocation; @@ -506,7 +511,7 @@ mozJSComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, for (PRUint32 i = 0; i < count; i++) { nsCOMPtr supports; - nsCOMPtr component; + nsCOMPtr component; rv = mDeferredComponents.GetElementAt(i, getter_AddRefs(supports)); if (NS_FAILED(rv)) @@ -541,7 +546,7 @@ mozJSComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, nsIModule * mozJSComponentLoader::ModuleForLocation(const char *registryLocation, - nsIFileSpec *component) + nsIFile *component) { nsIModule *module = nsnull; if (!mInitialized && @@ -616,7 +621,7 @@ mozJSComponentLoader::ModuleForLocation(const char *registryLocation, JSObject * mozJSComponentLoader::GlobalForLocation(const char *aLocation, - nsIFileSpec *component) + nsIFile *component) { JSObject *obj = nsnull; PRBool needRelease = PR_FALSE; @@ -648,12 +653,26 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation, NS_FAILED(cxstack->Push(mContext))) return nsnull; + + nsCOMPtr localFile = do_QueryInterface(component); + + if (!localFile) + return nsnull; + char *location; // declare before first jump to out: jsval retval; - nsXPIDLCString nativePath; - /* XXX MAC: we use strings as file paths, *sigh* */ - component->GetNativePath(getter_Copies(nativePath)); - JSScript *script = JS_CompileFile(mContext, obj, (const char *)nativePath); + nsXPIDLCString displayPath; + FILE* fileHandle; + + localFile->GetPath(getter_Copies(displayPath)); + rv = localFile->OpenANSIFileDesc("r", &fileHandle); + if (NS_FAILED(rv)) + return nsnull; + + JSScript *script = JS_CompileFileHandle(mContext, obj, (const char *)displayPath, fileHandle); + + /* JS will close the filehandle after compilation is complete. */ + if (!script) { #ifdef DEBUG_shaver_off fprintf(stderr, "mJCL: script compilation of %s FAILED\n", @@ -856,7 +875,7 @@ mozJSModule::GetClassObject(nsIComponentManager *aCompMgr, NS_IMETHODIMP mozJSModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -888,7 +907,7 @@ mozJSModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP mozJSModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -945,7 +964,7 @@ NS_NewJSModule(const char* moduleName, } extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr, - nsIFileSpec *location, + nsIFile *location, nsIModule** result) { return NS_NewJSModule("mozJSComponentLoader", diff --git a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h index 52c75085678..9fd92886278 100644 --- a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h +++ b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.h @@ -26,7 +26,8 @@ #include "nsIXPConnect.h" #include "nsIModule.h" #include "nsSupportsArray.h" - +#include "nsIFileSpec.h" +#include "nsIFile.h" extern const char mozJSComponentLoaderProgID[]; extern const char jsComponentTypeName[]; @@ -47,14 +48,14 @@ public: protected: nsresult ReallyInit(); - nsresult AttemptRegistration(nsIFileSpec *component, PRBool deferred); - nsresult RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir); - JSObject *GlobalForLocation(const char *aLocation, nsIFileSpec *component); + nsresult AttemptRegistration(nsIFile *component, PRBool deferred); + nsresult RegisterComponentsInDir(PRInt32 when, nsIFile *dir); + JSObject *GlobalForLocation(const char *aLocation, nsIFile *component); nsIModule *ModuleForLocation(const char *aLocation, - nsIFileSpec *component); - PRBool HasChanged(const char *registryLocation, nsIFileSpec *component); + nsIFile *component); + PRBool HasChanged(const char *registryLocation, nsIFile *component); nsresult SetRegistryInfo(const char *registryLocation, - nsIFileSpec *component); + nsIFile *component); nsIComponentManager* mCompMgr; // weak ref, should make it strong? nsCOMPtr mRegistry; diff --git a/mozilla/js/src/xpconnect/tests/components/xpctest_module.cpp b/mozilla/js/src/xpconnect/tests/components/xpctest_module.cpp index ed507f6bd3c..d3ee7a9621e 100644 --- a/mozilla/js/src/xpconnect/tests/components/xpctest_module.cpp +++ b/mozilla/js/src/xpconnect/tests/components/xpctest_module.cpp @@ -38,6 +38,7 @@ #include "nsCOMPtr.h" #include "nsIModule.h" #include "nsIGenericFactory.h" +#include "nsCRT.h" // XXX progids need to be standardized! static nsModuleComponentInfo components[] = { @@ -63,3 +64,4 @@ static nsModuleComponentInfo components[] = { }; NS_IMPL_NSGETMODULE("xpconnect test", components) + diff --git a/mozilla/layout/build/nsLayoutDLF.cpp b/mozilla/layout/build/nsLayoutDLF.cpp index 18c90c0415a..3e76671ef09 100644 --- a/mozilla/layout/build/nsLayoutDLF.cpp +++ b/mozilla/layout/build/nsLayoutDLF.cpp @@ -504,7 +504,7 @@ static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_ static nsresult RegisterTypes(nsIComponentManager* aCompMgr, const char* aCommand, - nsIFileSpec* aPath, + nsIFile* aPath, char** aTypes) { nsresult rv = NS_OK; @@ -528,7 +528,7 @@ RegisterTypes(nsIComponentManager* aCompMgr, nsresult nsLayoutModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath) + nsIFile* aPath) { nsresult rv; @@ -563,7 +563,7 @@ nsLayoutModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr, void nsLayoutModule::UnregisterDocumentFactories(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath) + nsIFile* aPath) { aCompMgr->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath); } diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 4f7be6a0c3c..b6b2ec38158 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -19,6 +19,8 @@ * * Contributor(s): */ +#include "nspr.h" +#include "nsString.h" #include "nsCOMPtr.h" #include "nsLayoutModule.h" #include "nsLayoutCID.h" @@ -62,7 +64,7 @@ static nsLayoutModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; @@ -350,7 +352,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsLayoutModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -382,7 +384,7 @@ nsLayoutModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsLayoutModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG diff --git a/mozilla/layout/build/nsLayoutModule.h b/mozilla/layout/build/nsLayoutModule.h index 5dc1c143e94..73e77f9bc2b 100644 --- a/mozilla/layout/build/nsLayoutModule.h +++ b/mozilla/layout/build/nsLayoutModule.h @@ -49,10 +49,10 @@ protected: void Shutdown(); nsresult RegisterDocumentFactories(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath); + nsIFile* aPath); void UnregisterDocumentFactories(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath); + nsIFile* aPath); PRBool mInitialized; // static nsIFactory* gFactory; diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index 4c2ed4b8f3e..c9e1021ab8c 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -79,7 +79,7 @@ #include "nsGenericDOMNodeList.h" #include "nsICSSLoader.h" #include "nsIHTTPChannel.h" -#include "nsIFileChannel.h" +#include "nsIFile.h" #include "nsIEventListenerManager.h" #include "nsISelectElement.h" @@ -497,8 +497,11 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, nsCOMPtr fileChannel = do_QueryInterface(aChannel); if (fileChannel) { PRTime modDate; - - rv = fileChannel->GetModDate(&modDate); + + nsCOMPtr file; + rv = fileChannel->GetFile(getter_AddRefs(file)); + if (NS_FAILED(rv)) { return rv; } + rv = file->GetLastModificationDate(&modDate); if (NS_FAILED(rv)) { return rv; } PRExplodedTime prtime; char buf[100]; diff --git a/mozilla/lib/mac/NSStdLib/NSStdLib.exp b/mozilla/lib/mac/NSStdLib/NSStdLib.exp index ce007367216..f25dba859d5 100644 --- a/mozilla/lib/mac/NSStdLib/NSStdLib.exp +++ b/mozilla/lib/mac/NSStdLib/NSStdLib.exp @@ -1005,3 +1005,5 @@ GC_stdout GC_stderr GC_address_to_source MWUnmangle + +FSp_fopen diff --git a/mozilla/lib/mac/NSStdLib/NSStdLib.mcp b/mozilla/lib/mac/NSStdLib/NSStdLib.mcp index d098ace9892e87b599db4f16cf4f50f4a4da4dbf..f51bf3802439b8ac60c2cf605e80ff49246f95e8 100644 GIT binary patch delta 1221 zcmXZcTSyd97zglkX3p+-SudNq-feByE`;RW3`u2M!?fC3g9^lulnByA(n^!9EWGB0 zV~h_Wg&9_q#%w!Ln2KcJOTF|IQNBbFz4VkB*_rjf@O{5?{yRHoc4yA2<8kVE-0UN% zu$BLc?aJKQ_&hWI6>@+b5;Giiu0cUyRh}~``L`CqxP|WX27GjdV zhf2{FSKL(foTm}m-_e`N;gw!reN&6Cu~|K~O6|J6PW~-vA6A}FEha;ue4(vCt#e7G zqaFvJwM1&2t|+P-yNB{Kv5cDoHf3_6WMkuwqFd|ab;>h>p@fihFOs5{NW9HP@`q}N zU+s}LKXxktQP&&WK6AYIcGM}Zu$F2+*VZkj(7%LQah5ssScUdRo5a4SPLY}Nqt6Ff3N@Qs#4Q=q jzv!%9rsaCsYvz?`v&!dKKF!hJ&9Rm+TB;W>v#+NAxO^dK delta 1161 zcmXZbTSyd97zgk=P_5wlUaMc#%Fyw9qrH78bSpy`6pQ(G-_mr6Y4HUF+NF zOe-lZD>mK*2~?m8J)kGlpc#5WZ)kx&a0~Q>e*bk!{s@ZT9T*5ZU=XyzU>E{JVHgaD z5ik-)!RSq$k`#j=7RJGNm;e)D65IxR;4Rn-``~TZ4+r3&p;>IbYcrse{rOHYYr^ej z*a9!X%kT=k3R~d~cn!8eCv1n;A>DW6s9pST#zpG}tUJUvWZ+&V%!1i4XHz;cP)tnp z=Rk@oo|&WxgDDYW@Dz*2;5|4+YX@VJ!~)$2#Bmul6vtrLUe!>$_xw3~Q$x&!s)i~t z*8M}}JXVlrCc3?bc(K2(&QQH&g@p5%O69lAmKI(T<{PCEI@_F~SK8!Umpz_NTD)1S z&4+N~oDh1_PomD}0P(j#_^$m;er;+VkwC*iD=aceF=KUdLt(OmfCU+Gc^oXQe z_{VZJQlYa6CjI^!V&+R$xh1G;b&-gY`Rbyw{GF8XchhPZ@zlD+=8y6(Ty-cUm*>A$ a%Vkod(-}3LB=h+hwcbQ>c=nw7)#D$$Xd|=$ diff --git a/mozilla/mailnews/base/build/nsMsgFactory.cpp b/mozilla/mailnews/base/build/nsMsgFactory.cpp index c67758e900e..50774391d45 100644 --- a/mozilla/mailnews/base/build/nsMsgFactory.cpp +++ b/mozilla/mailnews/base/build/nsMsgFactory.cpp @@ -443,9 +443,9 @@ static Components gComponents[] = { #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) NS_IMETHODIMP nsMsgBaseModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) + nsIFile* aPath, + const char* registryLocation, + const char* componentType) { nsresult rv = NS_OK; @@ -484,8 +484,8 @@ NS_IMETHODIMP nsMsgBaseModule::RegisterSelf(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsMsgBaseModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) + nsIFile* aPath, + const char* registryLocation) { Components* cp = gComponents; Components* end = cp + NUM_COMPONENTS; @@ -512,7 +512,7 @@ NS_IMETHODIMP nsMsgBaseModule::CanUnload(nsIComponentManager *aCompMgr, PRBool * static nsMsgBaseModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/mailnews/db/msgdb/build/nsMsgDBFactory.cpp b/mozilla/mailnews/db/msgdb/build/nsMsgDBFactory.cpp index 70fb6ca6aa4..f36a8a52434 100644 --- a/mozilla/mailnews/db/msgdb/build/nsMsgDBFactory.cpp +++ b/mozilla/mailnews/db/msgdb/build/nsMsgDBFactory.cpp @@ -166,9 +166,9 @@ static Components gComponents[] = { #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) NS_IMETHODIMP nsMsgDBModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) + nsIFile* aPath, + const char* registryLocation, + const char* componentType) { nsresult rv = NS_OK; @@ -187,9 +187,8 @@ NS_IMETHODIMP nsMsgDBModule::RegisterSelf(nsIComponentManager *aCompMgr, return rv; } -NS_IMETHODIMP nsMsgDBModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) +NS_IMETHODIMP nsMsgDBModule::UnregisterSelf(nsIComponentManager* aCompMgr, nsIFile* aPath, + const char* registryLocation) { Components* cp = gComponents; Components* end = cp + NUM_COMPONENTS; @@ -216,7 +215,7 @@ NS_IMETHODIMP nsMsgDBModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *ok static nsMsgDBModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/mailnews/imap/build/nsImapFactory.cpp b/mozilla/mailnews/imap/build/nsImapFactory.cpp index 651c5b952fb..b2e9e1f6d5a 100644 --- a/mozilla/mailnews/imap/build/nsImapFactory.cpp +++ b/mozilla/mailnews/imap/build/nsImapFactory.cpp @@ -237,9 +237,9 @@ static Components gComponents[] = { #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) NS_IMETHODIMP nsMsgImapModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) + nsIFile* aPath, + const char* registryLocation, + const char* componentType) { nsresult rv = NS_OK; @@ -259,8 +259,8 @@ NS_IMETHODIMP nsMsgImapModule::RegisterSelf(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsMsgImapModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) + nsIFile* aPath, + const char* registryLocation) { Components* cp = gComponents; Components* end = cp + NUM_COMPONENTS; @@ -287,7 +287,7 @@ NS_IMETHODIMP nsMsgImapModule::CanUnload(nsIComponentManager *aCompMgr, PRBool * static nsMsgImapModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraFactory.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraFactory.cpp index 1c24f746016..017a5c37f27 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraFactory.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraFactory.cpp @@ -27,7 +27,7 @@ #include "nsIRegistry.h" #include "nsIImportService.h" #include "nsEudoraImport.h" - +#include "nsCRT.h" #include "EudoraDebugLog.h" static NS_DEFINE_CID(kEudoraImportCID, NS_EUDORAIMPORT_CID); @@ -65,7 +65,7 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey) } NS_METHOD EudoraRegister(nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, + nsIFile *aPath, const char *registryLocation, const char *componentType) { @@ -120,4 +120,3 @@ static nsModuleComponentInfo components[] = { NS_IMPL_NSGETMODULE("nsEudoraImportModule", components) - diff --git a/mozilla/mailnews/import/oexpress/nsOEFactory.cpp b/mozilla/mailnews/import/oexpress/nsOEFactory.cpp index 9d433cdb687..155d18e0e1c 100644 --- a/mozilla/mailnews/import/oexpress/nsOEFactory.cpp +++ b/mozilla/mailnews/import/oexpress/nsOEFactory.cpp @@ -31,7 +31,7 @@ #include "nsIRegistry.h" #include "nsIImportService.h" #include "nsOEImport.h" - +#include "nsCRT.h" #include "OEDebugLog.h" static NS_DEFINE_CID(kOEImportCID, NS_OEIMPORT_CID); @@ -69,9 +69,9 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey) } NS_METHOD OERegister(nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, - const char *registryLocation, - const char *componentType) + nsIFile *aPath, + const char *registryLocation, + const char *componentType) { nsresult rv; @@ -122,3 +122,8 @@ static nsModuleComponentInfo components[] = { }; NS_IMPL_NSGETMODULE("nsOEImport", components) + + + + + diff --git a/mozilla/mailnews/import/outlook/src/MapiMessage.h b/mozilla/mailnews/import/outlook/src/MapiMessage.h index afd5a5a3c53..2fd76238038 100644 --- a/mozilla/mailnews/import/outlook/src/MapiMessage.h +++ b/mozilla/mailnews/import/outlook/src/MapiMessage.h @@ -24,7 +24,7 @@ #include "nsUInt32Array.h" #include "nsString.h" - +#include "nsIFileSpec.h" #include "MapiApi.h" diff --git a/mozilla/mailnews/import/src/nsImportFactory.cpp b/mozilla/mailnews/import/src/nsImportFactory.cpp index 3d8ed039918..203033dc8fa 100644 --- a/mozilla/mailnews/import/src/nsImportFactory.cpp +++ b/mozilla/mailnews/import/src/nsImportFactory.cpp @@ -24,7 +24,7 @@ #include "nsIGenericFactory.h" #include "nsIImportService.h" #include "nsImportMimeEncode.h" - +#include "nsCRT.h" #include "ImportDebug.h" @@ -45,7 +45,7 @@ static nsModuleComponentInfo components[] = { } }; -//---------------------------------------------------------------------- + NS_IMPL_NSGETMODULE( "nsImportServiceModule", components) diff --git a/mozilla/mailnews/import/text/src/nsTextFactory.cpp b/mozilla/mailnews/import/text/src/nsTextFactory.cpp index 658e1b38da1..af33319b81c 100644 --- a/mozilla/mailnews/import/text/src/nsTextFactory.cpp +++ b/mozilla/mailnews/import/text/src/nsTextFactory.cpp @@ -71,7 +71,7 @@ nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey) } NS_METHOD TextRegister(nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, + nsIFile *aPath, const char *registryLocation, const char *componentType) { diff --git a/mozilla/mailnews/local/build/nsMsgLocalFactory.cpp b/mozilla/mailnews/local/build/nsMsgLocalFactory.cpp index a0582366b4d..461086b627d 100644 --- a/mozilla/mailnews/local/build/nsMsgLocalFactory.cpp +++ b/mozilla/mailnews/local/build/nsMsgLocalFactory.cpp @@ -282,9 +282,9 @@ static Components gComponents[] = { #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) NS_IMETHODIMP nsMsgLocalModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) + nsIFile* aPath, + const char* registryLocation, + const char* componentType) { nsresult rv = NS_OK; @@ -304,8 +304,8 @@ NS_IMETHODIMP nsMsgLocalModule::RegisterSelf(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsMsgLocalModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) + nsIFile* aPath, + const char* registryLocation) { Components* cp = gComponents; Components* end = cp + NUM_COMPONENTS; @@ -332,8 +332,8 @@ NS_IMETHODIMP nsMsgLocalModule::CanUnload(nsIComponentManager *aCompMgr, PRBool static nsMsgLocalModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, - nsIModule** return_cobj) + nsIFile* aPath, + nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/mailnews/mime/build/nsMimeModule.cpp b/mozilla/mailnews/mime/build/nsMimeModule.cpp index 6d3b23adfb8..d08173aa896 100644 --- a/mozilla/mailnews/mime/build/nsMimeModule.cpp +++ b/mozilla/mailnews/mime/build/nsMimeModule.cpp @@ -193,9 +193,9 @@ static Components gComponents[] = { #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) NS_IMETHODIMP nsMimeModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) + nsIFile* aPath, + const char* registryLocation, + const char* componentType) { nsresult rv = NS_OK; @@ -215,15 +215,15 @@ NS_IMETHODIMP nsMimeModule::RegisterSelf(nsIComponentManager *aCompMgr, } NS_IMETHODIMP nsMimeModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) + nsIFile* aPath, + const char* registryLocation) { Components* cp = gComponents; Components* end = cp + NUM_COMPONENTS; while (cp < end) { aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); - cp++; + cp++; } return NS_OK; @@ -243,7 +243,7 @@ NS_IMETHODIMP nsMimeModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okT static nsMimeModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/modules/libimg/gifcom/nsGIFModule.cpp b/mozilla/modules/libimg/gifcom/nsGIFModule.cpp index c63b1555d13..2e2c3923c80 100644 --- a/mozilla/modules/libimg/gifcom/nsGIFModule.cpp +++ b/mozilla/modules/libimg/gifcom/nsGIFModule.cpp @@ -56,8 +56,8 @@ static nsGIFModule *gModule = NULL; // Module entry point extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, - nsIModule** return_cobj) + nsIFile* aPath, + nsIModule** return_cobj) { nsGIFModule *gifModule; nsresult rv = NS_OK; @@ -169,7 +169,7 @@ nsGIFModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass, NS_IMETHODIMP nsGIFModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, + nsIFile* aPath, const char *registryLocation, const char *componentType) { @@ -177,17 +177,17 @@ nsGIFModule::RegisterSelf(nsIComponentManager *aCompMgr, rv = aCompMgr->RegisterComponentSpec(kGIFDecoderCID, "Netscape GIFDec", "component://netscape/image/decoder&type=image/gif", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); return rv; } NS_IMETHODIMP nsGIFModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, + nsIFile* aPath, const char *registryLocation) { nsresult rv; - rv = aCompMgr->UnregisterComponentSpec(kGIFDecoderCID, location); + rv = aCompMgr->UnregisterComponentSpec(kGIFDecoderCID, aPath); return rv; } diff --git a/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp b/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp index 1f8aead68f8..a0015ba09d9 100644 --- a/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp +++ b/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp @@ -56,7 +56,7 @@ static nsJPGModule *gModule = NULL; // Module entry point extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsJPGModule *module; @@ -169,7 +169,7 @@ nsJPGModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass, NS_IMETHODIMP nsJPGModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, + nsIFile* aPath, const char *registryLocation, const char *componentType) { @@ -177,17 +177,17 @@ nsJPGModule::RegisterSelf(nsIComponentManager *aCompMgr, rv = aCompMgr->RegisterComponentSpec(kJPGDecoderCID, "Netscape JPGDec", "component://netscape/image/decoder&type=image/jpeg", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); return rv; } NS_IMETHODIMP -nsJPGModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, +nsJPGModule::UnregisterSelf(nsIComponentManager *aCompMgr, + nsIFile* aPath, const char *registryLocation) { nsresult rv; - rv = aCompMgr->UnregisterComponentSpec(kJPGDecoderCID, location); + rv = aCompMgr->UnregisterComponentSpec(kJPGDecoderCID, aPath); return rv; } diff --git a/mozilla/modules/libimg/pngcom/nsPNGModule.cpp b/mozilla/modules/libimg/pngcom/nsPNGModule.cpp index d64ae05c931..8ce78eefe2b 100644 --- a/mozilla/modules/libimg/pngcom/nsPNGModule.cpp +++ b/mozilla/modules/libimg/pngcom/nsPNGModule.cpp @@ -55,8 +55,8 @@ static nsPNGModule *gModule = NULL; ////////////////////////////////////////////////////////////////////// // Module entry point -extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFile* aPath, nsIModule** return_cobj) { nsPNGModule *module; @@ -169,7 +169,7 @@ nsPNGModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass, NS_IMETHODIMP nsPNGModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, + nsIFile* aPath, const char *registryLocation, const char *componentType) { @@ -177,17 +177,17 @@ nsPNGModule::RegisterSelf(nsIComponentManager *aCompMgr, rv = aCompMgr->RegisterComponentSpec(kPNGDecoderCID, "Netscape PNGDec", "component://netscape/image/decoder&type=image/png", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); return rv; } NS_IMETHODIMP nsPNGModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, + nsIFile* aPath, const char *registryLocation) { nsresult rv; - rv = aCompMgr->UnregisterComponentSpec(kPNGDecoderCID, location); + rv = aCompMgr->UnregisterComponentSpec(kPNGDecoderCID, aPath); return rv; } diff --git a/mozilla/modules/libjar/nsIZipReader.idl b/mozilla/modules/libjar/nsIZipReader.idl index 1d9f0fbd96b..4bef86929f0 100644 --- a/mozilla/modules/libjar/nsIZipReader.idl +++ b/mozilla/modules/libjar/nsIZipReader.idl @@ -29,7 +29,7 @@ interface nsISimpleEnumerator; interface nsIInputStream; -native nsFileSpec(nsFileSpec&); +interface nsIFile; [scriptable, uuid(6ca5e43e-9632-11d3-8cd9-0060b0fc14a3)] interface nsIZipEntry : nsISupports @@ -47,7 +47,7 @@ interface nsIZipReader : nsISupports /** * Initializes a zip reader after construction. */ - [noscript] void init(in nsFileSpec zipFile); + void init(in nsIFile zipFile); /** * Opens a zip reader. @@ -63,7 +63,7 @@ interface nsIZipReader : nsISupports /** * Extracts a zip entry into a local file specified by outFile. */ - [noscript] void extract(in string zipEntry, in nsFileSpec outFile); + void extract(in string zipEntry, in nsIFile outFile); /** * Returns a nsIZipEntry describing a specified zip entry. diff --git a/mozilla/modules/libjar/nsJAR.cpp b/mozilla/modules/libjar/nsJAR.cpp index 788a75e67f2..d317e484a03 100644 --- a/mozilla/modules/libjar/nsJAR.cpp +++ b/mozilla/modules/libjar/nsJAR.cpp @@ -39,7 +39,7 @@ #include "nsJAR.h" #include "nsJARInputStream.h" -//#include "nsIFile.h" +#include "nsILocalFile.h" #ifndef __gen_nsIFile_h__ #define NS_ERROR_FILE_UNRECONGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1) @@ -99,7 +99,7 @@ nsJAR::~nsJAR() NS_IMPL_ISUPPORTS1(nsJAR, nsIZipReader); NS_IMETHODIMP -nsJAR::Init(nsFileSpec& zipFile) +nsJAR::Init(nsIFile* zipFile) { mZipFile = zipFile; return NS_OK; @@ -108,7 +108,16 @@ nsJAR::Init(nsFileSpec& zipFile) NS_IMETHODIMP nsJAR::Open() { - PRInt32 err = mZip.OpenArchive( nsNSPRPath(mZipFile) ); + nsresult rv; + nsCOMPtr localFile = do_QueryInterface(mZipFile, &rv); + if (NS_FAILED(rv)) return rv; + + PRFileDesc* fd; + rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd); + if (NS_FAILED(rv)) return rv; + + PRInt32 err = mZip.OpenArchiveWithFileDesc(fd); + PR_Close(fd); return ziperr2nsresult(err); } @@ -120,9 +129,19 @@ nsJAR::Close() } NS_IMETHODIMP -nsJAR::Extract(const char *zipEntry, nsFileSpec& outFile) +nsJAR::Extract(const char *zipEntry, nsIFile* outFile) { - PRInt32 err = mZip.ExtractFile(zipEntry, nsNSPRPath(outFile)); + nsresult rv; + nsCOMPtr localFile = do_QueryInterface(outFile, &rv); + if (NS_FAILED(rv)) return rv; + + PRFileDesc* fd; + rv = localFile->OpenNSPRFileDesc(PR_RDWR, 0664, &fd); + if (NS_FAILED(rv)) return rv; + + PRUint16 mode; + PRInt32 err = mZip.ExtractFileToFileDesc(zipEntry, fd, &mode); + PR_Close(fd); return ziperr2nsresult(err); } diff --git a/mozilla/modules/libjar/nsJAR.h b/mozilla/modules/libjar/nsJAR.h index db0a19450b9..3c8abaa1805 100644 --- a/mozilla/modules/libjar/nsJAR.h +++ b/mozilla/modules/libjar/nsJAR.h @@ -28,12 +28,13 @@ #ifndef nsJAR_h__ #define nsJAR_h__ -#include "nsFileSpec.h" +#include "nsIFile.h" #include "nsIZipReader.h" #include "prtypes.h" #include "nsIEnumerator.h" #include "nsZipArchive.h" #include "zipfile.h" +#include "nsCOMPtr.h" class nsIInputStream; @@ -60,7 +61,7 @@ class nsJAR : public nsIZipReader private: - nsFileSpec mZipFile; + nsCOMPtr mZipFile; nsZipArchive mZip; }; diff --git a/mozilla/modules/libjar/nsJARChannel.cpp b/mozilla/modules/libjar/nsJARChannel.cpp index 8ef9134445d..2d9a28bb156 100644 --- a/mozilla/modules/libjar/nsJARChannel.cpp +++ b/mozilla/modules/libjar/nsJARChannel.cpp @@ -20,7 +20,6 @@ #include "nsNetUtil.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" -#include "nsIFileSpec.h" #include "nsSpecialSystemDirectory.h" #include "nsJARChannel.h" #include "nsCRT.h" @@ -28,12 +27,11 @@ #include "nsIURL.h" #include "nsIMIMEService.h" #include "nsAutoLock.h" +#include "nsIFileStreams.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID); static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); - //////////////////////////////////////////////////////////////////////////////// class nsJARDownloadObserver : public nsIStreamObserver @@ -58,18 +56,18 @@ public: "wrong transport"); // after successfully downloading the jar file to the cache, // start the extraction process: - NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr jarCacheFile; - rv = serv->NewChannelFromNativePath(mJarCacheFile.GetNativePathCString(), - mJARChannel->mLoadGroup, - mJARChannel->mCallbacks, - mJARChannel->mLoadAttributes, - nsnull, - mJARChannel->mBufferSegmentSize, - mJARChannel->mBufferMaxSize, - getter_AddRefs(jarCacheFile)); + rv = NS_NewFileChannel(mJarCacheFile, + PR_RDONLY, + nsnull, // XXX content type + 0, // XXX content length + mJARChannel->mLoadGroup, + mJARChannel->mCallbacks, + mJARChannel->mLoadAttributes, + nsnull, + mJARChannel->mBufferSegmentSize, + mJARChannel->mBufferMaxSize, + getter_AddRefs(jarCacheFile)); if (NS_FAILED(rv)) return rv; rv = mJARChannel->ExtractJARElement(jarCacheFile); @@ -78,7 +76,7 @@ public: return rv; } - nsJARDownloadObserver(nsFileSpec& jarCacheFile, nsJARChannel* jarChannel) { + nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel) { NS_INIT_REFCNT(); mJarCacheFile = jarCacheFile; mJARChannel = jarChannel; @@ -90,7 +88,7 @@ public: } protected: - nsFileSpec mJarCacheFile; + nsCOMPtr mJarCacheFile; nsJARChannel* mJARChannel; }; @@ -314,29 +312,35 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, else { // otherwise, we need to download the jar file - nsFileSpec jarCacheFile; - rv = GetCacheFile(jarCacheFile); + nsCOMPtr jarCacheFile; + rv = GetCacheFile(getter_AddRefs(jarCacheFile)); if (NS_FAILED(rv)) return rv; - - if (jarCacheFile.IsFile()) { + + PRBool filePresent; + + rv = jarCacheFile->IsFile(&filePresent); + + if (NS_FAILED(rv)) + return rv; + + if (filePresent) + { // then we've already got the file in the local cache -- no need to download it - - NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv); + NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr jarCacheChannel; - rv = serv->NewChannelFromNativePath(jarCacheFile.GetNativePathCString(), - mLoadGroup, - mCallbacks, - mLoadAttributes, - nsnull, - mBufferSegmentSize, - mBufferMaxSize, - getter_AddRefs(jarCacheChannel)); - + nsCOMPtr jarCacheChannel; + rv = fts->CreateTransport(jarCacheFile, + PR_RDONLY, + mCommand, + mBufferSegmentSize, + mBufferMaxSize, + getter_AddRefs(jarCacheChannel)); if (NS_FAILED(rv)) return rv; - - rv = ExtractJARElement(jarCacheChannel); + + nsCOMPtr fileChannel = do_QueryInterface(jarCacheChannel); + if (fileChannel) return NS_ERROR_FAILURE; + rv = ExtractJARElement(fileChannel); return rv; } @@ -347,7 +351,8 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, // use a file transport to serve as a data pump for the download (done // on some other thread) - rv = fts->CreateTransport(jarCacheFile, mCommand, + nsCOMPtr jarCacheTransport; + rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize, getter_AddRefs(mJarCacheTransport)); if (NS_FAILED(rv)) return rv; @@ -369,16 +374,25 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, } nsresult -nsJARChannel::GetCacheFile(nsFileSpec& cacheFile) +nsJARChannel::GetCacheFile(nsIFile* *cacheFile) { // XXX change later to use the real network cache nsresult rv; - nsSpecialSystemDirectory jarCacheFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - jarCacheFile += "jarCache"; + nsCOMPtr jarCacheFile; + rv = NS_GetSpecialDirectory("xpcom.currentProcess.componentDirectory", + getter_AddRefs(jarCacheFile)); + if (NS_FAILED(rv)) return rv; - if (!jarCacheFile.Exists()) - jarCacheFile.CreateDirectory(); + jarCacheFile->Append("jarCache"); + + PRBool exists; + rv = jarCacheFile->Exists(&exists); + if (NS_FAILED(rv)) return rv; + if (!exists) { + rv = jarCacheFile->Create(nsIFile::DIRECTORY_TYPE, 0664); + if (NS_FAILED(rv)) return rv; + } nsCOMPtr jarBaseURL = do_QueryInterface(mJARBaseURI, &rv); if (NS_FAILED(rv)) return rv; @@ -386,10 +400,11 @@ nsJARChannel::GetCacheFile(nsFileSpec& cacheFile) char* jarFileName; rv = jarBaseURL->GetFileName(&jarFileName); if (NS_FAILED(rv)) return rv; - jarCacheFile += jarFileName; + jarCacheFile->Append(jarFileName); nsCRT::free(jarFileName); - cacheFile = jarCacheFile; + *cacheFile = jarCacheFile; + NS_ADDREF(*cacheFile); return rv; } @@ -606,8 +621,8 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength) getter_AddRefs(mJAR)); if (NS_FAILED(rv)) return rv; - nsFileSpec fs; - rv = mJARBaseFile->GetFileSpec(&fs); + nsCOMPtr fs; + rv = mJARBaseFile->GetFile(getter_AddRefs(fs)); if (NS_FAILED(rv)) return rv; rv = mJAR->Init(fs); diff --git a/mozilla/modules/libjar/nsJARChannel.h b/mozilla/modules/libjar/nsJARChannel.h index e5cac2e6606..a652bc179c4 100644 --- a/mozilla/modules/libjar/nsJARChannel.h +++ b/mozilla/modules/libjar/nsJARChannel.h @@ -28,13 +28,13 @@ #include "nsIJARProtocolHandler.h" #include "nsIJARURI.h" #include "nsIFileSystem.h" -#include "nsIFileChannel.h" +#include "nsIChannel.h" #include "nsIZipReader.h" -#include "nsIFileChannel.h" +#include "nsIChannel.h" #include "nsILoadGroup.h" #include "nsIInterfaceRequestor.h" #include "nsCOMPtr.h" -#include "nsFileSpec.h" +#include "nsIFile.h" class nsIFileChannel; @@ -79,7 +79,7 @@ public: PRUint32 bufferMaxSize); nsresult ExtractJARElement(nsIFileChannel* jarFileChannel); - nsresult GetCacheFile(nsFileSpec& cacheFile); + nsresult GetCacheFile(nsIFile* *cacheFile); friend class nsJARDownloadObserver; diff --git a/mozilla/modules/libjar/nsZipArchive.cpp b/mozilla/modules/libjar/nsZipArchive.cpp index ffcb62ab9d5..9304d47c8a0 100644 --- a/mozilla/modules/libjar/nsZipArchive.cpp +++ b/mozilla/modules/libjar/nsZipArchive.cpp @@ -289,6 +289,22 @@ PRInt32 nsZipArchive::OpenArchive( const char * aArchiveName ) return BuildFileList(); } +PRInt32 nsZipArchive::OpenArchiveWithFileDesc(PRFileDesc* fd) +{ + //-- validate arguments + if (fd == 0) + return ZIP_ERR_PARAM; + + //-- not allowed to do two opens on the same object! + if ( mFd != 0 ) + return ZIP_ERR_GENERAL; + + mFd = fd; + + //-- get table of contents for archive + return BuildFileList(); +} + //--------------------------------------------- // nsZipArchive::CloseArchive //--------------------------------------------- @@ -339,17 +355,17 @@ PRInt32 nsZipArchive::GetItem( const char * aFilename, nsZipItem *result) //--------------------------------------------- // nsZipArchive::ReadInit //--------------------------------------------- -PRInt32 nsZipArchive::ReadInit(const char* aFilename, nsZipRead** aRead) +PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead) { //-- Parameter validity check - if (aFilename == 0 || aRead == 0) + if (zipEntry == 0 || aRead == 0) return ZIP_ERR_PARAM; PRInt32 result; //-- find item and seek to file position nsZipItem* item; - result = ReadInitImpl(aFilename, &item); + result = ReadInitImpl(zipEntry, &item); if (result != ZIP_OK) return result; //-- Create nsZipRead object @@ -429,17 +445,41 @@ PRUint32 nsZipArchive::Available(nsZipRead* aRead) //--------------------------------------------- // nsZipArchive::ExtractFile //--------------------------------------------- -PRInt32 nsZipArchive::ExtractFile(const char* aFilename, const char* aOutname) +PRInt32 nsZipArchive::ExtractFile(const char* zipEntry, const char* aOutname) +{ + PRFileDesc* fOut = PR_Open(aOutname, ZFILE_CREATE, 0644); + if (fOut == 0) + return ZIP_ERR_DISK; + + PRUint16 mode; + PRInt32 status = ExtractFileToFileDesc(zipEntry, fOut, &mode); + PR_Close(fOut); + + if (status != ZIP_OK) { + PR_Delete(aOutname); + } +#if defined(XP_UNIX) || defined(XP_PC) + else { + //-- set extracted file permissions + chmod(aOutname, mode); + } +#endif + return status; +} + +PRInt32 +nsZipArchive::ExtractFileToFileDesc(const char * zipEntry, PRFileDesc* outFD, + PRUint16 *itemModeResult) { //-- sanity check arguments - if ( aFilename == 0 || aOutname == 0 ) + if ( zipEntry == 0 || outFD == 0 ) return ZIP_ERR_PARAM; PRInt32 status; nsZipItem* item; //-- Find item in archive and seek to it - status = ReadInitImpl( aFilename, &item ); + status = ReadInitImpl( zipEntry, &item ); if (status != ZIP_OK) return status; @@ -447,18 +487,18 @@ PRInt32 nsZipArchive::ExtractFile(const char* aFilename, const char* aOutname) switch( item->compression ) { case STORED: - status = CopyItemToDisk( item, aOutname ); + status = CopyItemToDisk( item, outFD ); break; case DEFLATED: - status = InflateItem( item, aOutname, 0 ); + status = InflateItem( item, outFD, 0 ); break; default: //-- unsupported compression type return ZIP_ERR_UNSUPPORTED; } - +#if 0 if (status != ZIP_OK) PR_Delete(aOutname); #if defined(XP_UNIX) || defined(XP_PC) @@ -468,7 +508,8 @@ PRInt32 nsZipArchive::ExtractFile(const char* aFilename, const char* aOutname) chmod(aOutname, item->mode); } #endif - +#endif + *itemModeResult = item->mode; return status; } @@ -784,15 +825,15 @@ PRInt32 nsZipArchive::BuildFileList() //--------------------------------------------- // nsZipArchive::GetFileItem //--------------------------------------------- -nsZipItem* nsZipArchive::GetFileItem( const char * aFilename ) +nsZipItem* nsZipArchive::GetFileItem( const char * zipEntry ) { - PR_ASSERT( aFilename != 0 ); + PR_ASSERT( zipEntry != 0 ); - nsZipItem* item = mFiles[ HashName(aFilename) ]; + nsZipItem* item = mFiles[ HashName(zipEntry) ]; for ( ; item != 0; item = item->next ) { - if ( 0 == PL_strcmp( aFilename, item->name ) ) + if ( 0 == PL_strcmp( zipEntry, item->name ) ) break; //-- found it } @@ -820,12 +861,12 @@ PRUint32 nsZipArchive::HashName( const char* aName ) //--------------------------------------------- // nsZipArchive::ReadInitImpl //--------------------------------------------- -PRInt32 nsZipArchive::ReadInitImpl(const char* aFilename, nsZipItem** aItem) +PRInt32 nsZipArchive::ReadInitImpl(const char* zipEntry, nsZipItem** aItem) { - PR_ASSERT (aFilename != 0); + PR_ASSERT (zipEntry != 0); //-- find file information - *aItem = GetFileItem( aFilename ); + *aItem = GetFileItem( zipEntry ); if ( *aItem == 0 ) return ZIP_ERR_FNF; @@ -883,13 +924,12 @@ PRInt32 nsZipArchive::ReadItem( nsZipRead* aRead, char* aBuf, //--------------------------------------------- // nsZipArchive::CopyItemToDisk //--------------------------------------------- -PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutname ) +PRInt32 nsZipArchive::CopyItemToDisk(const nsZipItem* aItem, PRFileDesc* fOut) { PRInt32 status = ZIP_OK; PRUint32 chunk, pos, size, crc; - PRFileDesc* fOut = 0; - PR_ASSERT( aItem != 0 && aOutname != 0 ); + PR_ASSERT( aItem != 0 && fOut != 0 ); char* buf = (char*)PR_Malloc(ZIP_BUFLEN); if ( buf == 0 ) @@ -901,14 +941,6 @@ PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutna //-- initialize crc crc = crc32(0L, Z_NULL, 0); - //-- open output file - fOut = PR_Open( aOutname, ZFILE_CREATE , 0644); - if ( fOut == 0 ) - { - status = ZIP_ERR_DISK; - goto cleanup; - } - //-- copy chunks until file is done size = aItem->size; for ( pos=0; pos < size; pos += chunk ) @@ -937,10 +969,6 @@ PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutna if ( (status == ZIP_OK) && (crc != aItem->crc32) ) status = ZIP_ERR_CORRUPT; -cleanup: - if ( fOut != 0 ) - PR_Close( fOut ); - PR_FREEIF( buf ); return status; } @@ -949,7 +977,7 @@ cleanup: //--------------------------------------------- // nsZipArchive::InflateItem //--------------------------------------------- -PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname, +PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, PRFileDesc* fOut, char* bigBuf ) /* * This function either inflates an archive item to disk, to the @@ -966,7 +994,6 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname, PRInt32 status = ZIP_OK; PRUint32 chunk, inpos, outpos, size, crc; PRUint32 bigBufSize; - PRFileDesc* fOut = 0; z_stream zs; int zerr; PRBool bInflating = PR_FALSE; @@ -980,7 +1007,7 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname, #endif /* STANDALONE */ // -- if aOutname is null, we'll be writing to a buffer instead of a file - if (aOutname != 0) + if (fOut != 0) { PR_ASSERT( aItem != 0 ); bToFile = PR_TRUE; @@ -1005,17 +1032,6 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, const char* aOutname, //-- We should already be at the correct spot in the archive. //-- ReadInitImpl did the seek(). - if (bToFile) - { - //-- open output file - fOut = PR_Open( aOutname, ZFILE_CREATE, 0644); - if ( fOut == 0 ) - { - status = ZIP_ERR_DISK; - goto cleanup; - } - } - //-- set up the inflate memset( &zs, 0, sizeof(zs) ); zerr = inflateInit2( &zs, -MAX_WBITS ); @@ -1147,8 +1163,6 @@ cleanup: inflateEnd( &zs ); } - if (fOut != 0 ) - PR_Close( fOut ); PR_FREEIF( inbuf ); PR_FREEIF( outbuf ); return status; diff --git a/mozilla/modules/libjar/nsZipArchive.h b/mozilla/modules/libjar/nsZipArchive.h index badc9478ee1..322a6f637b8 100644 --- a/mozilla/modules/libjar/nsZipArchive.h +++ b/mozilla/modules/libjar/nsZipArchive.h @@ -100,7 +100,9 @@ public: * @param aArchiveName full pathname of archive * @return status code */ - PRInt32 OpenArchive( const char * aArchiveName ); + PRInt32 OpenArchive(const char * aArchiveName); + + PRInt32 OpenArchiveWithFileDesc(PRFileDesc* fd); /** * Closes an open archive. @@ -121,11 +123,11 @@ public: * Prepare to read from an item in the archive. Must be called * before any calls to Read or Available * - * @param aFilename name of item in file + * @param zipEntry name of item in file * @param (out) a structure used by Read and Available * @return status code */ - PRInt32 ReadInit( const char* aFilename, nsZipRead** aRead); + PRInt32 ReadInit(const char* zipEntry, nsZipRead** aRead); /** * Read @@ -155,11 +157,14 @@ public: /** * ExtractFile * - * @param aFilename name of file in archive to extract + * @param zipEntry name of file in archive to extract * @param aOutname where to extract on disk * @return status code */ - PRInt32 ExtractFile( const char * aFilename, const char * aOutname ); + PRInt32 ExtractFile( const char * zipEntry, const char * aOutname ); + + PRInt32 ExtractFileToFileDesc(const char * zipEntry, PRFileDesc* outFD, + PRUint16 *itemModeResult); /** * FindInit @@ -195,15 +200,15 @@ private: nsZipArchive(const nsZipArchive& rhs); // prevent copies PRInt32 BuildFileList(); - nsZipItem* GetFileItem( const char * aFilename ); + nsZipItem* GetFileItem( const char * zipEntry ); PRUint32 HashName( const char* aName ); - PRInt32 ReadInitImpl(const char* aFilename, nsZipItem** aItem); + PRInt32 ReadInitImpl(const char* zipEntry, nsZipItem** aItem); PRInt32 ReadItem( nsZipRead* aRead, char* aBuf, PRUint32 aCount, PRUint32* aActual ); - PRInt32 CopyItemToDisk( const nsZipItem* aItem, const char* aOutname ); + PRInt32 CopyItemToDisk( const nsZipItem* aItem, PRFileDesc* outFD ); PRInt32 InflateItem( const nsZipItem* aItem, - const char* aOutname, + PRFileDesc* outFD, char* buf ); PRInt32 ReadInflatedItem( const nsZipItem* aItem, char* inflatedBuf, char* outbuf, diff --git a/mozilla/modules/libreg/xpcom/nsIRegistry.idl b/mozilla/modules/libreg/xpcom/nsIRegistry.idl index 095b82943ae..0813b21b394 100644 --- a/mozilla/modules/libreg/xpcom/nsIRegistry.idl +++ b/mozilla/modules/libreg/xpcom/nsIRegistry.idl @@ -42,6 +42,8 @@ interface nsIRegistry : nsISupports void setString(in nsRegistryKey baseKey, in string path, in string value); PRInt32 getInt(in nsRegistryKey baseKey, in string path); void setInt(in nsRegistryKey baseKey, in string path, in PRInt32 value); + PRInt64 getLongLong(in nsRegistryKey baseKey, in string path); + void setLongLong(in nsRegistryKey baseKey, in string path, inout PRInt64 value); nsRegistryKey addSubtree(in nsRegistryKey baseKey, in string path); void removeSubtree(in nsRegistryKey baseKey, in string path); diff --git a/mozilla/modules/libreg/xpcom/nsRegistry.cpp b/mozilla/modules/libreg/xpcom/nsRegistry.cpp index c764dc36d2b..faf6709dea2 100644 --- a/mozilla/modules/libreg/xpcom/nsRegistry.cpp +++ b/mozilla/modules/libreg/xpcom/nsRegistry.cpp @@ -22,7 +22,7 @@ #include "nsIRegistry.h" #include "nsIEnumerator.h" -#include "nsSpecialSystemDirectory.h" +#include "nsDirectoryService.h" #include "NSReg.h" #include "prmem.h" #include "prlock.h" @@ -30,6 +30,9 @@ #include "nsCRT.h" #include "nsAllocator.h" +#include "nsCOMPtr.h" +#include "nsILocalFile.h" +#include "nsIServiceManager.h" /* extra locking for the paranoid */ /* #define EXTRA_THREADSAFE */ #ifndef EXTRA_THREADSAFE @@ -321,7 +324,7 @@ NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue ) | Vanilla nsRegistry constructor. | ------------------------------------------------------------------------------*/ nsRegistry::nsRegistry() - : mReg(0), mCurRegFile(NULL), mCurRegID(0) { + : mReg(0), mCurRegFile(nsnull), mCurRegID(0) { NS_INIT_REFCNT(); #ifdef EXTRA_THREADSAFE mregLock = PR_NewLock(); @@ -397,16 +400,26 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) { // Ensure existing registry is closed. Close(); + + nsresult rv; + nsCOMPtr registryLocation; - nsSpecialSystemDirectory *registryLocation = NULL; PRBool foundReg = PR_FALSE; switch ( (nsWellKnownRegistry) regid ) { case ApplicationComponentRegistry: - registryLocation = - new nsSpecialSystemDirectory(nsSpecialSystemDirectory::XPCOM_CurrentProcessComponentRegistry); - if (registryLocation != NULL) - foundReg = PR_TRUE; + { + nsCOMPtr directoryService; + rv = nsDirectoryService::Create(nsnull, + NS_GET_IID(nsIProperties), + getter_AddRefs(directoryService)); + if (NS_FAILED(rv)) return rv; + directoryService->Get("xpcom.currentProcess.componentRegistry", NS_GET_IID(nsIFile), + (void**)®istryLocation); + + if (registryLocation != nsnull) + foundReg = PR_TRUE; + } break; default: @@ -417,16 +430,17 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) { return NS_ERROR_REG_BADTYPE; } - const char *regFile = registryLocation->GetNativePathCString(); + char *regFile; + registryLocation->GetPath(®File); // dougt fix... + #ifdef DEBUG_dp printf("nsRegistry: Opening std registry %s\n", regFile); #endif /* DEBUG_dp */ + PR_Lock(mregLock); err = NR_RegOpen((char*)regFile, &mReg ); PR_Unlock(mregLock); - // Cleanup - delete registryLocation; // Store the registry that was opened for optimizing future opens. mCurRegID = regid; @@ -463,7 +477,7 @@ NS_IMETHODIMP nsRegistry::Close() { mReg = 0; if (mCurRegFile) nsCRT::free(mCurRegFile); - mCurRegFile = NULL; + mCurRegFile = nsnull; mCurRegID = 0; } return regerr2nsresult( err ); @@ -607,6 +621,24 @@ NS_IMETHODIMP nsRegistry::GetInt( nsRegistryKey baseKey, const char *path, PRInt return rv; } + +/*---------------------------- nsRegistry::GetLongLong-------------------------- +| This function is just shorthand for fetching a 1-element PRInt64 array. We | +| implement it "manually" using NR_RegGetEntry | +------------------------------------------------------------------------------*/ +NS_IMETHODIMP nsRegistry::GetLongLong( nsRegistryKey baseKey, const char *path, PRInt64 *result ) { + REGERR err = REGERR_OK; + + PR_Lock(mregLock); + + uint32 length = sizeof(PRInt64); + err = NR_RegGetEntry( mReg,(RKEY)baseKey,(char*)path,(void*)result,&length); + + PR_Unlock(mregLock); + + // Convert status. + return regerr2nsresult( err ); +} /*---------------------------- nsRegistry::SetInt ------------------------------ | Write out the value as a one-element PRInt32 array, using NR_RegSetEntry. | ------------------------------------------------------------------------------*/ @@ -625,6 +657,28 @@ NS_IMETHODIMP nsRegistry::SetInt( nsRegistryKey baseKey, const char *path, PRInt return regerr2nsresult( err ); } + + +/*---------------------------- nsRegistry::SetLongLong--------------------------- +| Write out the value as a one-element PRInt64 array, using NR_RegSetEntry. | +------------------------------------------------------------------------------*/ +NS_IMETHODIMP nsRegistry::SetLongLong( nsRegistryKey baseKey, const char *path, PRInt64* value ) { + REGERR err = REGERR_OK; + // Set the contents. + PR_Lock(mregLock); + + err = NR_RegSetEntry( mReg, + (RKEY)baseKey, + (char*)path, + REGTYPE_ENTRY_BYTES, + (void*)value, + sizeof(PRInt64) ); + + PR_Unlock(mregLock); + // Convert result. + return regerr2nsresult( err ); +} + /*-------------------------- nsRegistry::AddSubtree ---------------------------- | Add a new registry subkey with the specified name, using NR_RegAddKey. | ------------------------------------------------------------------------------*/ @@ -1133,7 +1187,7 @@ nsRegistryNode::nsRegistryNode( HREG hReg, char *name, RKEY childKey ) : mReg( hReg ), mChildKey( childKey ) { NS_INIT_REFCNT(); - PR_ASSERT(name != NULL); + PR_ASSERT(name != nsnull); strcpy(mName, name); #ifdef EXTRA_THREADSAFE @@ -1157,7 +1211,7 @@ nsRegistryNode::~nsRegistryNode() | using NR_RegEnumSubkeys. | ------------------------------------------------------------------------------*/ NS_IMETHODIMP nsRegistryNode::GetName( char **result ) { - if (result == NULL) return NS_ERROR_NULL_POINTER; + if (result == nsnull) return NS_ERROR_NULL_POINTER; // Make sure there is a place to put the result. *result = nsCRT::strdup( mName ); if ( !*result ) return NS_ERROR_OUT_OF_MEMORY; @@ -1170,7 +1224,7 @@ NS_IMETHODIMP nsRegistryNode::GetName( char **result ) { ------------------------------------------------------------------------------*/ NS_IMETHODIMP nsRegistryNode::GetKey( nsRegistryKey *r_key ) { nsresult rv = NS_OK; - if (r_key == NULL) return NS_ERROR_NULL_POINTER; + if (r_key == nsnull) return NS_ERROR_NULL_POINTER; *r_key = mChildKey; return rv; } @@ -1298,10 +1352,10 @@ nsRegistryFactory::CreateInstance(nsISupports *aOuter, nsresult rv = NS_OK; nsRegistry* newRegistry; - if(aResult == NULL) { + if(aResult == nsnull) { return NS_ERROR_NULL_POINTER; } else { - *aResult = NULL; + *aResult = nsnull; } if(0 != aOuter) { @@ -1310,7 +1364,7 @@ nsRegistryFactory::CreateInstance(nsISupports *aOuter, NS_NEWXPCOM(newRegistry, nsRegistry); - if(newRegistry == NULL) { + if(newRegistry == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/netwerk/base/public/Makefile.in b/mozilla/netwerk/base/public/Makefile.in index b443e5cac72..8007232d8f9 100644 --- a/mozilla/netwerk/base/public/Makefile.in +++ b/mozilla/netwerk/base/public/Makefile.in @@ -30,6 +30,7 @@ MODULE = necko XPIDL_MODULE = necko_base XPIDLSRCS = \ + nsIFileStreams.idl \ nsIRequest.idl \ nsIChannel.idl \ nsIURI.idl \ diff --git a/mozilla/netwerk/base/public/makefile.win b/mozilla/netwerk/base/public/makefile.win index bc8505c0aeb..73c45ba07be 100644 --- a/mozilla/netwerk/base/public/makefile.win +++ b/mozilla/netwerk/base/public/makefile.win @@ -31,6 +31,7 @@ EXPORTS = \ $(NULL) XPIDLSRCS = \ + .\nsIFileStreams.idl \ .\nsIRequest.idl \ .\nsIChannel.idl \ .\nsIURI.idl \ diff --git a/mozilla/netwerk/base/public/nsIChannel.idl b/mozilla/netwerk/base/public/nsIChannel.idl index 95c930b5c89..3148bb77962 100644 --- a/mozilla/netwerk/base/public/nsIChannel.idl +++ b/mozilla/netwerk/base/public/nsIChannel.idl @@ -29,6 +29,7 @@ interface nsIStreamObserver; interface nsIStreamListener; interface nsILoadGroup; interface nsIInterfaceRequestor; +interface nsIFile; typedef unsigned long nsLoadFlags; @@ -208,6 +209,7 @@ interface nsIChannel : nsIRequest }; +//////////////////////////////////////////////////////////////////////////////// /** * nsIInputStreamChannel is an interface that allows for the initialization @@ -241,3 +243,44 @@ interface nsIInputStreamChannel : nsIChannel } %} + +//////////////////////////////////////////////////////////////////////////////// + +/** + * nsIFileChannel is an interface that allows for the initialization + * of a simple nsIChannel that is constructed from a single nsIFile and + * associated content type. + */ +[scriptable, uuid(6eef6444-c7e3-11d3-8cda-0060b0fc14a3)] +interface nsIFileChannel : nsIChannel +{ + void init(in nsIFile file, + in long mode, + in string contentType, + in long contentLength, + in nsILoadGroup aLoadGroup, + in nsIInterfaceRequestor notificationCallbacks, + in nsLoadFlags loadAttributes, + in nsIURI originalURI, + in unsigned long bufferSegmentSize, + in unsigned long bufferMaxSize); + + readonly attribute nsIFile file; +}; + +%{C++ + +#define NS_FILECHANNEL_CLASSNAME "File Channel" +#define NS_FILECHANNEL_PROGID "component://netscape/network/file-channel" + +#define NS_FILECHANNEL_CID \ +{ /* 7036066e-c7e3-11d3-8cda-0060b0fc14a3 */ \ + 0x7036066e, \ + 0xc7e3, \ + 0x11d3, \ + {0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ +} + +%} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/public/nsIFileTransportService.idl b/mozilla/netwerk/base/public/nsIFileTransportService.idl index dc785bcede6..f5bde0ac187 100644 --- a/mozilla/netwerk/base/public/nsIFileTransportService.idl +++ b/mozilla/netwerk/base/public/nsIFileTransportService.idl @@ -30,15 +30,16 @@ interface nsIFileSystem; interface nsIEventSinkGetter; interface nsIInputStream; interface nsIRunnable; -native nsFileSpec(nsFileSpec&); +interface nsIFile; [scriptable, uuid(57211a60-8c45-11d3-93ac-00104ba0fd40)] interface nsIFileTransportService : nsISupports { - [noscript] nsIChannel createTransport(in nsFileSpec spec, // XXX change to nsIFile later - in string command, - in unsigned long bufferSegmentSize, - in unsigned long bufferMaxSize); + nsIChannel createTransport(in nsIFile file, + in long mode, + in string command, + in unsigned long bufferSegmentSize, + in unsigned long bufferMaxSize); // This version can be used with an existing input stream to serve // as a data pump: diff --git a/mozilla/netwerk/base/public/nsIIOService.idl b/mozilla/netwerk/base/public/nsIIOService.idl index fe100fd84cc..395f31a4d03 100644 --- a/mozilla/netwerk/base/public/nsIIOService.idl +++ b/mozilla/netwerk/base/public/nsIIOService.idl @@ -35,6 +35,9 @@ interface nsIBufferOutputStream; interface nsIFileChannel; interface nsILoadGroup; interface nsILoadGroupObserver; +interface nsIFile; +interface nsIInputStream; +interface nsIOutputStream; [scriptable, uuid(1daf19f0-8ea7-11d3-93ad-00104ba0fd40)] interface nsIIOService : nsISupports @@ -121,18 +124,6 @@ interface nsIIOService : nsISupports */ readonly attribute wstring userAgent; - /** - * This convenience routine first looks up the file protocol handler, and - * then uses it to construct a file channel from a native path string. - */ - nsIFileChannel newChannelFromNativePath(in string nativePath, - in nsILoadGroup aLoadGroup, - in nsIInterfaceRequestor notificationCallbacks, - in nsLoadFlags loadAttributes, - in nsIURI originalURI, - in unsigned long bufferSegmentSize, - in unsigned long bufferMaxSize); - /** * Utility for protocol implementors -- extracts the scheme from a URL * string, consistently and according to spec. @@ -160,6 +151,7 @@ interface nsIIOService : nsISupports * causing the dialer to come up). */ attribute boolean offline; + }; %{C++ diff --git a/mozilla/netwerk/base/public/nsIURL.idl b/mozilla/netwerk/base/public/nsIURL.idl index 16c2b1b1ccb..e4d8cd5785d 100644 --- a/mozilla/netwerk/base/public/nsIURL.idl +++ b/mozilla/netwerk/base/public/nsIURL.idl @@ -133,3 +133,16 @@ interface nsIURL : nsIURI } %} + +//////////////////////////////////////////////////////////////////////////////// + +interface nsIFile; + +/** + * nsIFileURL is used for the file: protocol, and gives access to the + * underlying nsIFile object. + */ +interface nsIFileURL : nsIURL +{ + attribute nsIFile file; +}; diff --git a/mozilla/netwerk/base/public/nsNetUtil.h b/mozilla/netwerk/base/public/nsNetUtil.h index a106f2cc633..c66daa2ee75 100644 --- a/mozilla/netwerk/base/public/nsNetUtil.h +++ b/mozilla/netwerk/base/public/nsNetUtil.h @@ -30,7 +30,6 @@ #include "nsILoadGroup.h" #include "nsIInterfaceRequestor.h" #include "nsString.h" - #include "nsIIOService.h" #include "nsIServiceManager.h" #include "nsIChannel.h" diff --git a/mozilla/netwerk/base/src/Makefile.in b/mozilla/netwerk/base/src/Makefile.in index 0b295bfdcc0..d24a3005812 100644 --- a/mozilla/netwerk/base/src/Makefile.in +++ b/mozilla/netwerk/base/src/Makefile.in @@ -30,6 +30,7 @@ MODULE = necko LIBRARY_NAME = neckobase_s CPPSRCS = \ + nsFileStreams.cpp \ nsAsyncStreamListener.cpp \ nsSyncStreamListener.cpp \ nsIOService.cpp \ diff --git a/mozilla/netwerk/base/src/makefile.win b/mozilla/netwerk/base/src/makefile.win index 0a4d65763ea..bec646f4188 100644 --- a/mozilla/netwerk/base/src/makefile.win +++ b/mozilla/netwerk/base/src/makefile.win @@ -27,6 +27,8 @@ LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET LIBRARY_NAME=neckobase_s CPP_OBJS = \ + .\$(OBJDIR)\nsFileStreams.obj \ + .\$(OBJDIR)\nsBufferedStreams.obj \ .\$(OBJDIR)\nsAsyncStreamListener.obj \ .\$(OBJDIR)\nsSyncStreamListener.obj \ .\$(OBJDIR)\nsIOService.obj \ diff --git a/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp b/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp index a67817965bc..f421442c71f 100644 --- a/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp +++ b/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp @@ -33,42 +33,39 @@ nsDirectoryIndexStream::nsDirectoryIndexStream() - : mOffset(0), - mIter(nsnull) + : mOffset(0) { NS_INIT_REFCNT(); } - nsresult -nsDirectoryIndexStream::Init(const nsFileSpec& aDir) +nsDirectoryIndexStream::Init(nsIFile* aDir) { - NS_PRECONDITION(aDir.IsDirectory(), "not a directory"); - if (! aDir.IsDirectory()) + nsresult rv; + PRBool isDir; + rv = aDir->IsDirectory(&isDir); + if (NS_FAILED(rv)) return rv; + NS_PRECONDITION(isDir, "not a directory"); + if (!isDir) return NS_ERROR_ILLEGAL_VALUE; mDir = aDir; // Sigh. We have to allocate on the heap because there are no // assignment operators defined. - mIter = new nsDirectoryIterator(mDir, PR_FALSE); // rjc: don't resolve aliases - if (! mIter) - return NS_ERROR_OUT_OF_MEMORY; + rv = mDir->GetDirectoryEntries(getter_AddRefs(mIter)); + if (NS_FAILED(rv)) return rv; - mBuf = "200: filename content-length last-modified file-type\n"; + mBuf = "200: filename content-length last-modified file-type\n"; return NS_OK; } - nsDirectoryIndexStream::~nsDirectoryIndexStream() { - delete mIter; } - - nsresult -nsDirectoryIndexStream::Create(const nsFileSpec& aDir, nsIInputStream** aResult) +nsDirectoryIndexStream::Create(nsIFile* aDir, nsIInputStream** aResult) { nsDirectoryIndexStream* result = new nsDirectoryIndexStream(); if (! result) @@ -86,29 +83,9 @@ nsDirectoryIndexStream::Create(const nsFileSpec& aDir, nsIInputStream** aResult) return NS_OK; } -NS_IMPL_ADDREF(nsDirectoryIndexStream); -NS_IMPL_RELEASE(nsDirectoryIndexStream); - -NS_IMETHODIMP -nsDirectoryIndexStream::QueryInterface(REFNSIID aIID, void** aResult) -{ - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(NS_GET_IID(nsIInputStream)) || - aIID.Equals(NS_GET_IID(nsIBaseStream)) || - aIID.Equals(NS_GET_IID(nsISupports))) { - *aResult = NS_STATIC_CAST(nsIInputStream*, this); - NS_ADDREF(this); - return NS_OK; - } - else { - *aResult = nsnull; - return NS_NOINTERFACE; - } -} - +NS_IMPL_ISUPPORTS2(nsDirectoryIndexStream, + nsIInputStream, + nsIBaseStream) NS_IMETHODIMP nsDirectoryIndexStream::Close() @@ -116,14 +93,15 @@ nsDirectoryIndexStream::Close() return NS_OK; } - - NS_IMETHODIMP nsDirectoryIndexStream::Available(PRUint32* aLength) { // Lie, and tell the caller that the stream is endless (until we // actually don't have anything left). - if (mIter->Exists()) { + PRBool more; + nsresult rv = mIter->HasMoreElements(&more); + if (NS_FAILED(rv)) return rv; + if (more) { *aLength = PRUint32(-1); return NS_OK; } @@ -133,7 +111,6 @@ nsDirectoryIndexStream::Available(PRUint32* aLength) } } - NS_IMETHODIMP nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) { @@ -153,15 +130,29 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) mBuf.Truncate(); // Okay, now we'll suck stuff off of our iterator into the mBuf... - while (PRUint32(mBuf.Length()) < aCount && mIter->Exists()) { - nsFileSpec current = mIter->Spec(); - ++(*mIter); + while (PRUint32(mBuf.Length()) < aCount) { + PRBool more; + nsresult rv = mIter->HasMoreElements(&more); + if (NS_FAILED(rv)) return rv; + if (!more) break; + + nsCOMPtr cur; + rv = mIter->GetNext(getter_AddRefs(cur)); + nsCOMPtr current = do_QueryInterface(cur, &rv); + if (NS_FAILED(rv)) return rv; - // rjc: don't return hidden files/directories! - if (current.IsHidden()) continue; + // rjc: don't return hidden files/directories! + PRBool hidden; + rv = current->IsHidden(&hidden); + if (NS_FAILED(rv)) return rv; + if (hidden) continue; + char* path; + rv = current->GetPath(&path); + if (NS_FAILED(rv)) return rv; PRFileInfo fileinfo; - PRStatus status = PR_GetFileInfo(nsNSPRPath(current), &fileinfo); + PRStatus status = PR_GetFileInfo(path, &fileinfo); + nsCRT::free(path); if (status != PR_SUCCESS) continue; @@ -169,7 +160,9 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) // The "filename" field { - char* leafname = current.GetLeafName(); + char* leafname; + rv = current->GetLeafName(&leafname); + if (NS_FAILED(rv)) return rv; if (leafname) { char* escaped = nsEscape(leafname, url_Path); if (escaped) { @@ -195,14 +188,27 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) } // The "file-type" field - if (current.IsFile()) { + PRBool isFile; + rv = current->IsFile(&isFile); + if (NS_FAILED(rv)) return rv; + if (isFile) { mBuf += "FILE "; } - else if (current.IsDirectory()) { - mBuf += "DIRECTORY "; - } - else if (current.IsSymlink()) { - mBuf += "SYMBOLIC-LINK "; + else { + PRBool isDir; + rv = current->IsDirectory(&isDir); + if (NS_FAILED(rv)) return rv; + if (isDir) { + mBuf += "DIRECTORY "; + } + else { + PRBool isLink; + rv = current->IsSymlink(&isLink); + if (NS_FAILED(rv)) return rv; + if (isLink) { + mBuf += "SYMBOLIC-LINK "; + } + } } mBuf.Append('\n'); diff --git a/mozilla/netwerk/base/src/nsDirectoryIndexStream.h b/mozilla/netwerk/base/src/nsDirectoryIndexStream.h index d79ee315be0..e9eee1e82cd 100644 --- a/mozilla/netwerk/base/src/nsDirectoryIndexStream.h +++ b/mozilla/netwerk/base/src/nsDirectoryIndexStream.h @@ -23,10 +23,10 @@ #ifndef nsDirectoryIndexStream_h__ #define nsDirectoryIndexStream_h__ - -#include "nsFileSpec.h" +#include "nsIFile.h" #include "nsString.h" #include "nsIInputStream.h" +#include "nsCOMPtr.h" class nsDirectoryIndexStream : public nsIInputStream { @@ -34,16 +34,16 @@ protected: nsCAutoString mBuf; PRInt32 mOffset; - nsFileSpec mDir; - nsDirectoryIterator* mIter; + nsCOMPtr mDir; + nsCOMPtr mIter; nsDirectoryIndexStream(); - nsresult Init(const nsFileSpec& aDir); + nsresult Init(nsIFile* aDir); virtual ~nsDirectoryIndexStream(); public: static nsresult - Create(const nsFileSpec& aDir, nsIInputStream** aStreamResult); + Create(nsIFile* aDir, nsIInputStream** aStreamResult); // nsISupportsInterface NS_DECL_ISUPPORTS diff --git a/mozilla/netwerk/base/src/nsFileTransport.cpp b/mozilla/netwerk/base/src/nsFileTransport.cpp index 8d7328980b5..67fe5f9f250 100644 --- a/mozilla/netwerk/base/src/nsFileTransport.cpp +++ b/mozilla/netwerk/base/src/nsFileTransport.cpp @@ -32,8 +32,7 @@ #include "nsIBufferOutputStream.h" #include "nsAutoLock.h" #include "netCore.h" -#include "nsFileStream.h" -#include "nsIFileStream.h" +#include "nsIFileStreams.h" #include "nsISimpleEnumerator.h" #include "nsIURL.h" #include "prio.h" @@ -43,9 +42,9 @@ #include "nsDirectoryIndexStream.h" #include "nsEscape.h" #include "nsIMIMEService.h" -#include "prlog.h" #include "nsProxyObjectManager.h" #include "nsNetUtil.h" +#include "nsInt64.h" static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID); static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); @@ -88,15 +87,23 @@ public: // exhausted". (Conveniently, a filespec will return "0" for a // directory's length, so our directory HTTP index stream will // just do the right thing.) - *contentLength = mSpec.GetFileSize(); + PRInt64 size; + rv = mFile->GetFileSize(&size); + if (NS_FAILED(rv)) return rv; + *contentLength = nsInt64(size); if (! *contentLength) *contentLength = -1; - if (mSpec.IsDirectory()) { + PRBool isDir; + rv = mFile->IsDirectory(&isDir); + if (NS_FAILED(rv)) return rv; + if (isDir) { *contentType = nsCRT::strdup("application/http-index-format"); } else { - char* fileName = mSpec.GetLeafName(); + char* fileName; + rv = mFile->GetLeafName(&fileName); + if (NS_FAILED(rv)) return rv; if (fileName != nsnull) { PRInt32 len = nsCRT::strlen(fileName); const char* ext = nsnull; @@ -145,44 +152,56 @@ public: NS_IMETHOD GetInputStream(nsIInputStream * *aInputStream) { nsresult rv; - if (mSpec.IsDirectory()) { - rv = nsDirectoryIndexStream::Create(mSpec, aInputStream); + PRBool isDir; + rv = mFile->IsDirectory(&isDir); + if (NS_FAILED(rv)) return rv; + if (isDir) { + rv = nsDirectoryIndexStream::Create(mFile, aInputStream); PR_LOG(gFileTransportLog, PR_LOG_DEBUG, ("nsFileTransport: opening local dir %s for input (%x)", (const char*)mSpec, rv)); return rv; } - nsCOMPtr in; - rv = NS_NewTypicalInputFileStream(getter_AddRefs(in), mSpec); + rv = NS_NewFileInputStream(mFile, aInputStream); PR_LOG(gFileTransportLog, PR_LOG_DEBUG, ("nsFileTransport: opening local file %s for input (%x)", (const char*)mSpec, rv)); - if (NS_FAILED(rv)) return rv; - return in->QueryInterface(NS_GET_IID(nsIInputStream), (void**)aInputStream); + return rv; } NS_IMETHOD GetOutputStream(nsIOutputStream * *aOutputStream) { nsresult rv; - nsCOMPtr out; - if (mSpec.IsDirectory()) { + PRBool isDir; + rv = mFile->IsDirectory(&isDir); + if (NS_FAILED(rv)) return rv; + if (isDir) { return NS_ERROR_FAILURE; } - rv = NS_NewTypicalOutputFileStream(getter_AddRefs(out), mSpec); + rv = NS_NewFileOutputStream(mFile, + PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, + 0664, + aOutputStream); PR_LOG(gFileTransportLog, PR_LOG_DEBUG, ("nsFileTransport: opening local file %s for output (%x)", (const char*)mSpec, rv)); - if (NS_FAILED(rv)) return rv; - return out->QueryInterface(NS_GET_IID(nsIOutputStream), (void**)aOutputStream); + return rv; } - nsLocalFileSystem(nsFileSpec& fileSpec) : mSpec(fileSpec) { + nsLocalFileSystem(nsIFile* file) : mFile(file) { NS_INIT_REFCNT(); +#ifdef PR_LOGGING + (void)mFile->GetPath(&mSpec); +#endif } - virtual ~nsLocalFileSystem() {} + virtual ~nsLocalFileSystem() { +#ifdef PR_LOGGING + if (mSpec) nsCRT::free(mSpec); +#endif + } - static nsresult Create(nsFileSpec& fileSpec, nsIFileSystem* *result) { - nsLocalFileSystem* fs = new nsLocalFileSystem(fileSpec); + static nsresult Create(nsIFile* file, nsIFileSystem* *result) { + nsLocalFileSystem* fs = new nsLocalFileSystem(file); if (fs == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(fs); @@ -191,7 +210,10 @@ public: } protected: - nsFileSpec mSpec; + nsCOMPtr mFile; +#ifdef PR_LOGGING + char* mSpec; +#endif }; NS_IMPL_ISUPPORTS1(nsLocalFileSystem, nsIFileSystem); @@ -279,6 +301,9 @@ nsFileTransport::nsFileTransport() mOffset(0), mTotalAmount(-1), mTransferAmount(0), +#ifdef PR_LOGGING + mSpec(nsnull), +#endif mBuffer(nsnull) { NS_INIT_REFCNT(); @@ -295,13 +320,30 @@ nsFileTransport::nsFileTransport() } nsresult -nsFileTransport::Init(nsFileSpec& spec, const char* command, +nsFileTransport::Init(nsIFile* file, PRInt32 mode, const char* command, PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize) { nsresult rv; - mSpec = spec; + mFile = file; +#if 0 + nsCOMPtr channel; + rv = NS_NewFileChannel(file, + mode, + nsnull, // contentType -- infer + 0, // contentLength -- infer + nsnull, // loadGroup + nsnull, // notificationCallbacks + nsIChannel::LOAD_NORMAL, + nsnull, // originalURI + bufferSegmentSize, + bufferMaxSize, + getter_AddRefs(channel)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr fsObj = do_QueryInterface(channel, &rv); +#else nsCOMPtr fsObj; - rv = nsLocalFileSystem::Create(spec, getter_AddRefs(fsObj)); + rv = nsLocalFileSystem::Create(file, getter_AddRefs(fsObj)); +#endif if (NS_FAILED(rv)) return rv; return Init(fsObj, command, bufferSegmentSize, bufferMaxSize); } @@ -334,6 +376,12 @@ nsFileTransport::Init(nsIFileSystem* fsObj, const char* command, ? bufferSegmentSize : NS_FILE_TRANSPORT_DEFAULT_SEGMENT_SIZE; mBufferMaxSize = bufferMaxSize != 0 ? bufferMaxSize : NS_FILE_TRANSPORT_DEFAULT_BUFFER_SIZE; +#ifdef PR_LOGGING + if (mFile) + (void)mFile->GetPath(&mSpec); + else + mSpec = nsCRT::strdup(""); +#endif return rv; } @@ -351,6 +399,10 @@ nsFileTransport::~nsFileTransport() nsAutoMonitor::DestroyMonitor(mMonitor); if (mContentType) nsCRT::free(mContentType); +#ifdef PR_LOGGING + if (mSpec) + nsCRT::free(mSpec); +#endif } NS_IMETHODIMP @@ -479,7 +531,11 @@ nsFileTransport::OpenInputStream(PRUint32 startPosition, PRInt32 readCount, if (mState != CLOSED) return NS_ERROR_IN_PROGRESS; - if (!mSpec.Exists()) + PRBool exists; + rv = mFile->Exists(&exists); + if (NS_FAILED(rv)) return rv; + + if (!exists) return NS_ERROR_FAILURE; // XXX probably need NS_BASE_STREAM_FILE_NOT_FOUND or something rv = NS_NewPipe(getter_AddRefs(mBufferInputStream), @@ -521,10 +577,15 @@ nsFileTransport::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **resu if (mState != CLOSED) return NS_ERROR_IN_PROGRESS; - nsCOMPtr str; - rv = NS_NewTypicalIOFileStream(getter_AddRefs(str), mSpec); + nsCOMPtr str; + rv = NS_NewFileOutputStream(mFile, + PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, + 0664, + getter_AddRefs(str)); if (NS_FAILED(rv)) return rv; - rv = str->QueryInterface(NS_GET_IID(nsIOutputStream), (void**)result); + + *result = str; + NS_ADDREF(*result); mOffset = startPosition; if (mOffset > 0) { diff --git a/mozilla/netwerk/base/src/nsFileTransport.h b/mozilla/netwerk/base/src/nsFileTransport.h index 1293f059456..2962d70714f 100644 --- a/mozilla/netwerk/base/src/nsFileTransport.h +++ b/mozilla/netwerk/base/src/nsFileTransport.h @@ -37,6 +37,8 @@ #include "nsIBufferOutputStream.h" #include "nsIFileSystem.h" #include "nsIInterfaceRequestor.h" +#include "nsIFile.h" +#include "prlog.h" class nsIInterfaceRequestor; @@ -59,7 +61,8 @@ public: static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult); - nsresult Init(nsFileSpec& spec, + nsresult Init(nsIFile* file, + PRInt32 mode, const char* command, PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize); @@ -97,9 +100,9 @@ public: }; protected: + nsCOMPtr mFile; nsCOMPtr mCallbacks; nsCOMPtr mProgress; - nsFileSpec mSpec; // eliminate? nsCOMPtr mFileObject; char* mContentType; PRUint32 mBufferSegmentSize; @@ -130,6 +133,10 @@ protected: nsCOMPtr mObserver; nsCOMPtr mSink; char* mBuffer; + +#ifdef PR_LOGGING + char* mSpec; +#endif }; #define NS_FILE_TRANSPORT_DEFAULT_SEGMENT_SIZE (2*1024) diff --git a/mozilla/netwerk/base/src/nsFileTransportService.cpp b/mozilla/netwerk/base/src/nsFileTransportService.cpp index f0c457530f7..510a537284a 100644 --- a/mozilla/netwerk/base/src/nsFileTransportService.cpp +++ b/mozilla/netwerk/base/src/nsFileTransportService.cpp @@ -81,7 +81,8 @@ nsFileTransportService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResul //////////////////////////////////////////////////////////////////////////////// NS_IMETHODIMP -nsFileTransportService::CreateTransport(nsFileSpec& spec, +nsFileTransportService::CreateTransport(nsIFile* file, + PRInt32 mode, const char* command, PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize, @@ -92,7 +93,7 @@ nsFileTransportService::CreateTransport(nsFileSpec& spec, if (trans == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(trans); - rv = trans->Init(spec, command, bufferSegmentSize, bufferMaxSize); + rv = trans->Init(file, mode, command, bufferSegmentSize, bufferMaxSize); if (NS_FAILED(rv)) { NS_RELEASE(trans); return rv; diff --git a/mozilla/netwerk/base/src/nsIOService.cpp b/mozilla/netwerk/base/src/nsIOService.cpp index 509b35e24bb..6fe274f5e66 100644 --- a/mozilla/netwerk/base/src/nsIOService.cpp +++ b/mozilla/netwerk/base/src/nsIOService.cpp @@ -32,9 +32,7 @@ #include "prprf.h" #include "prmem.h" // for PR_Malloc #include "prsystem.h" // for PR_GetSystemInfo -#include "nsIFileProtocolHandler.h" // for NewChannelFromNativePath #include "nsLoadGroup.h" -#include "nsIFileChannel.h" #include "nsInputStreamChannel.h" #include "nsXPIDLString.h" @@ -367,40 +365,6 @@ nsIOService::GetUserAgent(PRUnichar* *aUserAgent) return NS_OK; } -NS_IMETHODIMP -nsIOService::NewChannelFromNativePath(const char *nativePath, - nsILoadGroup* aLoadGroup, - nsIInterfaceRequestor* notificationCallbacks, - nsLoadFlags loadAttributes, - nsIURI* originalURI, - PRUint32 bufferSegmentSize, - PRUint32 bufferMaxSize, - nsIFileChannel **result) -{ - nsresult rv; - nsCOMPtr handler; - rv = GetProtocolHandler("file", getter_AddRefs(handler)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr fileHandler = do_QueryInterface(handler, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr channel; - rv = fileHandler->NewChannelFromNativePath(nativePath, - aLoadGroup, - notificationCallbacks, - loadAttributes, - originalURI, - bufferSegmentSize, - bufferMaxSize, - getter_AddRefs(channel)); - if (NS_FAILED(rv)) return rv; - - *result = channel; - NS_ADDREF(*result); - return NS_OK; -} - NS_IMETHODIMP nsIOService::GetOffline(PRBool *offline) { diff --git a/mozilla/netwerk/base/src/nsStdURL.cpp b/mozilla/netwerk/base/src/nsStdURL.cpp index 53a3ff5dcbf..c74ea62dd97 100644 --- a/mozilla/netwerk/base/src/nsStdURL.cpp +++ b/mozilla/netwerk/base/src/nsStdURL.cpp @@ -27,7 +27,8 @@ #include "prmem.h" #include "prprf.h" #include "nsXPIDLString.h" -#include "nsCOMPtr.h" +#include "nsILocalFile.h" +#include "nsEscape.h" static NS_DEFINE_CID(kStdURLCID, NS_STANDARDURL_CID); static NS_DEFINE_CID(kThisStdURLImplementationCID, @@ -1279,3 +1280,77 @@ nsStdURL::SetFileBaseName(const char *name) { return NS_ERROR_NOT_IMPLEMENTED; } + +//////////////////////////////////////////////////////////////////////////////// +// nsIFileURL methods: + +NS_IMETHODIMP +nsStdURL::GetFile(nsIFile * *aFile) +{ + nsresult rv; + if (mFile) { + *aFile = mFile; + NS_ADDREF(*aFile); + return NS_OK; + } + + // if we didn't have an nsIFile already, then synthesize one and cache it + + if (nsCRT::strcasecmp(mScheme, "file") != 0) { + // if this isn't a file: URL, then we can't return an nsIFile + return NS_ERROR_FAILURE; + } + + NS_ASSERTION(mPreHost == nsnull, "file: with mPreHost"); + + // we do not use the path cause it can contain the # char + nsCAutoString path(mDirectory); + path.Append(mFileName); +#ifdef XP_PC + if (path.CharAt(2) == '|') { + path.SetCharAt(':', 2); + // cut off the leading '/' + if (path.CharAt(0) == '/') + path.Cut(0, 1); + } + path.ReplaceChar('/', '\\'); +#elif defined(XP_MAC) + // For now we'll just convert the /'s into :'s to make it look like a Mac path + // at some point we need to doa better job - FIX ME!!!!!!! + path.ReplaceChar('/', ':'); + if (path.CharAt(0) == ':') + path.Cut(0, 1); +#endif + + // we need to make sure that the filepath is unescaped! + + char* escapedPath = (char*) nsAllocator::Clone((void*)(const char*)path,strlen(path)); + nsUnescape(escapedPath); + + nsCOMPtr localFile; + rv = NS_NewLocalFile(escapedPath, getter_AddRefs(localFile)); + + nsAllocator::Free(escapedPath); + + mFile = localFile; + *aFile = mFile; + NS_IF_ADDREF(*aFile); + return rv; +} + +NS_IMETHODIMP +nsStdURL::SetFile(nsIFile * aFile) +{ + nsresult rv; + mFile = aFile; + + // set up this URL to denote the nsIFile + SetScheme("file"); + + rv = mFile->GetPath(&mPath); + if (NS_FAILED(rv)) return rv; + + return ParsePath(); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsStdURL.h b/mozilla/netwerk/base/src/nsStdURL.h index 6d878d18db7..21a19b0d3d4 100644 --- a/mozilla/netwerk/base/src/nsStdURL.h +++ b/mozilla/netwerk/base/src/nsStdURL.h @@ -27,6 +27,8 @@ #include "nsAgg.h" #include "nsCRT.h" #include "nsString.h" // REMOVE Later!! +#include "nsCOMPtr.h" +#include "nsIFile.h" #define NS_THIS_STANDARDURL_IMPLEMENTATION_CID \ { /* e3939dc8-29ab-11d3-8cce-0060b0fc14a3 */ \ @@ -36,9 +38,14 @@ {0x8c, 0xce, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ } -class nsStdURL : public nsIURL +class nsStdURL : public nsIFileURL { public: + NS_DECL_AGGREGATED + NS_DECL_NSIURI + NS_DECL_NSIURL + NS_DECL_NSIFILEURL + //////////////////////////////////////////////////////////////////////////// // nsStdURL methods: @@ -52,16 +59,6 @@ public: static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - NS_DECL_AGGREGATED - - //////////////////////////////////////////////////////////////////////////// - // nsIURI methods: - NS_DECL_NSIURI - - //////////////////////////////////////////////////////////////////////////// - // nsIURL methods: - NS_DECL_NSIURL - /* todo move this to protected later */ nsresult ParsePath(void); @@ -73,8 +70,8 @@ protected: // Some handy functions nsresult DupString(char* *o_Dest, const char* i_Src); nsresult ExtractString(char* i_Src, char* *o_Dest, PRUint32 length); -protected: +protected: char* mScheme; char* mPreHost; char* mHost; @@ -89,6 +86,9 @@ protected: char* mSpec; + // If a file was given to SetFile, then this instance variable holds it. + // If GetFile is called, we synthesize one and cache it here. + nsCOMPtr mFile; }; inline NS_METHOD diff --git a/mozilla/netwerk/build/nsNetModule.cpp b/mozilla/netwerk/build/nsNetModule.cpp index c9a54da87d8..cbcdcf3339c 100644 --- a/mozilla/netwerk/build/nsNetModule.cpp +++ b/mozilla/netwerk/build/nsNetModule.cpp @@ -38,6 +38,7 @@ #include "nsUnicharStreamLoader.h" #include "nsAsyncStreamListener.h" #include "nsSyncStreamListener.h" +#include "nsFileStreams.h" /////////////////////////////////////////////////////////////////////////////// // Module implementation for the net library @@ -98,7 +99,15 @@ static nsModuleComponentInfo gNetModuleInfo[] = { { "Load Group", NS_LOADGROUP_CID, "component://netscape/network/load-group", - nsLoadGroup::Create } + nsLoadGroup::Create }, + { NS_FILEINPUTSTREAM_CLASSNAME, + NS_FILEINPUTSTREAM_CID, + NS_FILEINPUTSTREAM_PROGID, + nsFileInputStream::Create }, + { NS_FILEOUTPUTSTREAM_CLASSNAME, + NS_FILEOUTPUTSTREAM_CID, + NS_FILEOUTPUTSTREAM_PROGID, + nsFileOutputStream::Create } }; NS_IMPL_NSGETMODULE("net", gNetModuleInfo) diff --git a/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.h b/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.h index d5dc7fe2a50..97b5acdedf1 100644 --- a/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.h +++ b/mozilla/netwerk/cache/filecache/nsDiskCacheRecord.h @@ -28,7 +28,7 @@ #include "nsIDBAccessor.h" #include "prtypes.h" #include "nsILoadGroup.h" -#include "nsIFileChannel.h" +#include "nsIChannel.h" #include "nsNetDiskCache.h" class nsDiskCacheRecord : public nsINetDataCacheRecord diff --git a/mozilla/netwerk/macbuild/netwerk.mcp b/mozilla/netwerk/macbuild/netwerk.mcp index 47b05d09feae0a01659f3f78a5361a9dea1a722f..f7418003f29cfd2c659d339bbe7690b61d2d022e 100644 GIT binary patch delta 472 zcmZ4Sj(Np9<_)`rLuD8k7-WGM2IPPY1x6qN#Ku4>0*DhB7+6m-FmM2wKz>?gQE`ca zdQ6NuuL2Mh=Oh*b#liZRfD9lu-Yg(;fn7PT*r_xvEwv~$CAg$0H8HnXFS($AA+Oji zGba@)GWkM+!sZ9A@=TMR`!adId;tg0K}H})P1aW^ z=0$P#WZrOx&EFM-*o0UYg0uiJ5U_3s5)l&}(?Uw VCU5u@&1gQE=d&?T$l>z~W&p{Qiv0ip delta 353 zcmZ4Sj(Np9<_)`rC%Oo@$}li6C@=yEAT|V2VL+U~z`(kYfq?_a1oCGFF*K}ZWY{D+ zGmxQSEhEF`y~#jvus$Xr1BeYb3y54`-+ak6iD|NvTnTRgP*@F!{eakN@@cs*69YIV z@0Tx_>>*st3lu|u$*kcXo4+dvu}yTZnB4n>cXOY5J>a0w-_K;bV6>%gn&w z=DNA|i4fDo0M^NO^rYBb&b(z{aLL+y(e*duaL(0{-A>ppIMh}!}tFM9Wtv0(Fz_u|ZqOD1pl6wRnV Ondh@HP{`r)3uXW#UT~HG diff --git a/mozilla/netwerk/macbuild/netwerkIDL.mcp b/mozilla/netwerk/macbuild/netwerkIDL.mcp index 9a077f6823c68c1542958a8345a273f4dd6d5705..b2f1e94ab171ed6ce06a55d24ce8bebc5be72c25 100644 GIT binary patch delta 629 zcmYMxJxIeq6ae6NNwo1N{-RN9+XPzF!P&tM3jRq~zm(MOcrRzZVse@!v|#@)y=etJ4#FBba8B{3duRQlYe>dTV$o zo(>t+rHVI$XTm#dm_LN~Xa2HSF$JJ#04jDN3I;xpF%%5gE|%VJNY7R{r^lM jV&QnyE;~8AuvhO~ep|#5U00hjJL9{qpE=^ly_bFf#c_Vv delta 560 zcmYk(&r1S96bJA(yIcM!OOxD6(G|2h)L$S$9r`V-iIfzPAVGoRMqb5#z{@hHg)W{t zM71#8I&`dC7mwWn=@NG65JuQrc~T2+KQrGM-psPCw$y4%_O{O#0RWBR3riDuU)Lj! z)vj!2g8ZYRh+_C&GS`>*LA1ahqL!IaL_Stf%*>^;%!`Q=F0=rDNtBkcM+ys-y8vz+ z_UFJBZv3IgeE=^=c+4#3GM1Ng-&t`RAlDI%q$&ma_rZP6UJU_Z&shluVk_NbE-QWu zPNn%>ddLZSy`K~YUySdjb-t60n=6OnIa}K^Gfn4`b;#;^&S^DxB5RxJRqXF2 zB{D|($T4!193dGglWx*Ox=5vO9bkxpVKP9DlYVl743d*%h*Zfba+;hWqog+YQk3z| r)#sv7u9hm!>~AHxf#dn|dG!>3$lJf%5dP~UnO$(h4l_eE>?i3L1P*u0 diff --git a/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp b/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp index f533f0802ac..d8ce0d55ba7 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp @@ -26,10 +26,9 @@ #include "nsIStringStream.h" #include "nsXPIDLString.h" #include "nsIURI.h" -#include "nsSpecialSystemDirectory.h" #include "prtime.h" #include "nsCOMPtr.h" -#include "nsIFileStream.h" +#include "nsIFileStreams.h" #include "nsNetUtil.h" #ifdef XP_MAC @@ -105,11 +104,21 @@ nsAboutBloat::NewChannel(const char *verb, if (NS_FAILED(rv)) return rv; } else { - nsSpecialSystemDirectory file(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - file += "bloatlogs"; + nsCOMPtr file; + rv = NS_GetSpecialDirectory("xpcom.currentProcess.componentRegistry", + getter_AddRefs(file)); + if (NS_FAILED(rv)) return rv; + rv = file->Append("bloatlogs"); + if (NS_FAILED(rv)) return rv; - if (!file.Exists()) - file.CreateDirectory(); + PRBool exists; + rv = file->Exists(&exists); + if (NS_FAILED(rv)) return rv; + + if (!exists) { + rv = file->Create(nsIFile::DIRECTORY_TYPE, 0664); + if (NS_FAILED(rv)) return rv; + } nsCAutoString dumpFileName; if (statType == nsTraceRefcnt::ALL_STATS) @@ -121,9 +130,15 @@ nsAboutBloat::NewChannel(const char *verb, char time[128]; PR_FormatTimeUSEnglish(time, 128, "%Y-%m-%d-%H%M%S.txt", &expTime); dumpFileName += time; - file += (const char*)dumpFileName; + rv = file->Append((const char*)dumpFileName); + if (NS_FAILED(rv)) return rv; - FILE* out = ::fopen(file, "w"); + char* nativePath; + rv = file->GetPath(&nativePath); + if (NS_FAILED(rv)) return rv; + + FILE* out = ::fopen(nativePath, "w"); + nsCRT::free(nativePath); if (out == nsnull) return NS_ERROR_FAILURE; @@ -131,12 +146,11 @@ nsAboutBloat::NewChannel(const char *verb, ::fclose(out); if (NS_FAILED(rv)) return rv; - size = file.GetFileSize(); - - nsCOMPtr in; - rv = NS_NewTypicalInputFileStream(getter_AddRefs(in), file); + PRInt64 bigSize; + rv = file->GetFileSize(&bigSize); if (NS_FAILED(rv)) return rv; - inStr = do_QueryInterface(in, &rv); + + rv = NS_NewFileInputStream(file, getter_AddRefs(inStr)); if (NS_FAILED(rv)) return rv; } diff --git a/mozilla/netwerk/protocol/file/public/MANIFEST_IDL b/mozilla/netwerk/protocol/file/public/MANIFEST_IDL index c2790b00a5d..8b137891791 100644 --- a/mozilla/netwerk/protocol/file/public/MANIFEST_IDL +++ b/mozilla/netwerk/protocol/file/public/MANIFEST_IDL @@ -1,3 +1 @@ -nsIFileChannel.idl -nsIFileProtocolHandler.idl diff --git a/mozilla/netwerk/protocol/file/public/Makefile.in b/mozilla/netwerk/protocol/file/public/Makefile.in index db3ee779c3d..de918254ff4 100644 --- a/mozilla/netwerk/protocol/file/public/Makefile.in +++ b/mozilla/netwerk/protocol/file/public/Makefile.in @@ -30,8 +30,6 @@ MODULE = necko XPIDL_MODULE = necko_file XPIDLSRCS = \ - nsIFileChannel.idl \ - nsIFileProtocolHandler.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/netwerk/protocol/file/public/makefile.win b/mozilla/netwerk/protocol/file/public/makefile.win index 663b0161c6c..b03597d6b8b 100644 --- a/mozilla/netwerk/protocol/file/public/makefile.win +++ b/mozilla/netwerk/protocol/file/public/makefile.win @@ -27,8 +27,6 @@ include <$(DEPTH)/config/config.mak> XPIDL_MODULE = necko_file XPIDLSRCS = \ - .\nsIFileChannel.idl \ - .\nsIFileProtocolHandler.idl \ $(NULL) include <$(DEPTH)/config/rules.mak> diff --git a/mozilla/netwerk/protocol/file/public/nsIFileProtocolHandler.idl b/mozilla/netwerk/protocol/file/public/nsIFileProtocolHandler.idl index 92c9ea29395..1e2e0a4df7b 100644 --- a/mozilla/netwerk/protocol/file/public/nsIFileProtocolHandler.idl +++ b/mozilla/netwerk/protocol/file/public/nsIFileProtocolHandler.idl @@ -23,15 +23,16 @@ #include "nsIProtocolHandler.idl" interface nsIFileChannel; +interface nsIFile; [scriptable, uuid(fa1941f2-3102-11d3-8cd0-0060b0fc14a3)] interface nsIFileProtocolHandler : nsIProtocolHandler { - nsIFileChannel NewChannelFromNativePath(in string nativePath, - in nsILoadGroup aLoadGroup, - in nsIInterfaceRequestor notificationCallbacks, - in nsLoadFlags loadAttributes, - in nsIURI originalURI, - in unsigned long bufferSegmentSize, - in unsigned long bufferMaxSize); + nsIFileChannel newFileChannel(in nsIFile file, + in nsILoadGroup aLoadGroup, + in nsIInterfaceRequestor notificationCallbacks, + in nsLoadFlags loadAttributes, + in nsIURI originalURI, + in unsigned long bufferSegmentSize, + in unsigned long bufferMaxSize); }; diff --git a/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp b/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp index 9d03c485326..27ffbf77e56 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp @@ -21,37 +21,20 @@ */ #include "nsFileChannel.h" -#include "nscore.h" -#include "nsIInterfaceRequestor.h" -#include "nsIURI.h" -#include "nsIEventQueue.h" -#include "nsIStreamListener.h" -#include "nsIIOService.h" -#include "nsIServiceManager.h" -#include "nsFileProtocolHandler.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" -#include "nsAutoLock.h" -#include "netCore.h" -#include "nsFileStream.h" -#include "nsIFileStream.h" -#include "nsISimpleEnumerator.h" #include "nsIURL.h" -#include "prio.h" -#include "prmem.h" // XXX can be removed when we start doing real content-type discovery -#include "nsCOMPtr.h" #include "nsXPIDLString.h" -#include "nsSpecialSystemDirectory.h" -#include "nsEscape.h" +#include "nsIServiceManager.h" #include "nsIMIMEService.h" -#include "nsIEventQueueService.h" -#include "nsIEventQueue.h" +#include "netCore.h" #include "nsIFileTransportService.h" +#include "nsIFile.h" +#include "nsInt64.h" + +#include "prio.h" // Need to pick up def of PR_RDONLY -static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID); -static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); +static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID); +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); //////////////////////////////////////////////////////////////////////////////// @@ -62,8 +45,7 @@ nsFileChannel::nsFileChannel() } nsresult -nsFileChannel::Init(nsIFileProtocolHandler* handler, - const char* command, +nsFileChannel::Init(const char* command, nsIURI* uri, nsILoadGroup* aLoadGroup, nsIInterfaceRequestor* notificationCallbacks, @@ -74,7 +56,6 @@ nsFileChannel::Init(nsIFileProtocolHandler* handler, { nsresult rv; - mHandler = handler; mOriginalURI = originalURI ? originalURI : uri; mURI = uri; mCommand = nsCRT::strdup(command); @@ -94,42 +75,15 @@ nsFileChannel::Init(nsIFileProtocolHandler* handler, // if we support the nsIURL interface then use it to get just // the file path with no other garbage! - nsCOMPtr aUrl = do_QueryInterface(mURI, &rv); - if (NS_SUCCEEDED(rv) && aUrl) { // does it support the url interface? - nsXPIDLCString fileString; - aUrl->GetFilePath(getter_Copies(fileString)); - // to be mac friendly you need to convert a file path to a nsFilePath before - // passing it to a nsFileSpec... -#ifdef XP_MAC - nsFilePath filePath(nsUnescape((char*)(const char*)fileString)); - mSpec = filePath; - - // Don't assume we actually created a good file spec - FSSpec theSpec = mSpec.GetFSSpec(); - if (!theSpec.name[0]) - { - NS_ERROR("failed to create a file spec"); - - // Since we didn't actually create the file spec - // we return an error - return NS_ERROR_MALFORMED_URI; - } -#else - nsFilePath filePath(nsUnescape((char*)(const char*)fileString)); - mSpec = filePath; -#endif - } - else { - // otherwise do the best we can by using the spec for the uri.... - // XXX temporary, until we integrate more thoroughly with nsFileSpec - char* url; - rv = mURI->GetSpec(&url); - if (NS_FAILED(rv)) return rv; - nsFileURL fileURL(url); - nsCRT::free(url); - mSpec = fileURL; + nsCOMPtr fileURL = do_QueryInterface(mURI, &rv); + if (NS_FAILED(rv)) { + // this URL doesn't denote a file + return NS_ERROR_MALFORMED_URI; } + rv = fileURL->GetFile(getter_AddRefs(mFile)); + if (NS_FAILED(rv)) return rv; + return rv; } @@ -226,7 +180,7 @@ nsFileChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount, NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(mSpec, mCommand, 0, 0, getter_AddRefs(mFileTransport)); + rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, 0, 0, getter_AddRefs(mFileTransport)); if (NS_FAILED(rv)) goto done; rv = mFileTransport->SetNotificationCallbacks(mCallbacks); @@ -252,7 +206,7 @@ nsFileChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **result NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(mSpec, mCommand, mBufferSegmentSize, mBufferMaxSize, + rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize, getter_AddRefs(mFileTransport)); if (NS_FAILED(rv)) goto done; @@ -309,7 +263,7 @@ nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(mSpec, mCommand, mBufferSegmentSize, mBufferMaxSize, + rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize, getter_AddRefs(mFileTransport)); if (NS_FAILED(rv)) goto done; @@ -339,7 +293,7 @@ nsFileChannel::AsyncWrite(nsIInputStream *fromStream, NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(mSpec, mCommand, mBufferSegmentSize, mBufferMaxSize, + rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize, getter_AddRefs(mFileTransport)); if (NS_FAILED(rv)) goto done; @@ -376,7 +330,9 @@ nsFileChannel::GetContentType(char * *aContentType) *aContentType = nsnull; if (mContentType.IsEmpty()) { - if (mSpec.IsDirectory()) { + PRBool directory; + mFile->IsDirectory(&directory); + if (directory) { mContentType = "application/http-index-format"; } else { @@ -414,11 +370,10 @@ NS_IMETHODIMP nsFileChannel::GetContentLength(PRInt32 *aContentLength) { nsresult rv; - PRUint32 length; - - rv = GetFileSize(&length); + PRInt64 size; + rv = mFile->GetFileSize(&size); if (NS_SUCCEEDED(rv)) { - *aContentLength = (PRInt32)length; + *aContentLength = nsInt64(size); } else { *aContentLength = -1; } @@ -528,325 +483,50 @@ nsFileChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* contex //////////////////////////////////////////////////////////////////////////////// NS_IMETHODIMP -nsFileChannel::GetModDate(PRTime *aModDate) -{ - nsFileSpec::TimeStamp date; - mSpec.GetModDate(date); - LL_I2L(*aModDate, date); - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::GetFileSize(PRUint32 *aFileSize) -{ - *aFileSize = mSpec.GetFileSize(); - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::GetParent(nsIFileChannel * *aParent) -{ - nsFileSpec parentSpec; - mSpec.GetParent(parentSpec); - return CreateFileChannelFromFileSpec(parentSpec, aParent); -} - -class nsDirEnumerator : public nsISimpleEnumerator -{ -public: - NS_DECL_ISUPPORTS - - nsDirEnumerator() : mDir(nsnull) { - NS_INIT_REFCNT(); - } - - nsresult Init(nsFileChannel* parent, nsIFileProtocolHandler* handler, - nsFileSpec& spec) { - const char* path = spec.GetNativePathCString(); - mDir = PR_OpenDir(path); - if (mDir == nsnull) // not a directory? - return NS_ERROR_FAILURE; - mHandler = handler; - mParent = parent; - NS_ADDREF(mParent); - return NS_OK; - } - - NS_IMETHOD HasMoreElements(PRBool *result) { - nsresult rv; - if (mNext == nsnull && mDir) { - PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH); - if (entry == nsnull) { - // end of dir entries - - PRStatus status = PR_CloseDir(mDir); - if (status != PR_SUCCESS) - return NS_ERROR_FAILURE; - mDir = nsnull; - - *result = PR_FALSE; - return NS_OK; - } - - const char* path = entry->name; - rv = mHandler->NewChannelFromNativePath(path, - mParent->mLoadGroup, - mParent->mCallbacks, - mParent->mLoadAttributes, - nsnull, - mParent->mBufferSegmentSize, - mParent->mBufferMaxSize, - getter_AddRefs(mNext)); - if (NS_FAILED(rv)) return rv; - - NS_ASSERTION(mNext, "NewChannel failed"); - } - *result = mNext != nsnull; - return NS_OK; - } - - NS_IMETHOD GetNext(nsISupports **result) { - nsresult rv; - PRBool hasMore; - rv = HasMoreElements(&hasMore); - if (NS_FAILED(rv)) return rv; - - *result = mNext; // might return nsnull - mNext = null_nsCOMPtr(); - return NS_OK; - } - - virtual ~nsDirEnumerator() { - if (mDir) { - PRStatus status = PR_CloseDir(mDir); - NS_ASSERTION(status == PR_SUCCESS, "close failed"); - } - NS_RELEASE(mParent); - } - -protected: - nsFileChannel* mParent; - nsCOMPtr mHandler; - PRDir* mDir; - nsCOMPtr mNext; -}; - -NS_IMPL_ISUPPORTS(nsDirEnumerator, NS_GET_IID(nsISimpleEnumerator)); - -NS_IMETHODIMP -nsFileChannel::GetChildren(nsISimpleEnumerator * *aChildren) +nsFileChannel::Init(nsIFile* file, + PRInt32 mode, + const char* contentType, + PRInt32 contentLength, + nsILoadGroup* aLoadGroup, + nsIInterfaceRequestor* notificationCallbacks, + nsLoadFlags loadAttributes, + nsIURI* originalURI, + PRUint32 bufferSegmentSize, + PRUint32 bufferMaxSize) { nsresult rv; - - PRBool isDir; - rv = IsDirectory(&isDir); + nsCOMPtr url; + rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, + NS_GET_IID(nsIFileURL), + getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; - if (!isDir) - return NS_ERROR_FAILURE; - nsDirEnumerator* dirEnum = new nsDirEnumerator(); - if (dirEnum == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(dirEnum); - rv = dirEnum->Init(this, mHandler, mSpec); - if (NS_FAILED(rv)) { - NS_RELEASE(dirEnum); - return rv; - } - *aChildren = dirEnum; - return NS_OK; + rv = url->SetFile(file); + if (NS_FAILED(rv)) return rv; + + return Init("load", // XXX + url, + aLoadGroup, + notificationCallbacks, + loadAttributes, + originalURI, + bufferSegmentSize, + bufferMaxSize); } NS_IMETHODIMP -nsFileChannel::GetNativePath(char * *aNativePath) +nsFileChannel::GetFile(nsIFile* *result) { - char* nativePath = nsCRT::strdup(mSpec.GetNativePathCString()); - if (nativePath == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - *aNativePath = nativePath; - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::Exists(PRBool *result) -{ - *result = mSpec.Exists(); - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::Create() -{ - nsFileSpec mySpec(mSpec); // relative path. - { - nsIOFileStream testStream(mySpec); // creates the file - // Scope ends here, file gets closed - } - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::Delete() -{ - mSpec.Delete(PR_TRUE); // RECURSIVE DELETE! - if (mSpec.Exists()) - return NS_ERROR_FAILURE; - - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::MoveFrom(nsIURI *src) -{ -#if 0 - nsresult rv; - nsIFileChannel* fc; - rv = src->QueryInterface(NS_GET_IID(nsIFileChannel), (void**)&fc); - if (NS_SUCCEEDED(rv)) { - rv = fc->moveToDir(this); - NS_RELEASE(fc); - return rv; - } - else { - // Do it the hard way -- fetch the URL and store the bits locally. - // Delete the src when done. - return NS_ERROR_NOT_IMPLEMENTED; - } -#else - return NS_ERROR_NOT_IMPLEMENTED; -#endif -} - -NS_IMETHODIMP -nsFileChannel::CopyFrom(nsIURI *src) -{ -#if 0 - nsresult rv; - nsIFileChannel* fc; - rv = src->QueryInterface(NS_GET_IID(nsIFileChannel), (void**)&fc); - if (NS_SUCCEEDED(rv)) { - rv = fc->copyToDir(this); - NS_RELEASE(fc); - return rv; - } - else { - // Do it the hard way -- fetch the URL and store the bits locally. - return NS_ERROR_NOT_IMPLEMENTED; - } -#else - return NS_ERROR_NOT_IMPLEMENTED; -#endif -} - -NS_IMETHODIMP -nsFileChannel::IsDirectory(PRBool *result) -{ - *result = mSpec.IsDirectory(); - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::IsFile(PRBool *result) -{ - *result = mSpec.IsFile(); - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::IsLink(PRBool *_retval) -{ - *_retval = mSpec.IsSymlink(); - return NS_OK; -} - -NS_IMETHODIMP -nsFileChannel::ResolveLink(nsIFileChannel **_retval) -{ - PRBool ignore; - nsFileSpec tempSpec = mSpec; - nsresult rv = tempSpec.ResolveSymlink(ignore); - - if (NS_SUCCEEDED(rv)) { - return CreateFileChannelFromFileSpec(tempSpec, _retval); - } - - return rv; -} - -NS_IMETHODIMP -nsFileChannel::MakeUnique(const char* baseName, nsIFileChannel **_retval) -{ - if (mSpec.IsDirectory()) { - nsFileSpec tempSpec = mSpec; - tempSpec.MakeUnique(baseName); - - return CreateFileChannelFromFileSpec(tempSpec, _retval); - } - return NS_ERROR_FAILURE; // XXX probably need NS_BASE_STREAM_NOT_DIRECTORY or something -} - - -NS_IMETHODIMP -nsFileChannel::Execute(const char *args) -{ - nsresult rv; - char* queryArgs = nsnull; - - if (args == nsnull) { - nsIURL* url; - rv = mURI->QueryInterface(NS_GET_IID(nsIURL), (void**)&url); - if (NS_SUCCEEDED(rv)) { - rv = url->GetQuery(&queryArgs); - NS_RELEASE(url); - if (NS_FAILED(rv)) return rv; - args = queryArgs; - } - } - - rv = mSpec.Execute(args); - if (queryArgs) - nsCRT::free(queryArgs); - return rv; -} - -NS_IMETHODIMP -nsFileChannel::GetFileSpec(nsFileSpec *spec) -{ - *spec = mSpec; + *result = mFile; + NS_ADDREF(*result); return NS_OK; } //////////////////////////////////////////////////////////////////////////////// -nsresult -nsFileChannel::CreateFileChannelFromFileSpec(nsFileSpec& spec, nsIFileChannel **result) -{ - nsresult rv; - nsFileURL aURL(spec); - const char* urlStr = aURL.GetURLString(); - NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - nsIChannel* channel; - rv = serv->NewChannel("load", // XXX what should this be? - urlStr, - nsnull, - mLoadGroup, - mCallbacks, - mLoadAttributes, - nsnull, - mBufferSegmentSize, - mBufferMaxSize, - &channel); - if (NS_FAILED(rv)) return rv; - // this cast is safe because nsFileURL::GetURLString aways - // returns file: strings, and consequently we'll make nsIFileChannel - // objects from them: - *result = NS_STATIC_CAST(nsIFileChannel*, channel); - return NS_OK; -} -//////////////////////////////////////////////////////////////////////////////// + diff --git a/mozilla/netwerk/protocol/file/src/nsFileChannel.h b/mozilla/netwerk/protocol/file/src/nsFileChannel.h index ce7e4507a27..0c4b1d3120f 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileChannel.h +++ b/mozilla/netwerk/protocol/file/src/nsFileChannel.h @@ -23,8 +23,7 @@ #ifndef nsFileChannel_h__ #define nsFileChannel_h__ -#include "nsIFileChannel.h" -#include "nsIFileProtocolHandler.h" +#include "nsIChannel.h" #include "nsIInterfaceRequestor.h" #include "nsILoadGroup.h" #include "nsIStreamListener.h" @@ -32,13 +31,15 @@ #include "nsFileSpec.h" #include "nsIURI.h" #include "nsCOMPtr.h" - #include "nsIRunnable.h" #include "nsIThread.h" #include "prlock.h" #include "nsIEventQueueService.h" #include "nsIPipe.h" -#include "nsString.h" +#include "nsILoadGroup.h" +#include "nsIStreamListener.h" +#include "nsCOMPtr.h" +#include "nsIFileSystem.h" class nsFileChannel : public nsIFileChannel, public nsIStreamListener @@ -59,8 +60,7 @@ public: static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult); - nsresult Init(nsIFileProtocolHandler* handler, - const char* command, + nsresult Init(const char* command, nsIURI* uri, nsILoadGroup* aLoadGroup, nsIInterfaceRequestor* notificationCallbacks, @@ -69,18 +69,12 @@ public: PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize); - friend class nsDirEnumerator; - -protected: - nsresult CreateFileChannelFromFileSpec(nsFileSpec& spec, nsIFileChannel** result); - protected: + nsCOMPtr mFile; nsCOMPtr mOriginalURI; nsCOMPtr mURI; - nsCOMPtr mHandler; nsCOMPtr mCallbacks; char* mCommand; - nsFileSpec mSpec; nsCOMPtr mFileTransport; nsCString mContentType; PRUint32 mLoadAttributes; diff --git a/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.cpp b/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.cpp index 31866b53b03..97771af3190 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.cpp @@ -53,9 +53,7 @@ nsFileProtocolHandler::~nsFileProtocolHandler() { } -NS_IMPL_ISUPPORTS2(nsFileProtocolHandler, - nsIFileProtocolHandler, - nsIProtocolHandler); +NS_IMPL_ISUPPORTS1(nsFileProtocolHandler, nsIProtocolHandler); NS_METHOD nsFileProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -142,7 +140,7 @@ nsFileProtocolHandler::NewChannel(const char* command, nsIURI* url, rv = nsFileChannel::Create(nsnull, NS_GET_IID(nsIFileChannel), (void**)&channel); if (NS_FAILED(rv)) return rv; - rv = channel->Init(this, command, url, aLoadGroup, notificationCallbacks, + rv = channel->Init(command, url, aLoadGroup, notificationCallbacks, loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize); if (NS_FAILED(rv)) { NS_RELEASE(channel); @@ -153,36 +151,4 @@ nsFileProtocolHandler::NewChannel(const char* command, nsIURI* url, return NS_OK; } -NS_IMETHODIMP -nsFileProtocolHandler::NewChannelFromNativePath(const char* nativePath, - nsILoadGroup* aLoadGroup, - nsIInterfaceRequestor* notificationCallbacks, - nsLoadFlags loadAttributes, - nsIURI* originalURI, - PRUint32 bufferSegmentSize, - PRUint32 bufferMaxSize, - nsIFileChannel* *result) -{ - nsresult rv; - nsFileSpec spec(nativePath); - nsFileURL fileURL(spec); - const char* urlStr = fileURL.GetURLString(); - nsIURI* uri; - - rv = NewURI(urlStr, nsnull, &uri); - if (NS_FAILED(rv)) return rv; - - rv = NewChannel("load", // XXX what should this be? - uri, - aLoadGroup, - notificationCallbacks, - loadAttributes, - originalURI, - bufferSegmentSize, - bufferMaxSize, - (nsIChannel**)result); - NS_RELEASE(uri); - return rv; -} - //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.h b/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.h index f219e4b9c45..0024c1eda74 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.h +++ b/mozilla/netwerk/protocol/file/src/nsFileProtocolHandler.h @@ -23,7 +23,7 @@ #ifndef nsFileProtocolHandler_h___ #define nsFileProtocolHandler_h___ -#include "nsIFileProtocolHandler.h" +#include "nsIProtocolHandler.h" class nsISupportsArray; class nsIRunnable; @@ -41,18 +41,12 @@ class nsIThreadPool; {0x93, 0x44, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \ } -class nsFileProtocolHandler : public nsIFileProtocolHandler +class nsFileProtocolHandler : public nsIProtocolHandler { public: NS_DECL_ISUPPORTS - - // nsIProtocolHandler methods: NS_DECL_NSIPROTOCOLHANDLER - // nsIFileProtocolHandler methods: - NS_DECL_NSIFILEPROTOCOLHANDLER - - // nsFileProtocolHandler methods: nsFileProtocolHandler(); virtual ~nsFileProtocolHandler(); diff --git a/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp b/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp index 700c58b63b8..b4b1a8cc076 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp +++ b/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp @@ -22,7 +22,7 @@ #include "nsIModule.h" #include "nsIGenericFactory.h" - +#include "nsFileChannel.h" #include "nsFileProtocolHandler.h" static nsModuleComponentInfo components[] = @@ -32,6 +32,11 @@ static nsModuleComponentInfo components[] = NS_NETWORK_PROTOCOL_PROGID_PREFIX "file", nsFileProtocolHandler::Create }, + { NS_FILECHANNEL_CLASSNAME, + NS_FILECHANNEL_CID, + NS_FILECHANNEL_PROGID, + nsFileChannel::Create + } }; NS_IMPL_NSGETMODULE("nsFileProtocolModule", components); diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp index 1f6385ae709..131cb313a34 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp @@ -161,7 +161,7 @@ nsHTTPEncodeStream::Read(char* outBuf, PRUint32 outBufCnt, PRUint32 *result) // nsIRandomAccessStore methods: NS_IMETHODIMP -nsHTTPEncodeStream::Seek(PRSeekWhence whence, PRInt32 offset) +nsHTTPEncodeStream::Seek(PRInt32 whence, PRInt32 offset) { nsresult rv; nsCOMPtr ras = do_QueryInterface(mInput, &rv); @@ -172,7 +172,7 @@ nsHTTPEncodeStream::Seek(PRSeekWhence whence, PRInt32 offset) } NS_IMETHODIMP -nsHTTPEncodeStream::Tell(PRIntn* outWhere) +nsHTTPEncodeStream::Tell(PRInt32* outWhere) { nsresult rv; nsCOMPtr ras = do_QueryInterface(mInput, &rv); @@ -181,6 +181,7 @@ nsHTTPEncodeStream::Tell(PRIntn* outWhere) return ras->Tell(outWhere); } +#if 0 NS_IMETHODIMP nsHTTPEncodeStream::GetAtEOF(PRBool* outAtEOF) { @@ -200,5 +201,6 @@ nsHTTPEncodeStream::SetAtEOF(PRBool inAtEOF) return ras->SetAtEOF(inAtEOF); } +#endif //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h index 545102a7f70..b968bbc00e9 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h +++ b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h @@ -26,7 +26,7 @@ #include "nsIInputStream.h" #include "nsString.h" #include "nsCOMPtr.h" -#include "nsIFileStream.h" +#include "nsIFileStreams.h" class nsHTTPEncodeStream : public nsIInputStream, public nsIRandomAccessStore @@ -35,13 +35,16 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIBASESTREAM NS_DECL_NSIINPUTSTREAM + NS_DECL_NSIRANDOMACCESSSTORE +#if 0 NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset); NS_IMETHOD Tell(PRIntn* outWhere); // XXX supposedly "protected": NS_IMETHOD GetAtEOF(PRBool* outAtEOF); NS_IMETHOD SetAtEOF(PRBool inAtEOF); - +#endif + // nsHTTPEncodeStream methods: nsHTTPEncodeStream(); virtual ~nsHTTPEncodeStream(); diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp index c3ffedebed7..4e8d53a1427 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp @@ -34,7 +34,7 @@ #include "nsIServiceManager.h" #include "nsIInterfaceRequestor.h" #include "nsIHttpEventSink.h" -#include "nsIFileStream.h" +#include "nsIFileStreams.h" #include "nsIStringStream.h" #include "nsHTTPEncodeStream.h" #include "nsHTTPAtoms.h" @@ -43,6 +43,8 @@ #ifdef DEBUG_gagan #include "nsUnixColorPrintf.h" #endif +#include "nsILocalFile.h" +#include "nsNetUtil.h" #if defined(PR_LOGGING) // @@ -328,43 +330,40 @@ nsHTTPHandler::NewEncodeStream(nsIInputStream *rawStream, PRUint32 encodeFlags, NS_IMETHODIMP nsHTTPHandler::NewDecodeStream(nsIInputStream *encodedStream, - PRUint32 decodeFlags, - nsIInputStream **result) + PRUint32 decodeFlags, + nsIInputStream **result) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTTPHandler::NewPostDataStream(PRBool isFile, - const char *data, - PRUint32 encodeFlags, - nsIInputStream **result) + const char *data, + PRUint32 encodeFlags, + nsIInputStream **result) { nsresult rv; if (isFile) { - nsISupports* in; - nsFileSpec spec(data); - rv = NS_NewTypicalInputFileStream(&in, spec); + nsCOMPtr file; + rv = NS_NewLocalFile(data, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; - nsIInputStream* rawStream; - rv = in->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&rawStream); - NS_RELEASE(in); + nsCOMPtr in; + rv = NS_NewFileInputStream(file, getter_AddRefs(in)); + if (NS_FAILED(rv)) return rv; - rv = NewEncodeStream(rawStream, - nsIHTTPProtocolHandler::ENCODE_NORMAL, - result); - NS_RELEASE(rawStream); + rv = NewEncodeStream(in, + nsIHTTPProtocolHandler::ENCODE_NORMAL, + result); return rv; } else { - nsISupports* in; - rv = NS_NewStringInputStream(&in, data); + nsCOMPtr in; + rv = NS_NewStringInputStream(getter_AddRefs(in), data); if (NS_FAILED(rv)) return rv; - rv = in->QueryInterface(NS_GET_IID(nsIInputStream), (void**)result); - NS_RELEASE(in); + rv = in->QueryInterface(nsIInputStream::GetIID(), (void**)result); return rv; } } diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp index 8ef9134445d..2d9a28bb156 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -20,7 +20,6 @@ #include "nsNetUtil.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" -#include "nsIFileSpec.h" #include "nsSpecialSystemDirectory.h" #include "nsJARChannel.h" #include "nsCRT.h" @@ -28,12 +27,11 @@ #include "nsIURL.h" #include "nsIMIMEService.h" #include "nsAutoLock.h" +#include "nsIFileStreams.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID); static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); - //////////////////////////////////////////////////////////////////////////////// class nsJARDownloadObserver : public nsIStreamObserver @@ -58,18 +56,18 @@ public: "wrong transport"); // after successfully downloading the jar file to the cache, // start the extraction process: - NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr jarCacheFile; - rv = serv->NewChannelFromNativePath(mJarCacheFile.GetNativePathCString(), - mJARChannel->mLoadGroup, - mJARChannel->mCallbacks, - mJARChannel->mLoadAttributes, - nsnull, - mJARChannel->mBufferSegmentSize, - mJARChannel->mBufferMaxSize, - getter_AddRefs(jarCacheFile)); + rv = NS_NewFileChannel(mJarCacheFile, + PR_RDONLY, + nsnull, // XXX content type + 0, // XXX content length + mJARChannel->mLoadGroup, + mJARChannel->mCallbacks, + mJARChannel->mLoadAttributes, + nsnull, + mJARChannel->mBufferSegmentSize, + mJARChannel->mBufferMaxSize, + getter_AddRefs(jarCacheFile)); if (NS_FAILED(rv)) return rv; rv = mJARChannel->ExtractJARElement(jarCacheFile); @@ -78,7 +76,7 @@ public: return rv; } - nsJARDownloadObserver(nsFileSpec& jarCacheFile, nsJARChannel* jarChannel) { + nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel) { NS_INIT_REFCNT(); mJarCacheFile = jarCacheFile; mJARChannel = jarChannel; @@ -90,7 +88,7 @@ public: } protected: - nsFileSpec mJarCacheFile; + nsCOMPtr mJarCacheFile; nsJARChannel* mJARChannel; }; @@ -314,29 +312,35 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, else { // otherwise, we need to download the jar file - nsFileSpec jarCacheFile; - rv = GetCacheFile(jarCacheFile); + nsCOMPtr jarCacheFile; + rv = GetCacheFile(getter_AddRefs(jarCacheFile)); if (NS_FAILED(rv)) return rv; - - if (jarCacheFile.IsFile()) { + + PRBool filePresent; + + rv = jarCacheFile->IsFile(&filePresent); + + if (NS_FAILED(rv)) + return rv; + + if (filePresent) + { // then we've already got the file in the local cache -- no need to download it - - NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv); + NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr jarCacheChannel; - rv = serv->NewChannelFromNativePath(jarCacheFile.GetNativePathCString(), - mLoadGroup, - mCallbacks, - mLoadAttributes, - nsnull, - mBufferSegmentSize, - mBufferMaxSize, - getter_AddRefs(jarCacheChannel)); - + nsCOMPtr jarCacheChannel; + rv = fts->CreateTransport(jarCacheFile, + PR_RDONLY, + mCommand, + mBufferSegmentSize, + mBufferMaxSize, + getter_AddRefs(jarCacheChannel)); if (NS_FAILED(rv)) return rv; - - rv = ExtractJARElement(jarCacheChannel); + + nsCOMPtr fileChannel = do_QueryInterface(jarCacheChannel); + if (fileChannel) return NS_ERROR_FAILURE; + rv = ExtractJARElement(fileChannel); return rv; } @@ -347,7 +351,8 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, // use a file transport to serve as a data pump for the download (done // on some other thread) - rv = fts->CreateTransport(jarCacheFile, mCommand, + nsCOMPtr jarCacheTransport; + rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize, getter_AddRefs(mJarCacheTransport)); if (NS_FAILED(rv)) return rv; @@ -369,16 +374,25 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, } nsresult -nsJARChannel::GetCacheFile(nsFileSpec& cacheFile) +nsJARChannel::GetCacheFile(nsIFile* *cacheFile) { // XXX change later to use the real network cache nsresult rv; - nsSpecialSystemDirectory jarCacheFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - jarCacheFile += "jarCache"; + nsCOMPtr jarCacheFile; + rv = NS_GetSpecialDirectory("xpcom.currentProcess.componentDirectory", + getter_AddRefs(jarCacheFile)); + if (NS_FAILED(rv)) return rv; - if (!jarCacheFile.Exists()) - jarCacheFile.CreateDirectory(); + jarCacheFile->Append("jarCache"); + + PRBool exists; + rv = jarCacheFile->Exists(&exists); + if (NS_FAILED(rv)) return rv; + if (!exists) { + rv = jarCacheFile->Create(nsIFile::DIRECTORY_TYPE, 0664); + if (NS_FAILED(rv)) return rv; + } nsCOMPtr jarBaseURL = do_QueryInterface(mJARBaseURI, &rv); if (NS_FAILED(rv)) return rv; @@ -386,10 +400,11 @@ nsJARChannel::GetCacheFile(nsFileSpec& cacheFile) char* jarFileName; rv = jarBaseURL->GetFileName(&jarFileName); if (NS_FAILED(rv)) return rv; - jarCacheFile += jarFileName; + jarCacheFile->Append(jarFileName); nsCRT::free(jarFileName); - cacheFile = jarCacheFile; + *cacheFile = jarCacheFile; + NS_ADDREF(*cacheFile); return rv; } @@ -606,8 +621,8 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength) getter_AddRefs(mJAR)); if (NS_FAILED(rv)) return rv; - nsFileSpec fs; - rv = mJARBaseFile->GetFileSpec(&fs); + nsCOMPtr fs; + rv = mJARBaseFile->GetFile(getter_AddRefs(fs)); if (NS_FAILED(rv)) return rv; rv = mJAR->Init(fs); diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.h b/mozilla/netwerk/protocol/jar/src/nsJARChannel.h index e5cac2e6606..a652bc179c4 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.h +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.h @@ -28,13 +28,13 @@ #include "nsIJARProtocolHandler.h" #include "nsIJARURI.h" #include "nsIFileSystem.h" -#include "nsIFileChannel.h" +#include "nsIChannel.h" #include "nsIZipReader.h" -#include "nsIFileChannel.h" +#include "nsIChannel.h" #include "nsILoadGroup.h" #include "nsIInterfaceRequestor.h" #include "nsCOMPtr.h" -#include "nsFileSpec.h" +#include "nsIFile.h" class nsIFileChannel; @@ -79,7 +79,7 @@ public: PRUint32 bufferMaxSize); nsresult ExtractJARElement(nsIFileChannel* jarFileChannel); - nsresult GetCacheFile(nsFileSpec& cacheFile); + nsresult GetCacheFile(nsIFile* *cacheFile); friend class nsJARDownloadObserver; diff --git a/mozilla/netwerk/test/TestFileInput.cpp b/mozilla/netwerk/test/TestFileInput.cpp index 89ef37410f3..8c4801a2c94 100644 --- a/mozilla/netwerk/test/TestFileInput.cpp +++ b/mozilla/netwerk/test/TestFileInput.cpp @@ -20,8 +20,6 @@ * Contributor(s): */ -#define NSPIPE2 - #include "nsIFileTransportService.h" #include "nsIStreamListener.h" #include "nsIServiceManager.h" @@ -32,14 +30,11 @@ #include "prmon.h" #include "prcmon.h" #include "prio.h" -#include "nsIFileStream.h" -#include "nsFileSpec.h" -#ifndef NSPIPE2 -#include "nsIBuffer.h" -#else +#include "nsIFileStreams.h" +#include "nsILocalFile.h" +#include "nsNetUtil.h" #include "nsIPipe.h" #include "nsIBufferOutputStream.h" -#endif #include "nsIBufferInputStream.h" #include "nsIRunnable.h" #include "nsIThread.h" @@ -47,6 +42,7 @@ #include "nsIChannel.h" #include "nsCOMPtr.h" #include +#include "nsInt64.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); @@ -206,38 +202,25 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) #define NS_FILE_TRANSPORT_BUFFER_SIZE (4*1024) nsresult rv; - nsISupports* fs; - nsIInputStream* fileStr = nsnull; + nsCOMPtr fileStr; nsIBufferInputStream* bufStr = nsnull; - nsFileSpec spec(path); PRUint32 sourceOffset = 0; -#ifndef NSPIPE2 - nsCOMPtr buf; -#else nsCOMPtr out; -#endif + nsCOMPtr file; rv = reader->OnStartRequest(nsnull, nsnull); if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer? - rv = NS_NewTypicalInputFileStream(&fs, spec); + rv = NS_NewLocalFile(path, getter_AddRefs(file)); if (NS_FAILED(rv)) goto done; - rv = fs->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&fileStr); - NS_RELEASE(fs); + rv = NS_NewFileInputStream(file, getter_AddRefs(fileStr)); if (NS_FAILED(rv)) goto done; -#ifndef NSPIPE2 - rv = NS_NewBuffer(getter_AddRefs(buf), NS_FILE_TRANSPORT_BUFFER_SIZE, - NS_FILE_TRANSPORT_BUFFER_SIZE, nsnull); - rv = NS_NewBufferInputStream(&bufStr, buf, PR_TRUE); - if (NS_FAILED(rv)) goto done; -#else rv = NS_NewPipe(&bufStr, getter_AddRefs(out), nsnull, NS_FILE_TRANSPORT_BUFFER_SIZE, NS_FILE_TRANSPORT_BUFFER_SIZE); if (NS_FAILED(rv)) goto done; -#endif /* if ( spec.GetFileSize() == 0) goto done; @@ -246,15 +229,10 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) while (PR_TRUE) { PRUint32 amt; /* id'l change to FillFrom... */ -#if 0 - rv = bufStr->FillFrom(fileStr, spec.GetFileSize(), &amt); -#else -#ifndef NSPIPE2 - rv = buf->WriteFrom(fileStr, spec.GetFileSize(), &amt); -#else - rv = out->WriteFrom(fileStr, spec.GetFileSize(), &amt); -#endif -#endif + PRInt64 size; + rv = file->GetFileSize(&size); + if (NS_FAILED(rv)) break; + rv = out->WriteFrom(fileStr, nsInt64(size), &amt); if (NS_FAILED(rv) || amt == 0) break; rv = reader->OnDataAvailable(nsnull, nsnull, bufStr, sourceOffset, amt); @@ -265,7 +243,6 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) done: NS_IF_RELEASE(bufStr); - NS_IF_RELEASE(fileStr); rv = reader->OnStopRequest(nsnull, nsnull, rv, nsnull); return rv; @@ -348,8 +325,12 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) PRDirEntry* entry; while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH)) != nsnull) { - nsFileSpec spec(dirName); - spec += entry->name; + nsCOMPtr file; + rv = NS_NewLocalFile(dirName, getter_AddRefs(file)); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewLocalFile failed"); + + rv = file->Append(entry->name); + NS_ASSERTION(NS_SUCCEEDED(rv), "AppendPath failed"); nsReader* reader = new nsReader(); NS_ASSERTION(reader, "out of memory"); @@ -369,7 +350,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) NS_ASSERTION(listener, "QI failed"); nsIChannel* trans; - rv = fts->CreateTransport(spec, "load", 0, 0, &trans); + rv = fts->CreateTransport(file, PR_RDONLY, "load", 0, 0, &trans); NS_ASSERTION(NS_SUCCEEDED(rv), "create failed"); rv = trans->AsyncRead(0, -1, nsnull, listener); diff --git a/mozilla/netwerk/test/TestFileInput2.cpp b/mozilla/netwerk/test/TestFileInput2.cpp index 184ce0f0737..3cc1020acc1 100644 --- a/mozilla/netwerk/test/TestFileInput2.cpp +++ b/mozilla/netwerk/test/TestFileInput2.cpp @@ -27,8 +27,9 @@ #include "nsIThread.h" #include "nsISupportsArray.h" #include "prinrval.h" -#include "nsIFileStream.h" -#include "nsFileSpec.h" +#include "nsIFileStreams.h" +#include "nsILocalFile.h" +#include "nsNetUtil.h" #include //////////////////////////////////////////////////////////////////////////////// @@ -112,8 +113,8 @@ nsTimeSampler::PrintStats() nsTimeSampler gTimeSampler; typedef nsresult (*CreateFun)(nsIRunnable* *result, - const char* inPath, - const char* outPath, + nsIFile* inPath, + nsIFile* outPath, PRUint32 bufferSize); //////////////////////////////////////////////////////////////////////////////// @@ -149,40 +150,28 @@ public: PRIntervalTime startTime = PR_IntervalNow(); PRIntervalTime endTime; - - nsIInputStream* inStr = nsnull; - nsIOutputStream* outStr = nsnull; - nsISupports* str = nsnull; - + nsCOMPtr inStr; + nsCOMPtr outStr; PRUint32 copyCount = 0; - nsFileSpec inSpec(mInPath); - nsFileSpec outSpec(mOutPath); - + // Open the input stream: - rv = NS_NewTypicalInputFileStream(&str, inSpec); - if (NS_FAILED(rv)) goto done; - rv = str->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&inStr); - NS_RELEASE(str); - if (NS_FAILED(rv)) goto done; + rv = NS_NewFileInputStream(mInPath, getter_AddRefs(inStr)); + if (NS_FAILED(rv)) return rv; // Open the output stream: - rv = NS_NewTypicalOutputFileStream(&str, outSpec); - if (NS_FAILED(rv)) goto done; - rv = str->QueryInterface(NS_GET_IID(nsIOutputStream), (void**)&outStr); - NS_RELEASE(str); - if (NS_FAILED(rv)) goto done; + rv = NS_NewFileOutputStream(mOutPath, + PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, + 0664, + getter_AddRefs(outStr)); + if (NS_FAILED(rv)) return rv; // Copy from one to the other rv = Copy(inStr, outStr, mBuffer, mBufferSize, ©Count); - if (NS_FAILED(rv)) goto done; + if (NS_FAILED(rv)) return rv; endTime = PR_IntervalNow(); gTimeSampler.AddTime(endTime - startTime); - done: - NS_IF_RELEASE(outStr); - NS_IF_RELEASE(inStr); - NS_IF_RELEASE(str); return rv; } @@ -195,11 +184,11 @@ public: NS_INIT_REFCNT(); } - nsresult Init(const char* inPath, const char* outPath, + nsresult Init(nsIFile* inPath, nsIFile* outPath, PRUint32 bufferSize) { - mInPath = nsCRT::strdup(inPath); - mOutPath = nsCRT::strdup(outPath); + mInPath = inPath; + mOutPath = outPath; mBuffer = new char[bufferSize]; mBufferSize = bufferSize; return (mInPath && mOutPath && mBuffer) @@ -207,8 +196,8 @@ public: } static nsresult Create(nsIRunnable* *result, - const char* inPath, - const char* outPath, + nsIFile* inPath, + nsIFile* outPath, PRUint32 bufferSize) { FileSpecWorker* worker = new FileSpecWorker(); @@ -226,16 +215,14 @@ public: } virtual ~FileSpecWorker() { - nsCRT::free(mInPath); - nsCRT::free(mOutPath); delete[] mBuffer; } protected: - char* mInPath; - char* mOutPath; - char* mBuffer; - PRUint32 mBufferSize; + nsCOMPtr mInPath; + nsCOMPtr mOutPath; + char* mBuffer; + PRUint32 mBufferSize; }; NS_IMPL_ISUPPORTS(FileSpecWorker, NS_GET_IID(nsIRunnable)); @@ -243,10 +230,7 @@ NS_IMPL_ISUPPORTS(FileSpecWorker, NS_GET_IID(nsIRunnable)); //////////////////////////////////////////////////////////////////////////////// #include "nsIIOService.h" -#include "nsIFileChannel.h" -#include "nsIFileProtocolHandler.h" - -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); +#include "nsIChannel.h" class FileChannelWorker : public nsIRunnable { public: @@ -254,56 +238,53 @@ public: NS_IMETHOD Run() { nsresult rv; - NS_WITH_SERVICE(nsIIOService, ioserv, kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - PRIntervalTime startTime = PR_IntervalNow(); PRIntervalTime endTime; - PRUint32 copyCount = 0; - nsIInputStream* inStr = nsnull; - nsIOutputStream* outStr = nsnull; - nsIFileChannel* inCh = nsnull; - nsIFileChannel* outCh = nsnull; + nsCOMPtr inCh; + nsCOMPtr outCh; + nsCOMPtr inStr; + nsCOMPtr outStr; - rv = ioserv->NewChannelFromNativePath(mInPath, - nsnull, // aLoadGroup - nsnull, // notificationCallbacks - nsIChannel::LOAD_NORMAL, - nsnull, // originalURI - 0, // bufferSegmentSize - 0, // bufferMaxSize - &inCh); - if (NS_FAILED(rv)) goto done; + rv = NS_NewFileChannel(mInPath, + PR_RDONLY, + nsnull, // contentType + 0, // contentLength, + nsnull, // aLoadGroup + nsnull, // notificationCallbacks + nsIChannel::LOAD_NORMAL, + nsnull, // originalURI + 0, // bufferSegmentSize + 0, // bufferMaxSize + getter_AddRefs(inCh)); + if (NS_FAILED(rv)) return rv; - rv = inCh->OpenInputStream(0, -1, &inStr); - if (NS_FAILED(rv)) goto done; + rv = inCh->OpenInputStream(0, -1, getter_AddRefs(inStr)); + if (NS_FAILED(rv)) return rv; - rv = ioserv->NewChannelFromNativePath(mOutPath, - nsnull, // aLoadGroup - nsnull, // notificationCallbacks - nsIChannel::LOAD_NORMAL, - nsnull, // originalURI - 0, // bufferSegmentSize - 0, // bufferMaxSize - &outCh); - if (NS_FAILED(rv)) goto done; + rv = NS_NewFileChannel(mOutPath, + PR_RDWR, + nsnull, // contentType + 0, // contentLength, + nsnull, // aLoadGroup + nsnull, // notificationCallbacks + nsIChannel::LOAD_NORMAL, + nsnull, // originalURI + 0, // bufferSegmentSize + 0, // bufferMaxSize + getter_AddRefs(outCh)); + if (NS_FAILED(rv)) return rv; - rv = outCh->OpenOutputStream(0, &outStr); - if (NS_FAILED(rv)) goto done; + rv = outCh->OpenOutputStream(0, getter_AddRefs(outStr)); + if (NS_FAILED(rv)) return rv; // Copy from one to the other rv = Copy(inStr, outStr, mBuffer, mBufferSize, ©Count); - if (NS_FAILED(rv)) goto done; + if (NS_FAILED(rv)) return rv; endTime = PR_IntervalNow(); gTimeSampler.AddTime(endTime - startTime); - done: - NS_RELEASE(inStr); - NS_RELEASE(inCh); - NS_RELEASE(outStr); - NS_RELEASE(outCh); return rv; } @@ -316,11 +297,11 @@ public: NS_INIT_REFCNT(); } - nsresult Init(const char* inPath, const char* outPath, + nsresult Init(nsIFile* inPath, nsIFile* outPath, PRUint32 bufferSize) { - mInPath = nsCRT::strdup(inPath); - mOutPath = nsCRT::strdup(outPath); + mInPath = inPath; + mOutPath = outPath; mBuffer = new char[bufferSize]; mBufferSize = bufferSize; return (mInPath && mOutPath && mBuffer) @@ -328,8 +309,8 @@ public: } static nsresult Create(nsIRunnable* *result, - const char* inPath, - const char* outPath, + nsIFile* inPath, + nsIFile* outPath, PRUint32 bufferSize) { FileChannelWorker* worker = new FileChannelWorker(); @@ -347,16 +328,14 @@ public: } virtual ~FileChannelWorker() { - nsCRT::free(mInPath); - nsCRT::free(mOutPath); delete[] mBuffer; } protected: - char* mInPath; - char* mOutPath; - char* mBuffer; - PRUint32 mBufferSize; + nsCOMPtr mInPath; + nsCOMPtr mOutPath; + char* mBuffer; + PRUint32 mBufferSize; }; NS_IMPL_ISUPPORTS(FileChannelWorker, NS_GET_IID(nsIRunnable)); @@ -365,13 +344,19 @@ NS_IMPL_ISUPPORTS(FileChannelWorker, NS_GET_IID(nsIRunnable)); void Test(CreateFun create, PRUint32 count, - const char* inDir, const char* outDir, PRUint32 bufSize) + nsIFile* inDirSpec, nsIFile* outDirSpec, PRUint32 bufSize) { nsresult rv; PRUint32 i; - + + char* inDir; + char* outDir; + (void)inDirSpec->GetPath(&inDir); + (void)outDirSpec->GetPath(&outDir); printf("###########\nTest: from %s to %s, bufSize = %d\n", inDir, outDir, bufSize); + nsCRT::free(inDir); + nsCRT::free(outDir); gTimeSampler.Reset(); nsTimeSampler testTime; testTime.StartTime(); @@ -380,32 +365,56 @@ Test(CreateFun create, PRUint32 count, rv = NS_NewISupportsArray(&threads); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewISupportsArray failed"); - nsFileSpec inDirSpec(inDir); - nsDirectoryIterator iter(inDirSpec, PR_TRUE); - for (i = 0; i < count && iter.Exists(); i++, iter++) { - nsIThread* thread; - nsIRunnable* worker; + nsCOMPtr entries; + rv = inDirSpec->GetDirectoryEntries(getter_AddRefs(entries)); + NS_ASSERTION(NS_SUCCEEDED(rv), "GetDirectoryEntries failed"); - nsFileSpec& inSpec = iter.Spec(); + i = 0; + PRBool hasMore; + while (i < count && NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) { + nsCOMPtr next; + rv = entries->GetNext(getter_AddRefs(next)); + if (NS_FAILED(rv)) goto done; - nsFileSpec outSpec(outDir); - outSpec += inSpec.GetLeafName(); - if (outSpec.Exists()) { - outSpec.Delete(PR_FALSE); + nsCOMPtr inSpec = do_QueryInterface(next, &rv); + if (NS_FAILED(rv)) goto done; + + nsCOMPtr outSpec; + rv = outDirSpec->Clone(getter_AddRefs(outSpec)); // don't munge the original + if (NS_FAILED(rv)) goto done; + + char* leafName; + rv = inSpec->GetLeafName(&leafName); + if (NS_FAILED(rv)) goto done; + + rv = outSpec->Append(leafName); + nsCRT::free(leafName); + if (NS_FAILED(rv)) goto done; + + PRBool exists; + rv = outSpec->Exists(&exists); + if (NS_FAILED(rv)) goto done; + + if (exists) { + rv = outSpec->Delete(PR_FALSE); + if (NS_FAILED(rv)) goto done; } - - rv = create(&worker, - inSpec.GetNativePathCString(), - outSpec.GetNativePathCString(), + + nsCOMPtr thread; + nsCOMPtr worker; + rv = create(getter_AddRefs(worker), + inSpec, + outSpec, bufSize); if (NS_FAILED(rv)) goto done; - rv = NS_NewThread(&thread, worker, 0, PR_JOINABLE_THREAD); - NS_RELEASE(worker); + rv = NS_NewThread(getter_AddRefs(thread), worker, 0, PR_JOINABLE_THREAD); if (NS_FAILED(rv)) goto done; PRBool inserted = threads->InsertElementAt(thread, i); NS_ASSERTION(inserted, "not inserted"); + + i++; } PRUint32 j; @@ -451,43 +460,51 @@ main(int argc, char* argv[]) rv = NS_AutoregisterComponents(); if (NS_FAILED(rv)) return rv; + nsCOMPtr inDirFile; + rv = NS_NewLocalFile(inDir, getter_AddRefs(inDirFile)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr outDirFile; + rv = NS_NewLocalFile(outDir, getter_AddRefs(outDirFile)); + if (NS_FAILED(rv)) return rv; + CreateFun create = FileChannelWorker::Create; - Test(create, 1, inDir, outDir, 16 * 1024); + Test(create, 1, inDirFile, outDirFile, 16 * 1024); #if 1 printf("FileChannelWorker *****************************\n"); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); #endif create = FileSpecWorker::Create; printf("FileSpecWorker ********************************\n"); #if 1 - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); - Test(create, 20, inDir, outDir, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); #endif #if 1 - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); - Test(create, 20, inDir, outDir, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); #endif return 0; diff --git a/mozilla/netwerk/test/TestFileTransport.cpp b/mozilla/netwerk/test/TestFileTransport.cpp index e65f5f423cd..27f8cc60605 100644 --- a/mozilla/netwerk/test/TestFileTransport.cpp +++ b/mozilla/netwerk/test/TestFileTransport.cpp @@ -27,7 +27,7 @@ #include "nsCOMPtr.h" #include "nsIAllocator.h" #include "nsString.h" -#include "nsIFileStream.h" +#include "nsIFileStreams.h" #include "nsIStreamListener.h" #include "nsIEventQueueService.h" #include "nsIEventQueue.h" @@ -94,11 +94,13 @@ public: str += ".bak"; nsFileSpec spec(origFile); spec.SetLeafName(str); - nsISupports* out; - rv = NS_NewTypicalOutputFileStream(&out, spec); - if (NS_FAILED(rv)) return rv; - mOut = do_QueryInterface(out); - return NS_OK; + nsCOMPtr file; + rv = NS_NewLocalFile(spec, getter_AddRefs(file)); + rv = NS_NewFileOutputStream(file, + PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, + 0664, + getter_AddRefs(mOut)); + return rv; } virtual ~MyListener() { @@ -126,7 +128,10 @@ TestAsyncRead(const char* fileName, PRUint32 offset, PRInt32 length) nsFileSpec fs(fileName); nsIChannel* fileTrans; - rv = fts->CreateTransport(fs, "load", 0, 0, &fileTrans); + nsCOMPtr file; + rv = NS_NewLocalFile(fs, getter_AddRefs(file)); + if (NS_FAILED(rv)) return rv; + rv = fts->CreateTransport(file, PR_RDONLY, "load", 0, 0, &fileTrans); if (NS_FAILED(rv)) return rv; MyListener* listener = new MyListener(); @@ -167,7 +172,12 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) outFile += ".out"; nsFileSpec fs(outFile); nsIChannel* fileTrans; - rv = fts->CreateTransport(fs, "load", 0, 0, &fileTrans); + nsCOMPtr file; + rv = NS_NewLocalFile(fs, getter_AddRefs(file)); + if (NS_FAILED(rv)) return rv; + rv = fts->CreateTransport(file, + PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, + "load", 0, 0, &fileTrans); if (NS_FAILED(rv)) return rv; MyListener* listener = new MyListener(); @@ -178,10 +188,12 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) if (NS_FAILED(rv)) return rv; nsFileSpec spec(fileName); - nsCOMPtr in; - rv = NS_NewTypicalInputFileStream(getter_AddRefs(in), spec); + nsCOMPtr f; + rv = NS_NewLocalFile(spec, getter_AddRefs(f)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr inStr; + rv = NS_NewFileInputStream(f, getter_AddRefs(inStr)); if (NS_FAILED(rv)) return rv; - nsCOMPtr inStr = do_QueryInterface(in); gDone = PR_FALSE; rv = fileTrans->AsyncWrite(inStr, offset, length, nsnull, listener); @@ -243,7 +255,10 @@ TestAsyncOpen(const char* fileName, PRUint32 offset, PRInt32 length) nsFileSpec fs(fileName); nsIChannel* fileTrans; - rv = fts->CreateTransport(fs, "load", 0, 0, &fileTrans); + nsCOMPtr file; + rv = NS_NewLocalFile(fs, getter_AddRefs(file)); + if (NS_FAILED(rv)) return rv; + rv = fts->CreateTransport(file, PR_RDONLY, "load", 0, 0, &fileTrans); if (NS_FAILED(rv)) return rv; MyListener* listener = new MyListener(1); diff --git a/mozilla/netwerk/test/TestRawCache.cpp b/mozilla/netwerk/test/TestRawCache.cpp index 1e9f1233859..2afa7a338ec 100644 --- a/mozilla/netwerk/test/TestRawCache.cpp +++ b/mozilla/netwerk/test/TestRawCache.cpp @@ -35,7 +35,7 @@ #include "nsNetDiskCacheCID.h" #include "nsIPref.h" #include "prenv.h" -#include "nsIFileStream.h" +#include "nsIFileStreams.h" #include "nsIFileSpec.h" // Number of test entries to be placed in the cache #define NUM_CACHE_ENTRIES 250 diff --git a/mozilla/parser/htmlparser/src/nsParserModule.cpp b/mozilla/parser/htmlparser/src/nsParserModule.cpp index 4798fab986e..73e4f21a4de 100644 --- a/mozilla/parser/htmlparser/src/nsParserModule.cpp +++ b/mozilla/parser/htmlparser/src/nsParserModule.cpp @@ -20,6 +20,8 @@ * Contributor(s): * Pierre Phaneuf */ +#include "nsString.h" +#include "nspr.h" #include "nsCOMPtr.h" #include "nsIGenericFactory.h" #include "nsIModule.h" @@ -292,7 +294,7 @@ nsParserModule::GetClassObject(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -316,7 +318,7 @@ nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsParserModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { Components* cp = gComponents; @@ -350,7 +352,7 @@ nsParserModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) static nsParserModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/view/src/nsViewFactory.cpp b/mozilla/view/src/nsViewFactory.cpp index f63d47623a6..9013d896f95 100644 --- a/mozilla/view/src/nsViewFactory.cpp +++ b/mozilla/view/src/nsViewFactory.cpp @@ -173,7 +173,7 @@ static nsViewModule *gModule = NULL; // Module entry point extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsViewModule *viewModule; @@ -256,9 +256,9 @@ nsViewModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass NS_IMETHODIMP nsViewModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, - const char *registryLocation, - const char *componentType) + nsIFile* aPath, + const char *registryLocation, + const char *componentType) { nsresult rv; @@ -268,19 +268,19 @@ nsViewModule::RegisterSelf(nsIComponentManager *aCompMgr, rv = aCompMgr->RegisterComponentSpec(kCViewManager, "View Manager", "component://netscape/view-manager", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) return rv; rv = aCompMgr->RegisterComponentSpec(kCView, "View", "component://netscape/view", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) return rv; rv = aCompMgr->RegisterComponentSpec(kCScrollingView, "Scrolling View", "component://netscape/scrolling-view", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) return rv; rv = aCompMgr->RegisterComponentSpec(kCScrollPortView, "Scroll Port View", "component://netscape/scroll-port-view", - location, PR_TRUE, PR_TRUE); + aPath, PR_TRUE, PR_TRUE); #ifdef DEBUG_dp printf("done.\n"); #endif @@ -289,17 +289,17 @@ nsViewModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsViewModule::UnregisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec *location, - const char *registryLocation) + nsIFile* aPath, + const char *registryLocation) { nsresult rv; - rv = aCompMgr->UnregisterComponentSpec(kCViewManager, location); + rv = aCompMgr->UnregisterComponentSpec(kCViewManager, aPath); if (NS_FAILED(rv)) return rv; - rv = aCompMgr->UnregisterComponentSpec(kCView, location); + rv = aCompMgr->UnregisterComponentSpec(kCView, aPath); if (NS_FAILED(rv)) return rv; - rv = aCompMgr->UnregisterComponentSpec(kCScrollingView, location); + rv = aCompMgr->UnregisterComponentSpec(kCScrollingView, aPath); if (NS_FAILED(rv)) return rv; - rv = aCompMgr->UnregisterComponentSpec(kCScrollPortView, location); + rv = aCompMgr->UnregisterComponentSpec(kCScrollPortView, aPath); return rv; } diff --git a/mozilla/widget/src/gtk/nsClipboard.cpp b/mozilla/widget/src/gtk/nsClipboard.cpp index 05c1260b09f..7b67b329a19 100644 --- a/mozilla/widget/src/gtk/nsClipboard.cpp +++ b/mozilla/widget/src/gtk/nsClipboard.cpp @@ -23,6 +23,7 @@ #include "nsClipboard.h" #include "nsCOMPtr.h" +#include "nsFileSpec.h" #include "nsISupportsArray.h" #include "nsIClipboardOwner.h" diff --git a/mozilla/widget/src/gtk/nsSound.cpp b/mozilla/widget/src/gtk/nsSound.cpp index d08eabd8793..9eabb75ddba 100644 --- a/mozilla/widget/src/gtk/nsSound.cpp +++ b/mozilla/widget/src/gtk/nsSound.cpp @@ -28,6 +28,8 @@ #include "prlink.h" +#include "nsFileSpec.h" +#include "nsIFileSpec.h" #include "nsSound.h" #include "nsIURI.h" diff --git a/mozilla/xpcom/base/nsDebug.cpp b/mozilla/xpcom/base/nsDebug.cpp index 45d66904f0b..0f5911b6bb0 100644 --- a/mozilla/xpcom/base/nsDebug.cpp +++ b/mozilla/xpcom/base/nsDebug.cpp @@ -25,6 +25,9 @@ #include "prlog.h" #include "prinit.h" #include "plstr.h" +#include "nsError.h" +#include "prerror.h" +#include "prerr.h" #if defined(XP_BEOS) /* For DEBUGGER macros */ @@ -298,3 +301,30 @@ NS_COM void nsDebug::Error(const char* aMessage, { Assertion(aMessage, "Error", aFile, aLine); } + +//////////////////////////////////////////////////////////////////////////////// + +NS_COM nsresult +NS_ErrorAccordingToNSPR() +{ + PRErrorCode err = PR_GetError(); + switch (err) { + case PR_OUT_OF_MEMORY_ERROR: return NS_ERROR_OUT_OF_MEMORY; + case PR_WOULD_BLOCK_ERROR: return NS_BASE_STREAM_WOULD_BLOCK; + case PR_FILE_NOT_FOUND_ERROR: return NS_ERROR_FILE_NOT_FOUND; + case PR_READ_ONLY_FILESYSTEM_ERROR: return NS_ERROR_FILE_READ_ONLY; + case PR_NOT_DIRECTORY_ERROR: return NS_ERROR_FILE_NOT_DIRECTORY; + case PR_IS_DIRECTORY_ERROR: return NS_ERROR_FILE_IS_DIRECTORY; + case PR_LOOP_ERROR: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; + case PR_FILE_EXISTS_ERROR: return NS_ERROR_FILE_ALREADY_EXISTS; + case PR_FILE_IS_LOCKED_ERROR: return NS_ERROR_FILE_IS_LOCKED; + case PR_FILE_TOO_BIG_ERROR: return NS_ERROR_FILE_TOO_BIG; + case PR_NO_DEVICE_SPACE_ERROR: return NS_ERROR_FILE_NO_DEVICE_SPACE; + case PR_NAME_TOO_LONG_ERROR: return NS_ERROR_FILE_NAME_TOO_LONG; + case PR_DIRECTORY_NOT_EMPTY_ERROR: return NS_ERROR_FILE_DIR_NOT_EMPTY; + case PR_NO_ACCESS_RIGHTS_ERROR: return NS_ERROR_FILE_ACCESS_DENIED; + default: return NS_ERROR_FAILURE; + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/base/nsError.h b/mozilla/xpcom/base/nsError.h index 62f954e5478..25b933541ef 100644 --- a/mozilla/xpcom/base/nsError.h +++ b/mozilla/xpcom/base/nsError.h @@ -23,9 +23,8 @@ #ifndef nsError_h #define nsError_h -#ifndef prtypes_h___ +#include "nsCom.h" #include "prtypes.h" -#endif /** * Generic result data type @@ -215,6 +214,52 @@ typedef PRUint32 nsresult; /*@}*/ +//////////////////////////////////////////////////////////////////////////////// +// I/O Errors + +/// Stream closed +#define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2) +/// Error from the operating system +#define NS_BASE_STREAM_OSERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 3) +/// Illegal arguments +#define NS_BASE_STREAM_ILLEGAL_ARGS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 4) +/// For unichar streams +#define NS_BASE_STREAM_NO_CONVERTER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 5) +/// For unichar streams +#define NS_BASE_STREAM_BAD_CONVERSION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 6) + +#define NS_BASE_STREAM_WOULD_BLOCK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 7) + + +#define NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1) +#define NS_ERROR_FILE_UNRESOLVABLE_SYMLINK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 2) +#define NS_ERROR_FILE_EXECUTION_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 3) +#define NS_ERROR_FILE_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 4) +#define NS_ERROR_FILE_DESTINATION_NOT_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 5) +#define NS_ERROR_FILE_TARGET_DOES_NOT_EXIST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 6) +#define NS_ERROR_FILE_COPY_OR_MOVE_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 7) +#define NS_ERROR_FILE_ALREADY_EXISTS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 8) +#define NS_ERROR_FILE_INVALID_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 9) +#define NS_ERROR_FILE_DISK_FULL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 10) +#define NS_ERROR_FILE_CORRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 11) +#define NS_ERROR_FILE_NOT_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 12) +#define NS_ERROR_FILE_IS_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 13) +#define NS_ERROR_FILE_IS_LOCKED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 14) +#define NS_ERROR_FILE_TOO_BIG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 15) +#define NS_ERROR_FILE_NO_DEVICE_SPACE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 16) +#define NS_ERROR_FILE_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 17) +#define NS_ERROR_FILE_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 18) +#define NS_ERROR_FILE_READ_ONLY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 19) +#define NS_ERROR_FILE_DIR_NOT_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 20) +#define NS_ERROR_FILE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 21) + +//////////////////////////////////////////////////////////////////////////////// +// This will return the nsresult corresponding to the most recent NSPR failure +// returned by PR_GetError. + +extern NS_COM nsresult +NS_ErrorAccordingToNSPR(); + //////////////////////////////////////////////////////////////////////////////// #ifdef XP_PC @@ -222,5 +267,6 @@ typedef PRUint32 nsresult; #pragma warning(disable: 4275) // non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode' #endif -#endif +//////////////////////////////////////////////////////////////////////////////// +#endif diff --git a/mozilla/xpcom/base/nsISupportsUtils.h b/mozilla/xpcom/base/nsISupportsUtils.h index 60c9fcf8b10..88561a207c5 100644 --- a/mozilla/xpcom/base/nsISupportsUtils.h +++ b/mozilla/xpcom/base/nsISupportsUtils.h @@ -545,20 +545,56 @@ NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \ return Super::Release(); \ } \ -#define NS_IMPL_QUERY_INTERFACE_INHERITED(Class,Super,AdditionalInterface) \ -NS_IMETHODIMP Class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \ -{ \ - if (!aInstancePtr) return NS_ERROR_NULL_POINTER; \ - if (aIID.Equals(NS_GET_IID(AdditionalInterface))) { \ - *aInstancePtr = NS_STATIC_CAST(AdditionalInterface*, this); \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - return Super::QueryInterface(aIID, aInstancePtr); \ +#define NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_HEAD(Class) \ + +#define NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + foundInterface = 0; \ + nsresult status; \ + if ( !foundInterface ) \ + return Super::QueryInterface(aIID, aInstancePtr); \ + else \ + { \ + NS_ADDREF(foundInterface); \ + status = NS_OK; \ + } \ + *aInstancePtr = foundInterface; \ + return status; \ } \ -#define NS_IMPL_ISUPPORTS_INHERITED(Class, Super, AdditionalInterface) \ - NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) \ +#define NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, i1) \ + NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \ + +#define NS_IMPL_QUERY_INTERFACE_INHERITED0(Class, Super) \ + NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + +#define NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \ + NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_BODY(i1) \ + NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + +#define NS_IMPL_QUERY_INTERFACE_INHERITED2(Class, Super, i1, i2) \ + NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_BODY(i1) \ + NS_IMPL_QUERY_BODY(i2) \ + NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + +#define NS_IMPL_ISUPPORTS_INHERITED(Class, Super, i1) \ + NS_IMPL_ISUPPORTS_INHERITED1(Class, Super, i1) \ + +#define NS_IMPL_ISUPPORTS_INHERITED0(Class, Super) \ + NS_IMPL_QUERY_INTERFACE_INHERITED0(Class, Super) \ + NS_IMPL_ADDREF_INHERITED(Class, Super) \ + NS_IMPL_RELEASE_INHERITED(Class, Super) \ + +#define NS_IMPL_ISUPPORTS_INHERITED1(Class, Super, i1) \ + NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \ + NS_IMPL_ADDREF_INHERITED(Class, Super) \ + NS_IMPL_RELEASE_INHERITED(Class, Super) \ + +#define NS_IMPL_ISUPPORTS_INHERITED2(Class, Super, i1, i2) \ + NS_IMPL_QUERY_INTERFACE_INHERITED2(Class, Super, i1, i2) \ NS_IMPL_ADDREF_INHERITED(Class, Super) \ NS_IMPL_RELEASE_INHERITED(Class, Super) \ diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index 70f1c1b29fa..f4102cc2040 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -26,6 +26,7 @@ #include "nsObserverService.h" #include "nsObserver.h" #include "nsProperties.h" +#include "nsIProperties.h" #include "nsPersistentProperties.h" #include "nsScriptableInputStream.h" @@ -49,15 +50,15 @@ #include "nsProxyObjectManager.h" #include "nsProxyEventPrivate.h" // access to the impl of nsProxyObjectManager for the generic factory registration. -#include "nsFileSpecImpl.h" #include "xptinfo.h" #include "nsThread.h" -#ifdef _NEW_NSIFILE -#include "nsIFileImpl.h" -#include "nsIDirEnumeratorImpl.h" -#endif +#include "nsFileSpecImpl.h" + +#include "nsILocalFile.h" +#include "nsLocalFile.h" +#include "nsDirectoryService.h" #ifdef GC_LEAK_DETECTOR #include "nsLeakDetector.h" @@ -171,8 +172,9 @@ nsICaseConversion *gCaseConv = NULL; extern nsIServiceManager* gServiceManager; extern PRBool gShuttingDown; -nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result, - nsFileSpec *binDirectory) +nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result, + nsIFile* binDirectory +) { nsresult rv = NS_OK; @@ -197,6 +199,8 @@ nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result, // 2. Create the Component Manager and register with global service manager // It is understood that the component manager can use the global service manager. nsComponentManagerImpl *compMgr = NULL; + nsDirectoryService *directoryService = NULL; + if (nsComponentManagerImpl::gComponentManager == NULL) { compMgr = new nsComponentManagerImpl(); @@ -204,24 +208,32 @@ nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result, return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(compMgr); - // Set the registry file - if (binDirectory && binDirectory->IsDirectory()) + rv = nsDirectoryService::Create(nsnull, + NS_GET_IID(nsIProperties), + (void**)&directoryService); // needs to be around for life of product + PRBool value; + + if (binDirectory) { - nsSpecialSystemDirectory::Set(nsSpecialSystemDirectory::Moz_BinDirectory, - binDirectory); + rv = binDirectory->IsDirectory(&value); + + if (NS_SUCCEEDED(rv) && value) + directoryService->Define("xpcom.currentProcess", binDirectory); } + rv = compMgr->Init(); if (NS_FAILED(rv)) { NS_RELEASE(compMgr); return rv; } + nsComponentManagerImpl::gComponentManager = compMgr; } rv = servMgr->RegisterService(kComponentManagerCID, NS_STATIC_CAST(nsIComponentManager*, compMgr)); if (NS_FAILED(rv)) return rv; - + // 3. Register the global services with the component manager so that // clients can create new objects. @@ -270,18 +282,6 @@ nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result, ByteBufferImpl::Create); if (NS_FAILED(rv)) return rv; - rv = RegisterGenericFactory(compMgr, kFileSpecCID, - NS_FILESPEC_CLASSNAME, - NS_FILESPEC_PROGID, - nsFileSpecImpl::Create); - if (NS_FAILED(rv)) return rv; - - rv = RegisterGenericFactory(compMgr, kDirectoryIteratorCID, - NS_DIRECTORYITERATOR_CLASSNAME, - NS_DIRECTORYITERATOR_PROGID, - nsDirectoryIteratorImpl::Create); - if (NS_FAILED(rv)) return rv; - rv = RegisterGenericFactory(compMgr, kScriptableInputStreamCID, NS_SCRIPTABLEINPUTSTREAM_CLASSNAME, NS_SCRIPTABLEINPUTSTREAM_PROGID, @@ -460,20 +460,29 @@ nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result, nsSupportsVoidImplConstructor); if (NS_FAILED(rv)) return rv; -#ifdef _NEW_NSIFILE - rv = RegisterGenericFactory(compMgr, nsIFileImpl::GetCID(), - NS_FILE_CLASSNAME, - NS_FILE_PROGID, - nsIFileImpl::Create); + rv = RegisterGenericFactory(compMgr, nsLocalFile::GetCID(), + NS_LOCAL_FILE_CLASSNAME, + NS_LOCAL_FILE_PROGID, + nsLocalFile::nsLocalFileConstructor); if (NS_FAILED(rv)) return rv; - rv = RegisterGenericFactory(compMgr, nsIDirEnumeratorImpl::GetCID(), - NS_DIRECTORY_ENUMERATOR_CLASS, - NS_DIRECTORY_ENUMERATOR_PROGID, - nsIDirEnumeratorImpl::Create); + rv = RegisterGenericFactory(compMgr, nsDirectoryService::GetCID(), + NS_DIRECTORY_SERVICE_CLASSNAME, + NS_DIRECTORY_SERVICE_PROGID, + nsDirectoryService::Create); if (NS_FAILED(rv)) return rv; -#endif + rv = RegisterGenericFactory(compMgr, kFileSpecCID, + NS_FILESPEC_CLASSNAME, + NS_FILESPEC_PROGID, + nsFileSpecImpl::Create); + if (NS_FAILED(rv)) return rv; + + rv = RegisterGenericFactory(compMgr, kDirectoryIteratorCID, + NS_DIRECTORYITERATOR_CLASSNAME, + NS_DIRECTORYITERATOR_PROGID, + nsDirectoryIteratorImpl::Create); + if (NS_FAILED(rv)) return rv; // Prepopulate registry for performance // Ignore return value. It is ok if this fails. diff --git a/mozilla/xpcom/components/makefile.win b/mozilla/xpcom/components/makefile.win index aef35211e8e..d3bafec42eb 100644 --- a/mozilla/xpcom/components/makefile.win +++ b/mozilla/xpcom/components/makefile.win @@ -59,6 +59,7 @@ LINCS = \ -I$(PUBLIC)\libreg \ -I..\base \ -I..\threads \ + -I..\io \ $(NULL) LCFLAGS = -DUSE_NSREG -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/xpcom/components/nsComponentManager.cpp b/mozilla/xpcom/components/nsComponentManager.cpp index 21b8f17c7d6..9aac70a9d5c 100644 --- a/mozilla/xpcom/components/nsComponentManager.cpp +++ b/mozilla/xpcom/components/nsComponentManager.cpp @@ -25,7 +25,6 @@ #include "nsCOMPtr.h" #include "nsComponentManager.h" #include "nsIServiceManager.h" -#include "nsSpecialSystemDirectory.h" #include "nsCRT.h" #include "nsIEnumerator.h" #include "nsIModule.h" @@ -35,6 +34,10 @@ #include "nsNativeComponentLoader.h" #include "nsXPIDLString.h" +#include "nsILocalFile.h" +#include "nsLocalFile.h" +#include "nsDirectoryService.h" + #include "plstr.h" #include "prlink.h" #include "prsystem.h" @@ -244,15 +247,15 @@ nsresult nsComponentManagerImpl::Init(void) nsStringKey loaderKey(nativeComponentType); mLoaders->Put(&loaderKey, mNativeComponentLoader); } - - PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, - ("nsComponentManager: Initialized.")); #ifdef USE_REGISTRY - NR_StartupRegistry(); - PlatformInit(); + NR_StartupRegistry(); + PlatformInit(); #endif + PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, + ("nsComponentManager: Initialized.")); + return NS_OK; } @@ -413,13 +416,17 @@ nsComponentManagerImpl::PlatformInit(void) rv = mRegistry->AddSubtree(nsIRegistry::Common, classIDKeyName, &mCLSIDKey); if (NS_FAILED(rv)) return rv; + + nsCOMPtr directoryService; + rv = nsDirectoryService::Create(nsnull, + NS_GET_IID(nsIProperties), + getter_AddRefs(directoryService)); + + directoryService->Get("xpcom.currentProcess.componentDirectory", NS_GET_IID(nsIFile), (void**)&mComponentsDir); - mComponentsDir = - new nsSpecialSystemDirectory(nsSpecialSystemDirectory::XPCOM_CurrentProcessComponentDirectory); if (!mComponentsDir) return NS_ERROR_OUT_OF_MEMORY; - mComponentsDirLen = strlen(mComponentsDir->GetNativePathCString()); - + if (mNativeComponentLoader) { /* now that we have the registry, Init the native loader */ rv = mNativeComponentLoader->Init(this, mRegistry); @@ -961,21 +968,21 @@ nsDll* nsComponentManagerImpl::CreateCachedDllName(const char *dllName) -nsDll* nsComponentManagerImpl::CreateCachedDll(nsIFileSpec *dllSpec) +nsDll* nsComponentManagerImpl::CreateCachedDll(nsIFile *dllSpec) { nsDll *dll = NULL; - PRUint32 modDate; - PRUint32 size; + PRInt64 modDate; + PRInt64 size; if (NS_FAILED(dllSpec->GetModDate(&modDate)) || NS_FAILED(dllSpec->GetFileSize(&size))) return NULL; char *persistentDescriptor = NULL; - if (NS_FAILED(dllSpec->GetPersistentDescriptorString(&persistentDescriptor))) + if (NS_FAILED(dllSpec->GetPath(&persistentDescriptor))) return NULL; dll = CreateCachedDll(persistentDescriptor, modDate, size); - nsCRT::free(persistentDescriptor); + nsAllocator::free(persistentDescriptor); return dll; } @@ -1322,42 +1329,36 @@ nsComponentManagerImpl::RegistryNameForLib(const char *aLibName, } nsresult -nsComponentManagerImpl::RegistryLocationForSpec(nsIFileSpec *aSpec, +nsComponentManagerImpl::RegistryLocationForSpec(nsIFile *aSpec, char **aRegistryName) { nsresult rv; - nsFileSpec spec; - if (NS_FAILED(rv = aSpec->GetFileSpec(&spec))) - return rv; + + if (!mComponentsDir) + return NS_ERROR_NOT_INITIALIZED; - if (spec.IsChildOf(*mComponentsDir)){ - /* - * According to sfraser, this sort of string magic is ``Mac-safe''. - * Who knew? - */ - const char *nativePath; - nativePath = spec.GetNativePathCString(); - nativePath += mComponentsDirLen; -#ifdef XP_MAC // XXX move relativize-fragment logic to nsFileSpec? - if (nativePath[0] != ':') - nativePath--; -#else - char sep = PR_GetDirectorySeparator(); - if (nativePath[0] == sep) - nativePath++; -#endif - rv = MakeRegistryName(nativePath, XPCOM_RELCOMPONENT_PREFIX, + PRBool containedIn; + mComponentsDir->IsContainedIn(aSpec, PR_TRUE, &containedIn); // dougt FIX! + + char *persistentDescriptor; + + if (containedIn){ + rv = aSpec->GetLeafName(&persistentDescriptor); + if (NS_FAILED(rv)) + return rv; + rv = MakeRegistryName(persistentDescriptor, XPCOM_RELCOMPONENT_PREFIX, aRegistryName); } else { /* absolute names include volume info on Mac, so persistent descriptor */ - char *persistentDescriptor; - rv = aSpec->GetPersistentDescriptorString(&persistentDescriptor); + rv = aSpec->GetPath(&persistentDescriptor); if (NS_FAILED(rv)) return rv; rv = MakeRegistryName(persistentDescriptor, XPCOM_ABSCOMPONENT_PREFIX, aRegistryName); - nsAllocator::Free(persistentDescriptor); } + + if (persistentDescriptor) + nsAllocator::Free(persistentDescriptor); return rv; @@ -1365,7 +1366,7 @@ nsComponentManagerImpl::RegistryLocationForSpec(nsIFileSpec *aSpec, nsresult nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation, - nsIFileSpec **aSpec) + nsIFile **aSpec) { nsresult rv; if (!aLocation || !aSpec) @@ -1373,15 +1374,28 @@ nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation, /* abs:/full/path/to/libcomponent.so */ if (!nsCRT::strncmp(aLocation, XPCOM_ABSCOMPONENT_PREFIX, 4)) { - if (NS_FAILED(rv = NS_NewFileSpec(aSpec))) - return rv; - return (*aSpec)->SetPersistentDescriptorString((char *)aLocation + 4); + + nsLocalFile* file = new nsLocalFile; + if (!file) return NS_ERROR_FAILURE; + + rv = file->InitWithPath(((char *)aLocation + 4)); + file->QueryInterface(NS_GET_IID(nsILocalFile), (void**)aSpec); + return rv; } if (!nsCRT::strncmp(aLocation, XPCOM_RELCOMPONENT_PREFIX, 4)) { - nsFileSpec compSpec = (*mComponentsDir); - compSpec += (aLocation + 4); - return NS_NewFileSpecWithSpec(compSpec, aSpec); + + if (!mComponentsDir) + return NS_ERROR_NOT_INITIALIZED; + + nsILocalFile* file = nsnull; + rv = mComponentsDir->Clone((nsIFile**)&file); + + if (NS_FAILED(rv)) return rv; + + rv = file->Append(aLocation + 4); + *aSpec = file; + return rv; } *aSpec = nsnull; return NS_ERROR_INVALID_ARG; @@ -1470,7 +1484,7 @@ nsresult nsComponentManagerImpl::RegisterComponentWithType(const nsCID &aClass, const char *aClassName, const char *aProgID, - nsIFileSpec *aSpec, + nsIFile *aSpec, const char *aLocation, PRBool aReplace, PRBool aPersist, @@ -1483,13 +1497,13 @@ nsComponentManagerImpl::RegisterComponentWithType(const nsCID &aClass, } /* - * Register a component, using whatever they stuck in the FileSpec. + * Register a component, using whatever they stuck in the nsIFile. */ nsresult nsComponentManagerImpl::RegisterComponentSpec(const nsCID &aClass, const char *aClassName, const char *aProgID, - nsIFileSpec *aLibrarySpec, + nsIFile *aLibrarySpec, PRBool aReplace, PRBool aPersist) { @@ -1821,24 +1835,23 @@ nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass, delete [] buf; } - // Convert the persistent descriptor into a nsIFileSpec - nsCOMPtrlibSpec; - rv = CreateInstanceByProgID(NS_FILESPEC_PROGID, NULL, - NS_GET_IID(nsIFileSpec), - getter_AddRefs(libSpec)); + // Convert the persistent descriptor into a nsIFile + nsLocalFile* libSpec = new nsLocalFile; + if (!libSpec) return NS_ERROR_FAILURE; + + rv = libSpec->InitWithPath((char *)aLibrary); + if (NS_FAILED(rv)) return rv; - rv = libSpec->SetPersistentDescriptorString((char *)aLibrary); - if (NS_FAILED(rv)) return rv; - - return UnregisterComponentSpec(aClass, libSpec); + + return UnregisterComponentSpec(aClass, libSpec); } nsresult nsComponentManagerImpl::UnregisterComponentSpec(const nsCID &aClass, - nsIFileSpec *aLibrarySpec) + nsIFile *aLibrarySpec) { char *aLibrary; - nsresult rv = aLibrarySpec->GetPersistentDescriptorString(&aLibrary); + nsresult rv = aLibrarySpec->GetPath(&aLibrary); if (NS_FAILED(rv)) return NS_ERROR_INVALID_ARG; @@ -1973,7 +1986,7 @@ nsComponentManagerImpl::UnloadLibraries(nsIServiceManager *serviceMgr, PRInt32 a struct AutoReg_closure { int when; - nsIFileSpec *spec; + nsIFile *spec; nsresult status; // this is a hack around Enumerate's void return nsIComponentLoader *native; PRBool registered; @@ -2012,17 +2025,20 @@ RegisterDeferred_enumerate(nsHashKey *key, void *aData, void *aClosure) } nsresult -nsComponentManagerImpl::AutoRegister(PRInt32 when, nsIFileSpec *inDirSpec) +nsComponentManagerImpl::AutoRegister(PRInt32 when, nsIFile *inDirSpec) { - nsCOMPtr dir; + nsCOMPtr dir; nsresult rv; if (inDirSpec) { dir = inDirSpec; } else { // Do default components directory - nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::XPCOM_CurrentProcessComponentDirectory); - rv = NS_NewFileSpecWithSpec(sysdir, getter_AddRefs(dir)); + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv); + if (NS_FAILED(rv)) return rv; + + + rv = directoryService->Get("xpcom.currentProcess.componentDirectory", NS_GET_IID(nsIFile), getter_AddRefs(dir)); if (NS_FAILED(rv)) return rv; // XXX translate error code? } @@ -2109,7 +2125,7 @@ AutoRegisterComponent_enumerate(nsHashKey *key, void *aData, void *aClosure) nsresult nsComponentManagerImpl::AutoRegisterComponent(PRInt32 when, - nsIFileSpec *component) + nsIFile *component) { struct AutoReg_closure closure; diff --git a/mozilla/xpcom/components/nsComponentManager.h b/mozilla/xpcom/components/nsComponentManager.h index 697c98119b3..ebf0dfa4d73 100644 --- a/mozilla/xpcom/components/nsComponentManager.h +++ b/mozilla/xpcom/components/nsComponentManager.h @@ -35,6 +35,7 @@ #include "nsCOMPtr.h" #include "nsWeakReference.h" #include "nsXPIDLString.h" +#include "nsIFile.h" class nsFactoryEntry; class nsDll; @@ -87,7 +88,7 @@ protected: nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory); nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, PRBool checkRegistry); - nsresult SyncComponentsInDir(PRInt32 when, nsIFileSpec *dirSpec); + nsresult SyncComponentsInDir(PRInt32 when, nsIFile *dirSpec); nsresult SelfRegisterDll(nsDll *dll); nsresult SelfUnregisterDll(nsDll *dll); nsresult HashProgID(const char *aprogID, const nsCID &aClass); @@ -115,9 +116,8 @@ protected: PRBool mPrePopulationDone; nsRegistryKey mLoadersKey; nsNativeComponentLoader *mNativeComponentLoader; - nsSpecialSystemDirectory *mComponentsDir; - PRUint32 mComponentsDirLen; - + nsIFile *mComponentsDir; + // Shutdown #define NS_SHUTDOWN_NEVERHAPPENED 0 #define NS_SHUTDOWN_INPROGRESS 1 diff --git a/mozilla/xpcom/components/nsComponentManagerUtils.h b/mozilla/xpcom/components/nsComponentManagerUtils.h index dd876cb5359..fe12a95dbcd 100644 --- a/mozilla/xpcom/components/nsComponentManagerUtils.h +++ b/mozilla/xpcom/components/nsComponentManagerUtils.h @@ -109,7 +109,7 @@ public: // Manually register a dynamically loaded component. // The libraryPersistentDescriptor is what gets passed to the library // self register function from ComponentManager. The format of this string - // is the same as nsIFileSpec::GetPersistentDescriptorString() + // is the same as nsIFile::GetPath() // // This function will go away in favour of RegisterComponentSpec. In fact, // it internally turns around and calls RegisterComponentSpec. @@ -125,7 +125,7 @@ public: static nsresult RegisterComponentSpec(const nsCID &aClass, const char *aClassName, const char *aProgID, - nsIFileSpec *aLibrary, + nsIFile *aLibrary, PRBool aReplace, PRBool aPersist); @@ -150,7 +150,7 @@ public: // Manually unregister a dynamically loaded component static nsresult UnregisterComponentSpec(const nsCID &aClass, - nsIFileSpec *aLibrarySpec); + nsIFile *aLibrarySpec); // Unload dynamically loaded factories that are not in use static nsresult FreeLibraries(void); @@ -158,10 +158,9 @@ public: // DLL registration support // If directory is NULL, then AutoRegister will try registering components - // in the default components directory which is got by - // nsSpecialSystemDirectory(XPCOM_CurrentProcessComponentDirectory) - static nsresult AutoRegister(PRInt32 when, nsIFileSpec* directory); - static nsresult AutoRegisterComponent(PRInt32 when, nsIFileSpec *component); + // in the default components directory. + static nsresult AutoRegister(PRInt32 when, nsIFile* directory); + static nsresult AutoRegisterComponent(PRInt32 when, nsIFile *component); // Is the given CID currently registered? static nsresult IsRegistered(const nsCID &aClass, diff --git a/mozilla/xpcom/components/nsGenericFactory.cpp b/mozilla/xpcom/components/nsGenericFactory.cpp index 7f04dfd080b..03ad6744c3d 100644 --- a/mozilla/xpcom/components/nsGenericFactory.cpp +++ b/mozilla/xpcom/components/nsGenericFactory.cpp @@ -21,8 +21,11 @@ * Pierre Phaneuf */ -#include "nsGenericFactory.h" +// DO NOT COPY THIS CODE INTO YOUR SOURCE! USE NS_IMPL_NSGETMODULE() + +#include "nsGenericFactory.h" +#include "nsCRT.h" nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor) : mConstructor(constructor), mDestructor(NULL) { @@ -196,7 +199,7 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -238,7 +241,7 @@ nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG diff --git a/mozilla/xpcom/components/nsIComponentLoader.idl b/mozilla/xpcom/components/nsIComponentLoader.idl index 1f51ee74420..ee3943d0dae 100644 --- a/mozilla/xpcom/components/nsIComponentLoader.idl +++ b/mozilla/xpcom/components/nsIComponentLoader.idl @@ -18,7 +18,7 @@ #include "nsISupports.idl" #include "nsIFactory.idl" -#include "nsIFileSpec.idl" +#include "nsIFile.idl" #include "nsIComponentManager.idl" [object, uuid(c073cfc0-567c-11d3-aec1-0000f8e25c06)] @@ -57,7 +57,7 @@ interface nsIComponentLoader : nsISupports { /** * AutoRegister components in the given directory. */ - void autoRegisterComponents(in long aWhen, in nsIFileSpec aDirectory); + void autoRegisterComponents(in long aWhen, in nsIFile aDirectory); /** * AutoRegister the given component. @@ -66,7 +66,7 @@ interface nsIComponentLoader : nsISupports { * attempt to register the component (wrong type) and ``throws'' an * NS_FAILED code if there was an error during registration. */ - boolean autoRegisterComponent(in long aWhen, in nsIFileSpec aComponent); + boolean autoRegisterComponent(in long aWhen, in nsIFile aComponent); /** * Register any deferred (NS_ERROR_FACTORY_REGISTER_AGAIN) components. diff --git a/mozilla/xpcom/components/nsIComponentManager.idl b/mozilla/xpcom/components/nsIComponentManager.idl index 401ef50cf43..a1c656e6c5e 100644 --- a/mozilla/xpcom/components/nsIComponentManager.idl +++ b/mozilla/xpcom/components/nsIComponentManager.idl @@ -17,10 +17,11 @@ */ #include "nsISupports.idl" -#include "nsIFileSpec.idl" #include "nsIFactory.idl" #include "nsIEnumerator.idl" +interface nsIFile; + /* should this be in nsroot.idl? */ native nsCID(nsCID); @@ -42,12 +43,12 @@ interface nsIComponentManager : nsISupports /** * Produce a rel: or abs: registry location for a given spec. */ - string registryLocationForSpec(in nsIFileSpec aSpec); + string registryLocationForSpec(in nsIFile aSpec); /** * Create a full FileSpec for the rel:/abs: location provided. */ - nsIFileSpec specForRegistryLocation(in string aLocation); + nsIFile specForRegistryLocation(in string aLocation); void registerFactory(in nsCIDRef aClass, in string aClassName, in string aProgID, in nsIFactory aFactory, @@ -60,13 +61,13 @@ interface nsIComponentManager : nsISupports void registerComponentWithType(in nsCIDRef aClass, in string aClassName, in string aProgID, - in nsIFileSpec aSpec, + in nsIFile aSpec, in string aLocation, in boolean aReplace, in boolean aPersist, in string aType); void registerComponentSpec(in nsCIDRef aClass, in string aClassName, - in string aProgID, in nsIFileSpec aLibrary, + in string aProgID, in nsIFile aLibrary, in boolean aReplace, in boolean aPersist); void registerComponentLib(in nsCIDRef aClass, in string aClassName, in string aProgID, in string adllName, @@ -75,7 +76,7 @@ interface nsIComponentManager : nsISupports void unregisterFactory(in nsCIDRef aClass, in nsIFactory aFactory); void unregisterComponent(in nsCIDRef aClass, in string aLibrary); void unregisterComponentSpec(in nsCIDRef aClass, - in nsIFileSpec aLibrarySpec); + in nsIFile aLibrarySpec); void freeLibraries(); const long NS_Startup = 0; @@ -83,8 +84,8 @@ interface nsIComponentManager : nsISupports const long NS_Timer = 2; const long NS_Shutdown = 3; - void autoRegister(in long when, in nsIFileSpec directory); - void autoRegisterComponent(in long when, in nsIFileSpec component); + void autoRegister(in long when, in nsIFile directory); + void autoRegisterComponent(in long when, in nsIFile component); boolean isRegistered(in nsCIDRef aClass); nsIEnumerator enumerateCLSIDs(); diff --git a/mozilla/xpcom/components/nsIGenericFactory.h b/mozilla/xpcom/components/nsIGenericFactory.h index 554c314d049..427e60b00d4 100644 --- a/mozilla/xpcom/components/nsIGenericFactory.h +++ b/mozilla/xpcom/components/nsIGenericFactory.h @@ -73,12 +73,12 @@ NS_NewGenericFactory(nsIGenericFactory* *result, #include "nsIModule.h" typedef NS_CALLBACK(NSRegisterSelfProcPtr) (nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, + nsIFile *aPath, const char *registryLocation, const char *componentType); typedef NS_CALLBACK(NSUnregisterSelfProcPtr) (nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, + nsIFile *aPath, const char *registryLocation); /** @@ -110,7 +110,7 @@ NS_NewGenericModule(const char* moduleName, #define NS_IMPL_NSGETMODULE_WITH_DTOR(_name, _components, _dtor) \ extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, \ - nsIFileSpec* location, \ + nsIFile* location, \ nsIModule** result) \ { \ return NS_NewGenericModule((_name), \ diff --git a/mozilla/xpcom/components/nsIModule.idl b/mozilla/xpcom/components/nsIModule.idl index 76088266886..11f344caa5b 100644 --- a/mozilla/xpcom/components/nsIModule.idl +++ b/mozilla/xpcom/components/nsIModule.idl @@ -22,7 +22,7 @@ #include "nsISupports.idl" #include "nsIFactory.idl" -#include "nsIFileSpec.idl" +#include "nsIFile.idl" #include "nsIComponentManager.idl" [scriptable, uuid(7392D032-5371-11d3-994E-00805FD26FEE)] @@ -38,10 +38,10 @@ interface nsIModule : nsISupports [retval, iid_is(aIID)] out nsQIResult result); // Component registration - void registerSelf(in nsIComponentManager aCompMgr, in nsIFileSpec location, + void registerSelf(in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation, in string componentType); - void unregisterSelf(in nsIComponentManager aCompMgr, in nsIFileSpec location, + void unregisterSelf(in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation); // Module load management @@ -60,11 +60,11 @@ interface nsIModule : nsISupports #define NS_GET_MODULE_SYMBOL "NSGetModule" extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *aCompMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj); typedef nsresult (*nsGetModuleProc)(nsIComponentManager *aCompMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj); %} diff --git a/mozilla/xpcom/components/nsIRegistry.idl b/mozilla/xpcom/components/nsIRegistry.idl index 095b82943ae..0813b21b394 100644 --- a/mozilla/xpcom/components/nsIRegistry.idl +++ b/mozilla/xpcom/components/nsIRegistry.idl @@ -42,6 +42,8 @@ interface nsIRegistry : nsISupports void setString(in nsRegistryKey baseKey, in string path, in string value); PRInt32 getInt(in nsRegistryKey baseKey, in string path); void setInt(in nsRegistryKey baseKey, in string path, in PRInt32 value); + PRInt64 getLongLong(in nsRegistryKey baseKey, in string path); + void setLongLong(in nsRegistryKey baseKey, in string path, inout PRInt64 value); nsRegistryKey addSubtree(in nsRegistryKey baseKey, in string path); void removeSubtree(in nsRegistryKey baseKey, in string path); diff --git a/mozilla/xpcom/components/nsIServiceManager.h b/mozilla/xpcom/components/nsIServiceManager.h index d8915a3e532..1c8dc20378b 100644 --- a/mozilla/xpcom/components/nsIServiceManager.h +++ b/mozilla/xpcom/components/nsIServiceManager.h @@ -32,7 +32,6 @@ #endif class nsIShutdownListener; -class nsFileSpec; #define NS_ISERVICEMANAGER_IID \ { /* cf0df3b0-3401-11d2-8163-006008119d7a */ \ @@ -337,7 +336,7 @@ NS_NewServiceManager(nsIServiceManager* *result); // directory must contain a "components" directory and a component.reg file. extern NS_COM nsresult -NS_InitXPCOM(nsIServiceManager* *result, nsFileSpec* binDirectory); +NS_InitXPCOM(nsIServiceManager* *result, nsIFile* binDirectory); //////////////////////////////////////////////////////////////////////////////// // Shutdown of XPCOM. XPCOM hosts an observer (NS_XPCOM_SHUTDOWN_OBSERVER_ID) diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index 0b6800c5497..f65cc896e74 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -30,6 +30,12 @@ #include "nsHashtableEnumerator.h" #include "nsXPIDLString.h" +#ifdef XP_MAC // sdagley dougt fix +#include +#include +#include "nsLocalFileMac.h" +#endif + #define PRINT_CRITICAL_ERROR_TO_SCREEN 1 #define USE_REGISTRY 1 #define XPCOM_USE_NSGETFACTORY 1 @@ -75,7 +81,8 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID, /* Should this all live in xcDll? */ nsDll *dll; - rv = CreateDll(nsnull, aLocation, 0, 0, &dll); + PRInt64 mod = LL_Zero(), size = LL_Zero(); + rv = CreateDll(nsnull, aLocation, &mod, &size, &dll); if (NS_FAILED(rv)) return rv; @@ -85,7 +92,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID, if (!dll->IsLoaded()) { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsNativeComponentLoader: loading \"%s\"", - dll->GetNativePath())); + dll->GetDisplayPath())); if (!dll->Load()) { @@ -119,7 +126,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID, fprintf(stderr, "XPCOM: Component %s uses DEPRECATED\n" " NSGetFactory interface. This could break " - "AT ANY TIME.\n", dll->GetNativePath()); + "AT ANY TIME.\n", dll->GetDisplayPath()); } #endif } @@ -128,7 +135,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID, PR_LOG(nsComponentManagerLog, (NS_SUCCEEDED(rv) ? PR_LOG_DEBUG : PR_LOG_ERROR), ("nsNativeComponentLoader: Factory creation %s " "%s -> %s\n", (NS_SUCCEEDED(rv) ? "passed" : "FAILED"), - aLocation, dll->GetNativePath())); + aLocation, dll->GetDisplayPath())); // If the dll failed to get us a factory. But the dll registered that // it would be able to create a factory for this CID. mmh! @@ -197,10 +204,10 @@ nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) // Create nsDll with this name nsDll *dll = NULL; - PRUint32 lastModTime = 0; - PRUint32 fileSize = 0; + PRInt64 lastModTime; + PRInt64 fileSize; GetRegistryDllInfo(libKey, &lastModTime, &fileSize); - rv = CreateDll(NULL, library, lastModTime, fileSize, &dll); + rv = CreateDll(NULL, library, &lastModTime, &fileSize, &dll); if (NS_FAILED(rv)) continue; } @@ -209,7 +216,7 @@ nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) NS_IMETHODIMP nsNativeComponentLoader::AutoRegisterComponents(PRInt32 aWhen, - nsIFileSpec *aDirectory) + nsIFile *aDirectory) { #ifdef DEBUG /* do we _really_ want to print this every time? */ @@ -228,7 +235,7 @@ nsNativeComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsresult nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when, - nsIFileSpec *dir) + nsIFile *dir) { nsresult rv = NS_ERROR_FAILURE; PRBool isDir = PR_FALSE; @@ -248,22 +255,20 @@ nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when, #endif /* 0 */ // Create a directory iterator - nsCOMPtrdirIterator; - rv = nsComponentManager::CreateInstance(NS_DIRECTORYITERATOR_PROGID, NULL, - NS_GET_IID(nsIDirectoryIterator), - getter_AddRefs(dirIterator)); + nsCOMPtr dirIterator; + rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator)); + if (NS_FAILED(rv)) return rv; - rv = dirIterator->Init(dir, PR_FALSE); - if (NS_FAILED(rv)) return rv; - + // whip through the directory to register every file - nsIFileSpec *dirEntry = NULL; + nsCOMPtr dirEntry; PRBool more = PR_FALSE; - rv = dirIterator->Exists(&more); + + rv = dirIterator->HasMoreElements(&more); if (NS_FAILED(rv)) return rv; while (more == PR_TRUE) { - rv = dirIterator->GetCurrentSpec(&dirEntry); + rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry)); if (NS_SUCCEEDED(rv)) { rv = dirEntry->IsDirectory(&isDir); @@ -281,11 +286,8 @@ nsNativeComponentLoader::RegisterComponentsInDir(PRInt32 when, rv = AutoRegisterComponent(when, dirEntry, ®istered); } } - NS_RELEASE(dirEntry); } - rv = dirIterator->Next(); - if (NS_FAILED(rv)) return rv; - rv = dirIterator->Exists(&more); + rv = dirIterator->HasMoreElements(&more); if (NS_FAILED(rv)) return rv; } @@ -334,7 +336,7 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when) { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Unload cant get nsIModule or CanUnload for %s", - dll->GetNativePath())); + dll->GetDisplayPath())); return rv; } } @@ -354,7 +356,7 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when) { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: nsIModule::CanUnload() returned error for %s.", - dll->GetNativePath())); + dll->GetDisplayPath())); return rv; } @@ -363,7 +365,7 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when) if (dllMarkedForUnload) { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, - ("nsComponentManager: + Unloading \"%s\".", dll->GetNativePath())); + ("nsComponentManager: + Unloading \"%s\".", dll->GetDisplayPath())); #if 0 // XXX dlls aren't counting their outstanding instances correctly // XXX hence, dont unload until this gets enforced. @@ -373,13 +375,13 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when) else { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, - ("nsComponentManager: Ready for unload \"%s\".", dll->GetNativePath())); + ("nsComponentManager: Ready for unload \"%s\".", dll->GetDisplayPath())); } } else { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, - ("nsComponentManager: + NOT Unloading %s", dll->GetNativePath())); + ("nsComponentManager: + NOT Unloading %s", dll->GetDisplayPath())); rv = NS_ERROR_FAILURE; } return rv; @@ -434,7 +436,7 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll, } PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, - ("nsNativeComponentLoader: + Loaded \"%s\".", dll->GetNativePath())); + ("nsNativeComponentLoader: + Loaded \"%s\".", dll->GetDisplayPath())); // Tell the module to self register nsCOMPtr mobj; @@ -443,8 +445,8 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll, { PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, ("nsNativeComponentLoader: %s using nsIModule to register self.", - dll->GetNativePath())); - nsCOMPtr fs; + dll->GetDisplayPath())); + nsCOMPtr fs; res = dll->GetDllSpec(getter_AddRefs(fs)); if (NS_SUCCEEDED(res)) res = mobj->RegisterSelf(mCompMgr, fs, registryLocation, @@ -453,7 +455,7 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll, { PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, ("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.", - dll->GetNativePath())); + dll->GetDisplayPath())); } mobj = NULL; // Force a release of the Module object before unload() } @@ -481,8 +483,12 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll, // installed. if (res != NS_ERROR_FACTORY_REGISTER_AGAIN) { dll->Sync(); - SetRegistryDllInfo(registryLocation, dll->GetLastModifiedTime(), - dll->GetSize()); + + PRInt64 modTime, size; + dll->GetLastModifiedTime(&modTime); + dll->GetSize(&size); + + SetRegistryDllInfo(registryLocation, &modTime, &size); } return res; @@ -553,7 +559,7 @@ nsNativeComponentLoader::DumpLoadError(nsDll *dll, PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, ("nsNativeComponentLoader: %s(%s) Load FAILED with error:%s", aCallerName, - dll->GetNativePath(), + dll->GetDisplayPath(), (const char *) errorMsg)); @@ -563,7 +569,7 @@ nsNativeComponentLoader::DumpLoadError(nsDll *dll, "nsNativeComponentLoader: %s(%s) Load FAILED with error: %s\n" "**************************************************\n", aCallerName, - dll->GetNativePath(), + dll->GetDisplayPath(), (const char *) errorMsg); #endif @@ -592,15 +598,15 @@ nsNativeComponentLoader::SelfUnregisterDll(nsDll *dll) if (NS_SUCCEEDED(res)) { PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, - ("nsNativeComponentLoader: %s using nsIModule to unregister self.", dll->GetNativePath())); - nsCOMPtr fs; + ("nsNativeComponentLoader: %s using nsIModule to unregister self.", dll->GetDisplayPath())); + nsCOMPtr fs; res = dll->GetDllSpec(getter_AddRefs(fs)); if (NS_SUCCEEDED(res)) res = mobj->UnregisterSelf(mCompMgr, fs, /* XXX location */ ""); else { PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, - ("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.", dll->GetNativePath())); + ("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.", dll->GetDisplayPath())); } mobj = NULL; // Force a release of the Module object before unload() } @@ -623,7 +629,7 @@ nsNativeComponentLoader::SelfUnregisterDll(nsDll *dll) nsresult nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, - nsIFileSpec *component, + nsIFile *component, PRBool *registered) { nsresult rv; @@ -664,25 +670,28 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, // deal only with files that have a valid extension PRBool validExtension = PR_FALSE; -#ifdef XP_MAC - // rjc - on Mac, check the file's type code (skip checking the creator code) - nsFileSpec fs; - if (NS_FAILED(rv = component->GetFileSpec(&fs))) - return(rv); +#ifdef XP_MAC // sdagley dougt fix + + // rjc - on Mac, check the file's type code (skip checking the creator code) + + nsCOMPtr localFileMac = do_QueryInterface(component); + if (localFileMac) + { + OSType type; + OSType creator; + rv = localFileMac->GetFileTypeAndCreator(&type, &creator); + if (NS_SUCCEEDED(rv)) + { + // on Mac, Mozilla shared libraries are of type 'shlb' + // Note: we don't check the creator (which for Mozilla is 'MOZZ') + // so that 3rd party shared libraries will be noticed! + if (type == 'shlb') + { + validExtension = PR_TRUE; + } + } + } - CInfoPBRec catInfo; - OSErr err = fs.GetCatInfo(catInfo); - if (!err) - { - // on Mac, Mozilla shared libraries are of type 'shlb' - // Note: we don't check the creator (which for Mozilla is 'MOZZ') - // so that 3rd party shared libraries will be noticed! - if ((catInfo.hFileInfo.ioFlFndrInfo.fdType == 'shlb') - /* && (catInfo.hFileInfo.ioFlFndrInfo.fdCreator == 'MOZZ') */ ) - { - validExtension = PR_TRUE; - } - } #else char *leafName = NULL; rv = component->GetLeafName(&leafName); @@ -701,7 +710,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, break; } } - if (leafName) nsCRT::free(leafName); + if (leafName) nsAllocator::Free(leafName); #endif if (validExtension == PR_FALSE) @@ -718,7 +727,8 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, // Get the registry representation of the dll, if any nsDll *dll; - rv = CreateDll(component, persistentDescriptor, 0, 0, &dll); + PRInt64 mod = LL_Zero(), size = LL_Zero(); + rv = CreateDll(component, persistentDescriptor, &mod, &size, &dll); if (NS_FAILED(rv)) return rv; @@ -729,7 +739,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsNativeComponentLoader: + nsDll not NS_OK \"%s\". Skipping...", - dll->GetNativePath())); + dll->GetDisplayPath())); return NS_ERROR_FAILURE; } @@ -739,7 +749,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, // Dll hasn't changed. Skip. PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: + nsDll not changed \"%s\". Skipping...", - dll->GetNativePath())); + dll->GetDisplayPath())); return NS_OK; } @@ -760,7 +770,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsNativeComponentLoader: *** Dll already loaded. " "Cannot unload either. Hence cannot re-register " - "\"%s\". Skipping...", dll->GetNativePath())); + "\"%s\". Skipping...", dll->GetDisplayPath())); return rv; } else { @@ -769,7 +779,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, dll->Unload(); PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsNativeComponentLoader: + Unloading \"%s\". (no CanUnloadProc).", - dll->GetNativePath())); + dll->GetDisplayPath())); } } // dll isloaded @@ -782,7 +792,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, // loaded. Whoever taught dp programming... PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsNativeComponentLoader: Dll still loaded. Cannot re-register " - "\"%s\". Skipping...", dll->GetNativePath())); + "\"%s\". Skipping...", dll->GetDisplayPath())); return NS_ERROR_FAILURE; } } // dll != NULL @@ -812,7 +822,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, } else { PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, ("nsNativeComponentLoader: Autoregistration FAILED for " - "\"%s\". Skipping...", dll->GetNativePath())); + "\"%s\". Skipping...", dll->GetDisplayPath())); return NS_ERROR_FACTORY_NOT_REGISTERED; } } @@ -820,7 +830,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, { PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsNativeComponentLoader: Autoregistration Passed for " - "\"%s\".", dll->GetNativePath())); + "\"%s\".", dll->GetDisplayPath())); // Marking dll along with modified time and size in the // registry happens at PlatformRegister(). No need to do it // here again. @@ -885,8 +895,8 @@ nsNativeComponentLoader::UnloadAll(PRInt32 aWhen) nsresult nsNativeComponentLoader::GetRegistryDllInfo(const char *aLocation, - PRUint32 *lastModifiedTime, - PRUint32 *fileSize) + PRInt64 *lastModifiedTime, + PRInt64 *fileSize) { nsresult rv; @@ -899,16 +909,16 @@ nsNativeComponentLoader::GetRegistryDllInfo(const char *aLocation, nsresult nsNativeComponentLoader::GetRegistryDllInfo(nsRegistryKey key, - PRUint32 *lastModifiedTime, - PRUint32 *fileSize) + PRInt64 *lastModifiedTime, + PRInt64 *fileSize) { - PRInt32 lastMod; - nsresult rv = mRegistry->GetInt(key, lastModValueName, &lastMod); + PRInt64 lastMod; + nsresult rv = mRegistry->GetLongLong(key, lastModValueName, &lastMod); if (NS_FAILED(rv)) return rv; *lastModifiedTime = lastMod; - PRInt32 fsize; - rv = mRegistry->GetInt(key, fileSizeValueName, &fsize); + PRInt64 fsize; + rv = mRegistry->GetLongLong(key, fileSizeValueName, &fsize); if (NS_FAILED(rv)) return rv; *fileSize = fsize; @@ -917,17 +927,17 @@ nsNativeComponentLoader::GetRegistryDllInfo(nsRegistryKey key, nsresult nsNativeComponentLoader::SetRegistryDllInfo(const char *aLocation, - PRUint32 lastModifiedTime, - PRUint32 fileSize) + PRInt64 *lastModifiedTime, + PRInt64 *fileSize) { nsresult rv; nsRegistryKey key; rv = mRegistry->GetSubtreeRaw(mXPCOMKey, aLocation, &key); if (NS_FAILED(rv)) return rv; - rv = mRegistry->SetInt(key, lastModValueName, lastModifiedTime); + rv = mRegistry->SetLongLong(key, lastModValueName, lastModifiedTime); if (NS_FAILED(rv)) return rv; - rv = mRegistry->SetInt(key, fileSizeValueName, fileSize); + rv = mRegistry->SetLongLong(key, fileSizeValueName, fileSize); return rv; } @@ -950,13 +960,13 @@ nsNativeComponentLoader::SetRegistryDllInfo(const char *aLocation, // registry along with its lastModTime and fileSize. // {NULL, rel:libpref.so, 8985659, 20987} nsresult -nsNativeComponentLoader::CreateDll(nsIFileSpec *aSpec, const char *aLocation, - PRUint32 modificationTime, PRUint32 fileSize, +nsNativeComponentLoader::CreateDll(nsIFile *aSpec, const char *aLocation, + PRInt64 *modificationTime, PRInt64 *fileSize, nsDll **aDll) { nsDll *dll; - nsFileSpec dllSpec; - nsCOMPtr spec; + nsCOMPtr dllSpec; + nsCOMPtr spec; nsresult rv; nsStringKey key(aLocation); @@ -986,10 +996,15 @@ nsNativeComponentLoader::CreateDll(nsIFileSpec *aSpec, const char *aLocation, if (!dll) { - if (modificationTime == 0 && fileSize == 0) + PR_ASSERT(modificationTime != NULL); + PR_ASSERT(fileSize != NULL); + + PRInt64 zit = LL_Zero(); + + if (LL_EQ(*modificationTime,zit) && LL_EQ(*fileSize,zit)) { // Get the modtime and filesize from the registry - rv = GetRegistryDllInfo(aLocation, &modificationTime, &fileSize); + rv = GetRegistryDllInfo(aLocation, modificationTime, fileSize); } dll = new nsDll(spec, aLocation, modificationTime, fileSize); } @@ -1016,7 +1031,7 @@ nsNativeComponentLoader::GetFactoryFromModule(nsDll *aDll, const nsCID &aCID, PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsNativeComponentLoader: %s using nsIModule to get factory", - aDll->GetNativePath())); + aDll->GetDisplayPath())); return module->GetClassObject(mCompMgr, aCID, NS_GET_IID(nsIFactory), (void **)aFactory); @@ -1037,7 +1052,7 @@ nsNativeComponentLoader::GetFactoryFromNSGetFactory(nsDll *aDll, PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsNativeComponentLoader: %s using OBSOLETE NSGetFactory\n", - aDll->GetNativePath())); + aDll->GetDisplayPath())); /* * There was a time when CLSIDToProgID was used to get className diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.h b/mozilla/xpcom/components/nsNativeComponentLoader.h index dc6790bc03c..8625d41196c 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.h +++ b/mozilla/xpcom/components/nsNativeComponentLoader.h @@ -20,9 +20,9 @@ #include "nsIRegistry.h" #include "nsIComponentLoader.h" #include "nsIComponentManager.h" -#include "nsIFileSpec.h" +#include "nsIFile.h" #include "nsIRegistry.h" -#include "nsSpecialSystemDirectory.h" +#include "nsDirectoryService.h" #include "nsCOMPtr.h" #include "nsHashtable.h" #include "nsVoidArray.h" @@ -41,29 +41,29 @@ class nsNativeComponentLoader : public nsIComponentLoader { virtual ~nsNativeComponentLoader(); nsresult RegistryNameForLib(const char *aLibName, char **aRegistryName); - nsresult RegistryNameForSpec(nsIFileSpec *aSpec, + nsresult RegistryNameForSpec(nsIFile *aSpec, char **aRegistryName); protected: nsCOMPtr mRegistry; nsIComponentManager* mCompMgr; // weak reference -- backpointer nsObjectHashtable* mDllStore; - NS_IMETHOD RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir); + NS_IMETHOD RegisterComponentsInDir(PRInt32 when, nsIFile *dir); nsRegistryKey mXPCOMKey; nsVoidArray mDeferredComponents; private: - nsresult CreateDll(nsIFileSpec *aSpec, const char *aLocation, - PRUint32 modifiedTime, PRUint32 fileSize, nsDll **aDll); + nsresult CreateDll(nsIFile *aSpec, const char *aLocation, + PRInt64 *modifiedTime, PRInt64 *fileSize, nsDll **aDll); nsresult SelfRegisterDll(nsDll *dll, const char *registryLocation, PRBool deferred); nsresult SelfUnregisterDll(nsDll *dll); - nsresult GetRegistryDllInfo(const char *aLocation, PRUint32 *lastModifiedTime, - PRUint32 *fileSize); - nsresult GetRegistryDllInfo(nsRegistryKey key, PRUint32 *lastModifiedTime, - PRUint32 *fileSize); - nsresult SetRegistryDllInfo(const char *aLocation, PRUint32 lastModifiedTime, - PRUint32 fileSize); + nsresult GetRegistryDllInfo(const char *aLocation, PRInt64 *lastModifiedTime, + PRInt64 *fileSize); + nsresult GetRegistryDllInfo(nsRegistryKey key, PRInt64 *lastModifiedTime, + PRInt64 *fileSize); + nsresult SetRegistryDllInfo(const char *aLocation, PRInt64 *lastModifiedTime, + PRInt64 *fileSize); nsresult GetFactoryFromModule(nsDll *aDll, const nsCID &aCID, nsIFactory **aFactory); /* obsolete! already! */ diff --git a/mozilla/xpcom/components/nsRegistry.cpp b/mozilla/xpcom/components/nsRegistry.cpp index c764dc36d2b..faf6709dea2 100644 --- a/mozilla/xpcom/components/nsRegistry.cpp +++ b/mozilla/xpcom/components/nsRegistry.cpp @@ -22,7 +22,7 @@ #include "nsIRegistry.h" #include "nsIEnumerator.h" -#include "nsSpecialSystemDirectory.h" +#include "nsDirectoryService.h" #include "NSReg.h" #include "prmem.h" #include "prlock.h" @@ -30,6 +30,9 @@ #include "nsCRT.h" #include "nsAllocator.h" +#include "nsCOMPtr.h" +#include "nsILocalFile.h" +#include "nsIServiceManager.h" /* extra locking for the paranoid */ /* #define EXTRA_THREADSAFE */ #ifndef EXTRA_THREADSAFE @@ -321,7 +324,7 @@ NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue ) | Vanilla nsRegistry constructor. | ------------------------------------------------------------------------------*/ nsRegistry::nsRegistry() - : mReg(0), mCurRegFile(NULL), mCurRegID(0) { + : mReg(0), mCurRegFile(nsnull), mCurRegID(0) { NS_INIT_REFCNT(); #ifdef EXTRA_THREADSAFE mregLock = PR_NewLock(); @@ -397,16 +400,26 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) { // Ensure existing registry is closed. Close(); + + nsresult rv; + nsCOMPtr registryLocation; - nsSpecialSystemDirectory *registryLocation = NULL; PRBool foundReg = PR_FALSE; switch ( (nsWellKnownRegistry) regid ) { case ApplicationComponentRegistry: - registryLocation = - new nsSpecialSystemDirectory(nsSpecialSystemDirectory::XPCOM_CurrentProcessComponentRegistry); - if (registryLocation != NULL) - foundReg = PR_TRUE; + { + nsCOMPtr directoryService; + rv = nsDirectoryService::Create(nsnull, + NS_GET_IID(nsIProperties), + getter_AddRefs(directoryService)); + if (NS_FAILED(rv)) return rv; + directoryService->Get("xpcom.currentProcess.componentRegistry", NS_GET_IID(nsIFile), + (void**)®istryLocation); + + if (registryLocation != nsnull) + foundReg = PR_TRUE; + } break; default: @@ -417,16 +430,17 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) { return NS_ERROR_REG_BADTYPE; } - const char *regFile = registryLocation->GetNativePathCString(); + char *regFile; + registryLocation->GetPath(®File); // dougt fix... + #ifdef DEBUG_dp printf("nsRegistry: Opening std registry %s\n", regFile); #endif /* DEBUG_dp */ + PR_Lock(mregLock); err = NR_RegOpen((char*)regFile, &mReg ); PR_Unlock(mregLock); - // Cleanup - delete registryLocation; // Store the registry that was opened for optimizing future opens. mCurRegID = regid; @@ -463,7 +477,7 @@ NS_IMETHODIMP nsRegistry::Close() { mReg = 0; if (mCurRegFile) nsCRT::free(mCurRegFile); - mCurRegFile = NULL; + mCurRegFile = nsnull; mCurRegID = 0; } return regerr2nsresult( err ); @@ -607,6 +621,24 @@ NS_IMETHODIMP nsRegistry::GetInt( nsRegistryKey baseKey, const char *path, PRInt return rv; } + +/*---------------------------- nsRegistry::GetLongLong-------------------------- +| This function is just shorthand for fetching a 1-element PRInt64 array. We | +| implement it "manually" using NR_RegGetEntry | +------------------------------------------------------------------------------*/ +NS_IMETHODIMP nsRegistry::GetLongLong( nsRegistryKey baseKey, const char *path, PRInt64 *result ) { + REGERR err = REGERR_OK; + + PR_Lock(mregLock); + + uint32 length = sizeof(PRInt64); + err = NR_RegGetEntry( mReg,(RKEY)baseKey,(char*)path,(void*)result,&length); + + PR_Unlock(mregLock); + + // Convert status. + return regerr2nsresult( err ); +} /*---------------------------- nsRegistry::SetInt ------------------------------ | Write out the value as a one-element PRInt32 array, using NR_RegSetEntry. | ------------------------------------------------------------------------------*/ @@ -625,6 +657,28 @@ NS_IMETHODIMP nsRegistry::SetInt( nsRegistryKey baseKey, const char *path, PRInt return regerr2nsresult( err ); } + + +/*---------------------------- nsRegistry::SetLongLong--------------------------- +| Write out the value as a one-element PRInt64 array, using NR_RegSetEntry. | +------------------------------------------------------------------------------*/ +NS_IMETHODIMP nsRegistry::SetLongLong( nsRegistryKey baseKey, const char *path, PRInt64* value ) { + REGERR err = REGERR_OK; + // Set the contents. + PR_Lock(mregLock); + + err = NR_RegSetEntry( mReg, + (RKEY)baseKey, + (char*)path, + REGTYPE_ENTRY_BYTES, + (void*)value, + sizeof(PRInt64) ); + + PR_Unlock(mregLock); + // Convert result. + return regerr2nsresult( err ); +} + /*-------------------------- nsRegistry::AddSubtree ---------------------------- | Add a new registry subkey with the specified name, using NR_RegAddKey. | ------------------------------------------------------------------------------*/ @@ -1133,7 +1187,7 @@ nsRegistryNode::nsRegistryNode( HREG hReg, char *name, RKEY childKey ) : mReg( hReg ), mChildKey( childKey ) { NS_INIT_REFCNT(); - PR_ASSERT(name != NULL); + PR_ASSERT(name != nsnull); strcpy(mName, name); #ifdef EXTRA_THREADSAFE @@ -1157,7 +1211,7 @@ nsRegistryNode::~nsRegistryNode() | using NR_RegEnumSubkeys. | ------------------------------------------------------------------------------*/ NS_IMETHODIMP nsRegistryNode::GetName( char **result ) { - if (result == NULL) return NS_ERROR_NULL_POINTER; + if (result == nsnull) return NS_ERROR_NULL_POINTER; // Make sure there is a place to put the result. *result = nsCRT::strdup( mName ); if ( !*result ) return NS_ERROR_OUT_OF_MEMORY; @@ -1170,7 +1224,7 @@ NS_IMETHODIMP nsRegistryNode::GetName( char **result ) { ------------------------------------------------------------------------------*/ NS_IMETHODIMP nsRegistryNode::GetKey( nsRegistryKey *r_key ) { nsresult rv = NS_OK; - if (r_key == NULL) return NS_ERROR_NULL_POINTER; + if (r_key == nsnull) return NS_ERROR_NULL_POINTER; *r_key = mChildKey; return rv; } @@ -1298,10 +1352,10 @@ nsRegistryFactory::CreateInstance(nsISupports *aOuter, nsresult rv = NS_OK; nsRegistry* newRegistry; - if(aResult == NULL) { + if(aResult == nsnull) { return NS_ERROR_NULL_POINTER; } else { - *aResult = NULL; + *aResult = nsnull; } if(0 != aOuter) { @@ -1310,7 +1364,7 @@ nsRegistryFactory::CreateInstance(nsISupports *aOuter, NS_NEWXPCOM(newRegistry, nsRegistry); - if(newRegistry == NULL) { + if(newRegistry == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/xpcom/components/nsRepository.cpp b/mozilla/xpcom/components/nsRepository.cpp index a1389ec315e..fa0603d8125 100644 --- a/mozilla/xpcom/components/nsRepository.cpp +++ b/mozilla/xpcom/components/nsRepository.cpp @@ -126,7 +126,7 @@ nsresult nsComponentManager::RegisterComponentSpec(const nsCID &aClass, const char *aClassName, const char *aProgID, - nsIFileSpec *aLibrary, + nsIFile *aLibrary, PRBool aReplace, PRBool aPersist) { @@ -174,7 +174,7 @@ nsComponentManager::UnregisterComponent(const nsCID &aClass, nsresult nsComponentManager::UnregisterComponentSpec(const nsCID &aClass, - nsIFileSpec *aLibrarySpec) + nsIFile *aLibrarySpec) { nsIComponentManager* cm; nsresult rv = NS_GetGlobalComponentManager(&cm); @@ -192,7 +192,7 @@ nsComponentManager::FreeLibraries(void) } nsresult -nsComponentManager::AutoRegister(PRInt32 when, nsIFileSpec *directory) +nsComponentManager::AutoRegister(PRInt32 when, nsIFile *directory) { nsIComponentManager* cm; nsresult rv = NS_GetGlobalComponentManager(&cm); @@ -202,7 +202,7 @@ nsComponentManager::AutoRegister(PRInt32 when, nsIFileSpec *directory) nsresult nsComponentManager::AutoRegisterComponent(PRInt32 when, - nsIFileSpec *fullname) + nsIFile *fullname) { nsIComponentManager* cm; nsresult rv = NS_GetGlobalComponentManager(&cm); diff --git a/mozilla/xpcom/components/xcDll.cpp b/mozilla/xpcom/components/xcDll.cpp index 9a8100287cb..9bbecd51687 100644 --- a/mozilla/xpcom/components/xcDll.cpp +++ b/mozilla/xpcom/components/xcDll.cpp @@ -32,20 +32,23 @@ #include "nsDebug.h" #include "nsIComponentManager.h" #include "nsIModule.h" -#include "nsIFileSpec.h" +#include "nsILocalFile.h" #include "nsCOMPtr.h" - +#include "nsCRT.h" #ifdef XP_MAC #include "prlink_mac.h" #endif nsDll::nsDll(const char *codeDllName, int type) - : m_dllName(NULL), m_dllSpec(NULL), m_modDate(0), m_size(0), + : m_dllName(NULL), m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL), m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE), m_registryLocation(0) { + m_modDate = LL_Zero(); + m_size = LL_Zero(); + if (!codeDllName || !*codeDllName) { m_status = DLL_INVALID_PARAM; @@ -59,12 +62,16 @@ nsDll::nsDll(const char *codeDllName, int type) } } -nsDll::nsDll(nsIFileSpec *dllSpec, const char *registryLocation) - : m_dllName(NULL), m_dllSpec(dllSpec), m_modDate(0), m_size(0), +nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation) + : m_dllName(NULL), m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL), m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE) { + m_modDate = LL_Zero(); + m_size = LL_Zero(); + m_dllSpec = dllSpec; + m_registryLocation = nsCRT::strdup(registryLocation); Init(dllSpec); // Populate m_modDate and m_size @@ -74,25 +81,41 @@ nsDll::nsDll(nsIFileSpec *dllSpec, const char *registryLocation) } } -nsDll::nsDll(nsIFileSpec *dllSpec, const char *registryLocation, PRUint32 modDate, PRUint32 fileSize) - : m_dllName(NULL), m_dllSpec(dllSpec), m_modDate(0), m_size(0), +nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation, PRInt64* modDate, PRInt64* fileSize) + : m_dllName(NULL), m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL), m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE) { + m_modDate = LL_Zero(); + m_size = LL_Zero(); + m_dllSpec = dllSpec; + m_registryLocation = nsCRT::strdup(registryLocation); Init(dllSpec); - m_modDate = modDate; - m_size = fileSize; + + if (modDate) + m_modDate = *modDate; + else + m_modDate = LL_Zero(); + + if (fileSize) + m_size = *fileSize; + else + m_size = LL_Zero(); + } nsDll::nsDll(const char *libPersistentDescriptor) - : m_dllName(NULL), m_dllSpec(NULL), m_modDate(0), m_size(0), + : m_dllName(NULL), m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL), m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE), m_registryLocation(0) { + m_modDate = LL_Zero(); + m_size = LL_Zero(); + Init(libPersistentDescriptor); // Populate m_modDate and m_size if (NS_FAILED(Sync())) @@ -101,26 +124,36 @@ nsDll::nsDll(const char *libPersistentDescriptor) } } -nsDll::nsDll(const char *libPersistentDescriptor, PRUint32 modDate, PRUint32 fileSize) - : m_dllName(NULL), m_dllSpec(NULL), m_modDate(0), m_size(0), +nsDll::nsDll(const char *libPersistentDescriptor, PRInt64* modDate, PRInt64* fileSize) + : m_dllName(NULL), m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL), m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE), m_registryLocation(0) { + m_modDate = LL_Zero(); + m_size = LL_Zero(); + Init(libPersistentDescriptor); // and overwrite the modData and fileSize - m_modDate = modDate; - m_size = fileSize; + + if (modDate) + m_modDate = *modDate; + else + m_modDate = LL_Zero(); + + if (fileSize) + m_size = *fileSize; + else + m_size = LL_Zero(); } void -nsDll::Init(nsIFileSpec *dllSpec) +nsDll::Init(nsIFile *dllSpec) { // Addref the m_dllSpec m_dllSpec = dllSpec; - NS_ADDREF(m_dllSpec); // Make sure we are dealing with a file PRBool isFile = PR_FALSE; @@ -145,8 +178,8 @@ void nsDll::Init(const char *libPersistentDescriptor) { nsresult rv; - m_modDate = 0; - m_size = 0; + m_modDate = LL_Zero(); + m_size = LL_Zero(); if (libPersistentDescriptor == NULL) { @@ -155,23 +188,26 @@ nsDll::Init(const char *libPersistentDescriptor) } // Create a FileSpec from the persistentDescriptor - nsIFileSpec *dllSpec = NULL; - rv = nsComponentManager::CreateInstance(NS_FILESPEC_PROGID, NULL, NS_GET_IID(nsIFileSpec), (void **) &dllSpec); + nsCOMPtr dllSpec; + + nsCID clsid; + nsComponentManager::ProgIDToClassID(NS_LOCAL_FILE_PROGID, &clsid); + rv = nsComponentManager::CreateInstance(clsid, nsnull, + NS_GET_IID(nsILocalFile), + (void**)getter_AddRefs(dllSpec)); if (NS_FAILED(rv)) { m_status = DLL_INVALID_PARAM; return; } - rv = dllSpec->SetPersistentDescriptorString((char *)libPersistentDescriptor); + rv = dllSpec->InitWithPath((char *)libPersistentDescriptor); if (NS_FAILED(rv)) { m_status = DLL_INVALID_PARAM; return; } - Init(dllSpec); - NS_RELEASE(dllSpec); } @@ -186,8 +222,6 @@ nsDll::~nsDll(void) // Hence turn it back on after all the above have been removed. Unload(); #endif - if (m_dllSpec) - NS_RELEASE(m_dllSpec); if (m_dllName) nsCRT::free(m_dllName); if (m_persistentDescriptor) @@ -206,20 +240,21 @@ nsDll::Sync() return NS_ERROR_FAILURE; // Populate m_modDate and m_size - nsresult rv = m_dllSpec->GetModDate(&m_modDate); + nsresult rv = m_dllSpec->GetLastModificationDate(&m_modDate); if (NS_FAILED(rv)) return rv; rv = m_dllSpec->GetFileSize(&m_size); return rv; } + const char * -nsDll::GetNativePath() +nsDll::GetDisplayPath() { if (m_dllName) return m_dllName; if (m_nativePath) return m_nativePath; - m_dllSpec->GetNativePath(&m_nativePath); + m_dllSpec->GetPath(&m_nativePath); return m_nativePath; } @@ -230,7 +265,7 @@ nsDll::GetPersistentDescriptorString() return m_dllName; if (m_persistentDescriptor) return m_persistentDescriptor; - m_dllSpec->GetPersistentDescriptorString(&m_persistentDescriptor); + m_dllSpec->GetPath(&m_persistentDescriptor); return m_persistentDescriptor; } @@ -241,15 +276,17 @@ nsDll::HasChanged() return PR_FALSE; // If mod date has changed, then dll has changed - PRBool modDateChanged = PR_FALSE; - nsresult rv = m_dllSpec->ModDateChanged(m_modDate, &modDateChanged); - if (NS_FAILED(rv) || modDateChanged == PR_TRUE) + PRInt64 currentDate; + + nsresult rv = m_dllSpec->GetLastModificationDate(¤tDate); + + if (NS_FAILED(rv) || LL_NE(currentDate, m_modDate)) return PR_TRUE; // If size has changed, then dll has changed - PRUint32 aSize = 0; + PRInt64 aSize; rv = m_dllSpec->GetFileSize(&aSize); - if (NS_FAILED(rv) || aSize != m_size) + if (NS_FAILED(rv) || LL_NE(aSize, m_size)) return PR_TRUE; return PR_FALSE; @@ -270,35 +307,43 @@ PRBool nsDll::Load(void) return (PR_TRUE); } - if (m_dllName) + if (m_dllSpec) { - m_instance = PR_LoadLibrary(m_dllName); - } - else - { -#ifndef XP_MAC - char *nsprPath = NULL; - nsresult rv = m_dllSpec->GetNSPRPath(&nsprPath); - if (NS_FAILED(rv)) return PR_FALSE; + nsCOMPtr localFile = do_QueryInterface(m_dllSpec); - m_instance = PR_LoadLibrary(nsprPath); - - nsCRT::free(nsprPath); -#else - nsFileSpec fileSpec; - m_dllSpec->GetFileSpec(&fileSpec); - FSSpec libSpec = fileSpec.GetFSSpec(); - m_instance = PR_LoadIndexedFragment(&libSpec, 0); - -#endif /* XP_MAC */ - } + if (localFile) + localFile->Load(&m_instance); + + #ifdef NS_BUILD_REFCNT_LOGGING - if (m_instance) { - // Inform refcnt tracer of new library so that calls through the - // new library can be traced. - nsTraceRefcnt::LoadLibrarySymbols(GetNativePath(), GetInstance()); - } + if (m_instance) { + // Inform refcnt tracer of new library so that calls through the + // new library can be traced. + char* displayPath; + m_dllSpec->GetPath(&displayPath); + nsTraceRefcnt::LoadLibrarySymbols(displayPath, m_instance); + nsAllocator::Free(displayPath); + } #endif + + + } + else if (m_dllName) + { + // if there is not an nsIFile, but there is a dll name, just try to load that.. + m_instance = PR_LoadLibrary(m_dllName); + +#ifdef NS_BUILD_REFCNT_LOGGING + if (m_instance) { + // Inform refcnt tracer of new library so that calls through the + // new library can be traced. + nsTraceRefcnt::LoadLibrarySymbols(m_dllName, m_instance); + } +#endif + + + } + return ((m_instance == NULL) ? PR_FALSE : PR_TRUE); } @@ -334,13 +379,13 @@ void * nsDll::FindSymbol(const char *symbol) // Component dll specific functions -nsresult nsDll::GetDllSpec(nsIFileSpec **fsobj) +nsresult nsDll::GetDllSpec(nsIFile **fsobj) { NS_ASSERTION(m_dllSpec, "m_dllSpec NULL"); NS_ASSERTION(fsobj, "xcDll::GetModule : Null argument" ); - NS_ADDREF(m_dllSpec); *fsobj = m_dllSpec; + NS_ADDREF(*fsobj); return NS_OK; } @@ -363,9 +408,9 @@ nsresult nsDll::GetModule(nsISupports *servMgr, nsIModule **cobj) // If not already loaded, load it now. if (Load() != PR_TRUE) return NS_ERROR_FAILURE; - // We need a nsIFileSpec for location. If we dont + // We need a nsIFile for location. If we dont // have one, create one. - if (m_dllSpec == NULL && m_dllName) + if (!m_dllSpec && m_dllName) { // Create m_dllSpec from m_dllName } diff --git a/mozilla/xpcom/components/xcDll.h b/mozilla/xpcom/components/xcDll.h index ea1f3a28da6..c76d666a0de 100644 --- a/mozilla/xpcom/components/xcDll.h +++ b/mozilla/xpcom/components/xcDll.h @@ -28,14 +28,15 @@ * dp Suresh */ -#include "prio.h" -#include "prlink.h" -#include "nsISupports.h" - #ifndef xcDll_h__ #define xcDll_h__ -class nsIFileSpec; +#include "prio.h" +#include "prlink.h" +#include "nsISupports.h" +#include "nsIFile.h" +#include "nsCOMPtr.h" + class nsIModule; class nsIServiceManager; @@ -53,9 +54,9 @@ class nsDll private: char *m_dllName; // Stores the dllName to load. - nsIFileSpec *m_dllSpec; // Filespec representing the component - PRUint32 m_modDate; // last modified time at creation of this object - PRUint32 m_size; // size of the dynamic library at creation of this object + nsCOMPtr m_dllSpec; // Filespec representing the component + PRInt64 m_modDate; // last modified time at creation of this object + PRInt64 m_size; // size of the dynamic library at creation of this object PRLibrary *m_instance; // Load instance nsDllStatus m_status; // holds current status @@ -68,15 +69,15 @@ private: PRBool m_markForUnload; char *m_registryLocation; - void Init(nsIFileSpec *dllSpec); + void Init(nsIFile *dllSpec); void Init(const char *persistentDescriptor); public: - nsDll(nsIFileSpec *dllSpec, const char *registryLocation); - nsDll(nsIFileSpec *dllSpec, const char *registryLocation, PRUint32 modDate, PRUint32 fileSize); + nsDll(nsIFile *dllSpec, const char *registryLocation); + nsDll(nsIFile *dllSpec, const char *registryLocation, PRInt64* modDate, PRInt64* fileSize); nsDll(const char *persistentDescriptor); - nsDll(const char *persistentDescriptor, PRUint32 modDate, PRUint32 fileSize); + nsDll(const char *persistentDescriptor, PRInt64* modDate, PRInt64* fileSize); nsDll(const char *dll, int type /* dummy */); ~nsDll(void); @@ -106,17 +107,17 @@ public: PRBool HasChanged(void); // WARNING: DONT FREE string returned. - const char *GetNativePath(void); + const char *GetDisplayPath(void); // WARNING: DONT FREE string returned. const char *GetPersistentDescriptorString(void); // WARNING: DONT FREE string returned. const char *GetRegistryLocation(void) { return m_registryLocation; } - PRUint32 GetLastModifiedTime(void) { return(m_modDate); } - PRUint32 GetSize(void) { return(m_size); } + void GetLastModifiedTime(PRInt64 *val) { *val = m_modDate; } + void GetSize(PRInt64 *val) { *val = m_size; } PRLibrary *GetInstance(void) { return (m_instance); } // NS_RELEASE() is required to be done on objects returned - nsresult GetDllSpec(nsIFileSpec **dllSpec); + nsresult GetDllSpec(nsIFile **dllSpec); nsresult GetModule(nsISupports *servMgr, nsIModule **mobj); }; diff --git a/mozilla/xpcom/glue/nsComponentManagerUtils.h b/mozilla/xpcom/glue/nsComponentManagerUtils.h index dd876cb5359..fe12a95dbcd 100644 --- a/mozilla/xpcom/glue/nsComponentManagerUtils.h +++ b/mozilla/xpcom/glue/nsComponentManagerUtils.h @@ -109,7 +109,7 @@ public: // Manually register a dynamically loaded component. // The libraryPersistentDescriptor is what gets passed to the library // self register function from ComponentManager. The format of this string - // is the same as nsIFileSpec::GetPersistentDescriptorString() + // is the same as nsIFile::GetPath() // // This function will go away in favour of RegisterComponentSpec. In fact, // it internally turns around and calls RegisterComponentSpec. @@ -125,7 +125,7 @@ public: static nsresult RegisterComponentSpec(const nsCID &aClass, const char *aClassName, const char *aProgID, - nsIFileSpec *aLibrary, + nsIFile *aLibrary, PRBool aReplace, PRBool aPersist); @@ -150,7 +150,7 @@ public: // Manually unregister a dynamically loaded component static nsresult UnregisterComponentSpec(const nsCID &aClass, - nsIFileSpec *aLibrarySpec); + nsIFile *aLibrarySpec); // Unload dynamically loaded factories that are not in use static nsresult FreeLibraries(void); @@ -158,10 +158,9 @@ public: // DLL registration support // If directory is NULL, then AutoRegister will try registering components - // in the default components directory which is got by - // nsSpecialSystemDirectory(XPCOM_CurrentProcessComponentDirectory) - static nsresult AutoRegister(PRInt32 when, nsIFileSpec* directory); - static nsresult AutoRegisterComponent(PRInt32 when, nsIFileSpec *component); + // in the default components directory. + static nsresult AutoRegister(PRInt32 when, nsIFile* directory); + static nsresult AutoRegisterComponent(PRInt32 when, nsIFile *component); // Is the given CID currently registered? static nsresult IsRegistered(const nsCID &aClass, diff --git a/mozilla/xpcom/glue/nsDebug.cpp b/mozilla/xpcom/glue/nsDebug.cpp index 45d66904f0b..0f5911b6bb0 100644 --- a/mozilla/xpcom/glue/nsDebug.cpp +++ b/mozilla/xpcom/glue/nsDebug.cpp @@ -25,6 +25,9 @@ #include "prlog.h" #include "prinit.h" #include "plstr.h" +#include "nsError.h" +#include "prerror.h" +#include "prerr.h" #if defined(XP_BEOS) /* For DEBUGGER macros */ @@ -298,3 +301,30 @@ NS_COM void nsDebug::Error(const char* aMessage, { Assertion(aMessage, "Error", aFile, aLine); } + +//////////////////////////////////////////////////////////////////////////////// + +NS_COM nsresult +NS_ErrorAccordingToNSPR() +{ + PRErrorCode err = PR_GetError(); + switch (err) { + case PR_OUT_OF_MEMORY_ERROR: return NS_ERROR_OUT_OF_MEMORY; + case PR_WOULD_BLOCK_ERROR: return NS_BASE_STREAM_WOULD_BLOCK; + case PR_FILE_NOT_FOUND_ERROR: return NS_ERROR_FILE_NOT_FOUND; + case PR_READ_ONLY_FILESYSTEM_ERROR: return NS_ERROR_FILE_READ_ONLY; + case PR_NOT_DIRECTORY_ERROR: return NS_ERROR_FILE_NOT_DIRECTORY; + case PR_IS_DIRECTORY_ERROR: return NS_ERROR_FILE_IS_DIRECTORY; + case PR_LOOP_ERROR: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; + case PR_FILE_EXISTS_ERROR: return NS_ERROR_FILE_ALREADY_EXISTS; + case PR_FILE_IS_LOCKED_ERROR: return NS_ERROR_FILE_IS_LOCKED; + case PR_FILE_TOO_BIG_ERROR: return NS_ERROR_FILE_TOO_BIG; + case PR_NO_DEVICE_SPACE_ERROR: return NS_ERROR_FILE_NO_DEVICE_SPACE; + case PR_NAME_TOO_LONG_ERROR: return NS_ERROR_FILE_NAME_TOO_LONG; + case PR_DIRECTORY_NOT_EMPTY_ERROR: return NS_ERROR_FILE_DIR_NOT_EMPTY; + case PR_NO_ACCESS_RIGHTS_ERROR: return NS_ERROR_FILE_ACCESS_DENIED; + default: return NS_ERROR_FAILURE; + } +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/glue/nsGenericFactory.cpp b/mozilla/xpcom/glue/nsGenericFactory.cpp index 7f04dfd080b..03ad6744c3d 100644 --- a/mozilla/xpcom/glue/nsGenericFactory.cpp +++ b/mozilla/xpcom/glue/nsGenericFactory.cpp @@ -21,8 +21,11 @@ * Pierre Phaneuf */ -#include "nsGenericFactory.h" +// DO NOT COPY THIS CODE INTO YOUR SOURCE! USE NS_IMPL_NSGETMODULE() + +#include "nsGenericFactory.h" +#include "nsCRT.h" nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor) : mConstructor(constructor), mDestructor(NULL) { @@ -196,7 +199,7 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -238,7 +241,7 @@ nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG diff --git a/mozilla/xpcom/glue/nsIGenericFactory.h b/mozilla/xpcom/glue/nsIGenericFactory.h index 554c314d049..427e60b00d4 100644 --- a/mozilla/xpcom/glue/nsIGenericFactory.h +++ b/mozilla/xpcom/glue/nsIGenericFactory.h @@ -73,12 +73,12 @@ NS_NewGenericFactory(nsIGenericFactory* *result, #include "nsIModule.h" typedef NS_CALLBACK(NSRegisterSelfProcPtr) (nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, + nsIFile *aPath, const char *registryLocation, const char *componentType); typedef NS_CALLBACK(NSUnregisterSelfProcPtr) (nsIComponentManager *aCompMgr, - nsIFileSpec *aPath, + nsIFile *aPath, const char *registryLocation); /** @@ -110,7 +110,7 @@ NS_NewGenericModule(const char* moduleName, #define NS_IMPL_NSGETMODULE_WITH_DTOR(_name, _components, _dtor) \ extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, \ - nsIFileSpec* location, \ + nsIFile* location, \ nsIModule** result) \ { \ return NS_NewGenericModule((_name), \ diff --git a/mozilla/xpcom/glue/nsISupportsUtils.h b/mozilla/xpcom/glue/nsISupportsUtils.h index 60c9fcf8b10..88561a207c5 100644 --- a/mozilla/xpcom/glue/nsISupportsUtils.h +++ b/mozilla/xpcom/glue/nsISupportsUtils.h @@ -545,20 +545,56 @@ NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \ return Super::Release(); \ } \ -#define NS_IMPL_QUERY_INTERFACE_INHERITED(Class,Super,AdditionalInterface) \ -NS_IMETHODIMP Class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \ -{ \ - if (!aInstancePtr) return NS_ERROR_NULL_POINTER; \ - if (aIID.Equals(NS_GET_IID(AdditionalInterface))) { \ - *aInstancePtr = NS_STATIC_CAST(AdditionalInterface*, this); \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - return Super::QueryInterface(aIID, aInstancePtr); \ +#define NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_HEAD(Class) \ + +#define NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + foundInterface = 0; \ + nsresult status; \ + if ( !foundInterface ) \ + return Super::QueryInterface(aIID, aInstancePtr); \ + else \ + { \ + NS_ADDREF(foundInterface); \ + status = NS_OK; \ + } \ + *aInstancePtr = foundInterface; \ + return status; \ } \ -#define NS_IMPL_ISUPPORTS_INHERITED(Class, Super, AdditionalInterface) \ - NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) \ +#define NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, i1) \ + NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \ + +#define NS_IMPL_QUERY_INTERFACE_INHERITED0(Class, Super) \ + NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + +#define NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \ + NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_BODY(i1) \ + NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + +#define NS_IMPL_QUERY_INTERFACE_INHERITED2(Class, Super, i1, i2) \ + NS_IMPL_QUERY_INHERITED_HEAD(Class) \ + NS_IMPL_QUERY_BODY(i1) \ + NS_IMPL_QUERY_BODY(i2) \ + NS_IMPL_QUERY_INHERITED_TAIL(Class, Super) \ + +#define NS_IMPL_ISUPPORTS_INHERITED(Class, Super, i1) \ + NS_IMPL_ISUPPORTS_INHERITED1(Class, Super, i1) \ + +#define NS_IMPL_ISUPPORTS_INHERITED0(Class, Super) \ + NS_IMPL_QUERY_INTERFACE_INHERITED0(Class, Super) \ + NS_IMPL_ADDREF_INHERITED(Class, Super) \ + NS_IMPL_RELEASE_INHERITED(Class, Super) \ + +#define NS_IMPL_ISUPPORTS_INHERITED1(Class, Super, i1) \ + NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \ + NS_IMPL_ADDREF_INHERITED(Class, Super) \ + NS_IMPL_RELEASE_INHERITED(Class, Super) \ + +#define NS_IMPL_ISUPPORTS_INHERITED2(Class, Super, i1, i2) \ + NS_IMPL_QUERY_INTERFACE_INHERITED2(Class, Super, i1, i2) \ NS_IMPL_ADDREF_INHERITED(Class, Super) \ NS_IMPL_RELEASE_INHERITED(Class, Super) \ diff --git a/mozilla/xpcom/io/MANIFEST b/mozilla/xpcom/io/MANIFEST index 799913efe34..7b80fd31eb2 100644 --- a/mozilla/xpcom/io/MANIFEST +++ b/mozilla/xpcom/io/MANIFEST @@ -8,3 +8,6 @@ nsIStringStream.h nsIUnicharInputStream.h nsSpecialSystemDirectory.h nsStorageStream.h +nsLocalFile.h +nsLocalFileMac.h +nsILocalFileMac.h diff --git a/mozilla/xpcom/io/MANIFEST_IDL b/mozilla/xpcom/io/MANIFEST_IDL index 8a8d93f8d0c..b9ccb0ef887 100644 --- a/mozilla/xpcom/io/MANIFEST_IDL +++ b/mozilla/xpcom/io/MANIFEST_IDL @@ -4,3 +4,5 @@ nsIInputStream.idl nsIBaseStream.idl nsIOutputStream.idl nsIPipe.idl +nsIFile.idl +nsILocalFile.idl diff --git a/mozilla/xpcom/io/Makefile.in b/mozilla/xpcom/io/Makefile.in index 8a55602bcf1..d494450f2b5 100644 --- a/mozilla/xpcom/io/Makefile.in +++ b/mozilla/xpcom/io/Makefile.in @@ -33,8 +33,10 @@ LIBRARY_NAME = xpcomio_s REQUIRES = xpcom uconv unicharutil CPPSRCS = \ + nsDirectoryService.cpp \ nsEscape.cpp \ nsLinebreakConverter.cpp \ + nsLocalFileUnix.cpp \ nsFileSpec.cpp \ nsFileSpecStreaming.cpp \ nsFileStream.cpp \ @@ -45,13 +47,16 @@ CPPSRCS = \ nsPipe2.cpp \ nsSpecialSystemDirectory.cpp \ nsUnicharInputStream.cpp \ - nsBinaryStream.cpp \ - nsStorageStream.cpp \ - nsScriptableInputStream.cpp \ + nsBinaryStream.cpp \ + nsStorageStream.cpp \ + nsScriptableInputStream.cpp \ $(NULL) EXPORTS = \ nsEscape.h \ + nsDirectoryService.h \ + nsLocalFile.h \ + nsLocalFileUnix.h \ nsLinebreakConverter.h \ nsFileSpec.h \ nsFileSpecStreaming.h \ @@ -65,17 +70,19 @@ EXPORTS = \ $(NULL) XPIDLSRCS = \ - nsIPipe.idl \ - nsIFileSpec.idl \ nsIBaseStream.idl \ - nsIInputStream.idl \ - nsIOutputStream.idl \ + nsIBinaryInputStream.idl \ + nsIBinaryOutputStream.idl \ nsIBufferInputStream.idl \ nsIBufferOutputStream.idl \ - nsIBinaryInputStream.idl \ - nsIBinaryOutputStream.idl \ - nsIStorageStream.idl \ - nsIScriptableInputStream.idl \ + nsIFile.idl \ + nsIFileSpec.idl \ + nsIInputStream.idl \ + nsILocalFile.idl \ + nsIOutputStream.idl \ + nsIPipe.idl \ + nsIScriptableInputStream.idl \ + nsIStorageStream.idl \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/xpcom/io/makefile.win b/mozilla/xpcom/io/makefile.win index d90b5cc0751..0b1b78639ca 100644 --- a/mozilla/xpcom/io/makefile.win +++ b/mozilla/xpcom/io/makefile.win @@ -33,12 +33,13 @@ EXPORTS = \ nsFileSpec.h \ nsFileSpecStreaming.h \ nsFileStream.h \ + nsSpecialSystemDirectory.h \ nsIFileStream.h \ nsIStringStream.h \ nsIUnicharInputStream.h \ - nsSpecialSystemDirectory.h \ nsStorageStream.h \ nsScriptableInputStream.h \ + nsDirectoryService.h \ $(NULL) NO_XPT_GEN=1 @@ -46,7 +47,6 @@ XPIDL_MODULE = xpcom_io XPIDLSRCS = \ .\nsIPipe.idl \ - .\nsIFileSpec.idl \ .\nsIBaseStream.idl \ .\nsIBinaryInputStream.idl \ .\nsIBinaryOutputStream.idl \ @@ -56,6 +56,9 @@ XPIDLSRCS = \ .\nsIBufferOutputStream.idl \ .\nsIScriptableInputStream.idl \ .\nsIStorageStream.idl \ + .\nsIFileSpec.idl \ + .\nsIFile.idl \ + .\nsILocalFile.idl \ $(NULL) ################################################################################ @@ -74,21 +77,23 @@ LINCS = $(LINCS) -I$(PUBLIC)\raptor # until we sort out the filespec/widgets LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN CPP_OBJS = \ + .\$(OBJDIR)\nsDirectoryService.obj \ + .\$(OBJDIR)\nsLocalFileWin.obj \ .\$(OBJDIR)\nsBinaryStream.obj \ .\$(OBJDIR)\nsEscape.obj \ .\$(OBJDIR)\nsLinebreakConverter.obj \ - .\$(OBJDIR)\nsFileSpec.obj \ - .\$(OBJDIR)\nsFileSpecImpl.obj \ - .\$(OBJDIR)\nsFileSpecStreaming.obj \ .\$(OBJDIR)\nsFileStream.obj \ .\$(OBJDIR)\nsIFileStream.obj \ .\$(OBJDIR)\nsIStringStream.obj \ .\$(OBJDIR)\nsSegmentedBuffer.obj \ .\$(OBJDIR)\nsPipe2.obj \ - .\$(OBJDIR)\nsSpecialSystemDirectory.obj \ .\$(OBJDIR)\nsStorageStream.obj \ .\$(OBJDIR)\nsUnicharInputStream.obj \ .\$(OBJDIR)\nsScriptableInputStream.obj \ + .\$(OBJDIR)\nsFileSpec.obj \ + .\$(OBJDIR)\nsFileSpecImpl.obj \ + .\$(OBJDIR)\nsFileSpecStreaming.obj \ + .\$(OBJDIR)\nsSpecialSystemDirectory.obj \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/xpcom/io/nsDirectoryService.cpp b/mozilla/xpcom/io/nsDirectoryService.cpp index 5c8bd2dcab3..5f5bb7d59b7 100644 --- a/mozilla/xpcom/io/nsDirectoryService.cpp +++ b/mozilla/xpcom/io/nsDirectoryService.cpp @@ -20,8 +20,173 @@ * Contributor(s): */ - #include "nsDirectoryService.h" +#include "nsCOMPtr.h" +#include "nsDirectoryService.h" +#include "nsILocalFile.h" +#include "nsLocalFile.h" +#include "nsDebug.h" +#ifdef XP_MAC +#include +#include +#include +#include +#elif defined(XP_PC) +#include +#include +#include +#include +#elif defined(XP_UNIX) +#include +#include +#include +#include "prenv.h" +#elif defined(XP_BEOS) +#include +#include +#include +#include +#include +#include +#include +#include "prenv.h" +#endif + + + + + + + +//---------------------------------------------------------------------------------------- +static nsresult GetCurrentProcessDirectory(nsILocalFile* aFile) +//---------------------------------------------------------------------------------------- +{ +#ifdef XP_PC + char buf[MAX_PATH]; + if ( ::GetModuleFileName(0, buf, sizeof(buf)) ) { + // chop of the executable name by finding the rightmost backslash + char* lastSlash = PL_strrchr(buf, '\\'); + if (lastSlash) + *(lastSlash + 1) = '\0'; + + aFile->InitWithPath(buf); + return NS_OK; + } + +#elif defined(XP_MAC) + // get info for the the current process to determine the directory + // its located in + OSErr err; + ProcessSerialNumber psn; + if (!(err = GetCurrentProcess(&psn))) + { + ProcessInfoRec pInfo; + FSSpec tempSpec; + + // initialize ProcessInfoRec before calling + // GetProcessInformation() or die horribly. + pInfo.processName = nil; + pInfo.processAppSpec = &tempSpec; + pInfo.processInfoLength = sizeof(ProcessInfoRec); + + if (!(err = GetProcessInformation(&psn, &pInfo))) + { + FSSpec appFSSpec = *(pInfo.processAppSpec); + + // Truncate the nsame so the spec is just to the app directory + appFSSpec.name[0] = 0; + + nsCOMPtr localFileMac = do_QueryInterface(aFile); + if (localFileMac) { + localFileMac->InitWithFSSpec(&appFSSpec); + return NS_OK; + } + } + } + +#elif defined(XP_UNIX) + + // 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 + // - else give the current directory + char buf[MAXPATHLEN]; + char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME"); + if (moz5) + { + aFile->InitWithPath(moz5); + 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; + } + + // Fall back to current directory. + if (getcwd(buf, sizeof(buf))) + { + aFile->InitWithPath(buf); + return NS_OK; + } + } + +#elif defined(XP_BEOS) + + char *moz5 = getenv("MOZILLA_FIVE_HOME"); + if (moz5) + { + aFile->InitWithPath(moz5); + return NS_OK; + } + else + { + static char buf[MAXPATHLEN]; + int32 cookie = 0; + image_info info; + char *p; + *buf = 0; + if(get_next_image_info(0, &cookie, &info) == B_OK) + { + strcpy(buf, info.name); + if((p = strrchr(buf, '/')) != 0) + { + *p = 0; + aFile->InitWithPath(buf); + return NS_OK; + } + } + } + +#endif + + NS_ERROR("unable to get current process directory"); + return NS_ERROR_FAILURE; +} // GetCurrentProcessDirectory() + + + + + + + + + + + + + + + + + + +nsDirectoryService* nsDirectoryService::mService = nsnull; nsDirectoryService::nsDirectoryService(nsISupports* outer) { @@ -34,14 +199,14 @@ nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult) NS_ENSURE_ARG_POINTER(aResult); NS_ENSURE_PROPER_AGGREGATION(outer, aIID); - nsDirectoryService* props = new nsDirectoryService(outer); - if (props == NULL) - return NS_ERROR_OUT_OF_MEMORY; + if (mService == nsnull) + { + mService = new nsDirectoryService(outer); + if (mService == NULL) + return NS_ERROR_OUT_OF_MEMORY; + } - nsresult rv = props->AggregatedQueryInterface(aIID, aResult); - if (NS_FAILED(rv)) - delete props; - return rv; + return mService->AggregatedQueryInterface(aIID, aResult); } PRBool @@ -78,7 +243,7 @@ nsDirectoryService::AggregatedQueryInterface(const nsIID& aIID, void** aInstance } NS_IMETHODIMP -nsDirectoryService::DefineProperty(const char* prop, nsISupports* initialValue) +nsDirectoryService::Define(const char* prop, nsISupports* initialValue) { nsStringKey key(prop); if (Exists(&key)) @@ -91,7 +256,7 @@ nsDirectoryService::DefineProperty(const char* prop, nsISupports* initialValue) } NS_IMETHODIMP -nsDirectoryService::UndefineProperty(const char* prop) +nsDirectoryService::Undefine(const char* prop) { nsStringKey key(prop); if (!Exists(&key)) @@ -103,32 +268,72 @@ nsDirectoryService::UndefineProperty(const char* prop) } NS_IMETHODIMP -nsDirectoryService::GetProperty(const char* prop, nsISupports* *result) +nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) { nsStringKey key(prop); if (!Exists(&key)) { // check to see if it is one of our defaults - // - // code here.. - // - // - // else - // + + if (strncmp(prop, "xpcom.currentProcess.componentRegistry", 38) == 0) + { + nsLocalFile* localFile = new nsLocalFile; + + if (localFile == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(localFile); + + nsresult rv = GetCurrentProcessDirectory(localFile); + if (NS_FAILED(rv)) + return rv; + +#ifdef XP_MAC + localFile->Append("Component Registry"); +#else + localFile->Append("component.reg"); +#endif /* XP_MAC */ + + Set(prop, NS_STATIC_CAST(nsILocalFile*, localFile)); + rv =localFile->QueryInterface(uuid, result); + NS_RELEASE(localFile); + return rv; + } + else if (strncmp(prop, "xpcom.currentProcess.componentDirectory", 39) == 0) + { + nsLocalFile* localFile = new nsLocalFile; + + if (localFile == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(localFile); + + nsresult rv = GetCurrentProcessDirectory(localFile); + if (NS_FAILED(rv)) + return rv; + +#ifdef XP_MAC + localFile->Append("Components"); +#else + localFile->Append("components"); +#endif /* XP_MAC */ + + rv =localFile->QueryInterface(uuid, result); + NS_RELEASE(localFile); + return rv; + } + return NS_ERROR_FAILURE; } - nsISupports* value = (nsISupports*)Get(&key); - NS_IF_ADDREF(value); - *result = value; - return NS_OK; + + nsISupports* value = (nsISupports*)nsHashtable::Get(&key); + return value->QueryInterface(uuid, result); } NS_IMETHODIMP -nsDirectoryService::SetProperty(const char* prop, nsISupports* value) +nsDirectoryService::Set(const char* prop, nsISupports* value) { nsStringKey key(prop); - if (!Exists(&key)) + if (Exists(&key)) return NS_ERROR_FAILURE; nsISupports* prevValue = (nsISupports*)Put(&key, value); @@ -138,12 +343,18 @@ nsDirectoryService::SetProperty(const char* prop, nsISupports* value) } NS_IMETHODIMP -nsDirectoryService::HasProperty(const char* prop, nsISupports* expectedValue) +nsDirectoryService::Has(const char *prop, PRBool *_retval) { - nsISupports* value; - nsresult rv = GetProperty(prop, &value); - if (NS_FAILED(rv)) return rv; - rv = (value == expectedValue) ? NS_OK : NS_ERROR_FAILURE; - NS_IF_RELEASE(value); + *_retval = PR_FALSE; + nsCOMPtr value; + nsresult rv = Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(value)); + if (NS_FAILED(rv)) + return rv; + + if (value) + { + *_retval = PR_TRUE; + } + return rv; } diff --git a/mozilla/xpcom/io/nsDirectoryService.h b/mozilla/xpcom/io/nsDirectoryService.h index 03ad3c175a2..4aa6645abc6 100644 --- a/mozilla/xpcom/io/nsDirectoryService.h +++ b/mozilla/xpcom/io/nsDirectoryService.h @@ -26,15 +26,7 @@ #include "nsIProperties.h" #include "nsHashtable.h" #include "nsAgg.h" - - -#define NS_DIRECTORY_SERVICE_CID \ -{ /* f00152d0-b40b-11d3-8c9c-000064657374 */ \ - 0xf00152d0, \ - 0xb40b, \ - 0x11d3, \ - {0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} \ -} +#include "nsIFile.h" #define NS_DIRECTORY_SERVICE_PROGID "component://netscape/file/directory_service" #define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service" @@ -47,12 +39,7 @@ public: NS_DECL_AGGREGATED - // nsIProperties methods: - NS_IMETHOD DefineProperty(const char* prop, nsISupports* initialValue); - NS_IMETHOD UndefineProperty(const char* prop); - NS_IMETHOD GetProperty(const char* prop, nsISupports* *result); - NS_IMETHOD SetProperty(const char* prop, nsISupports* value); - NS_IMETHOD HasProperty(const char* prop, nsISupports* value); + NS_DECL_NSIPROPERTIES // nsProperties methods: nsDirectoryService(nsISupports* outer); @@ -62,8 +49,11 @@ public: Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); static PRBool ReleaseValues(nsHashKey* key, void* data, void* closure); - +private: + static nsDirectoryService* mService; + }; -#endif \ No newline at end of file +#endif + diff --git a/mozilla/xpcom/io/nsFileSpecImpl.cpp b/mozilla/xpcom/io/nsFileSpecImpl.cpp index 16be0fab5b2..0929594b47d 100644 --- a/mozilla/xpcom/io/nsFileSpecImpl.cpp +++ b/mozilla/xpcom/io/nsFileSpecImpl.cpp @@ -81,8 +81,15 @@ nsresult nsFileSpecImpl::MakeInterface(const nsFileSpec& inSpec, nsIFileSpec** r NS_IMETHODIMP nsFileSpecImpl::FromFileSpec(const nsIFileSpec *original) //---------------------------------------------------------------------------------------- { - mFileSpec = FILESPEC(original); - return mFileSpec.Error(); + if (original) { + nsresult rv = ((nsIFileSpec *)original)->GetFileSpec( &mFileSpec); + if (NS_SUCCEEDED( rv)) + return mFileSpec.Error(); + else + return( rv); + } + else + return( NS_ERROR_FAILURE); } //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsFileStream.cpp b/mozilla/xpcom/io/nsFileStream.cpp index 7b40b105d4f..4b6e474c57a 100644 --- a/mozilla/xpcom/io/nsFileStream.cpp +++ b/mozilla/xpcom/io/nsFileStream.cpp @@ -25,7 +25,6 @@ // which does not actually depend on the charT, can be placed here. #include "nsFileStream.h" - #include "nsFileSpec.h" #include "nsIFileSpec.h" #include "nsIStringStream.h" diff --git a/mozilla/xpcom/io/nsIBaseStream.idl b/mozilla/xpcom/io/nsIBaseStream.idl index 29b19fbc9a8..4b9f2121285 100644 --- a/mozilla/xpcom/io/nsIBaseStream.idl +++ b/mozilla/xpcom/io/nsIBaseStream.idl @@ -28,21 +28,3 @@ interface nsIBaseStream : nsISupports /** Close the stream. */ void Close(); }; - -/** Error codes */ -%{C++ -//@{ -/// Stream closed -#define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2) -/// Error from the operating system -#define NS_BASE_STREAM_OSERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 3) -/// Illegal arguments -#define NS_BASE_STREAM_ILLEGAL_ARGS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 4) -/// For unichar streams -#define NS_BASE_STREAM_NO_CONVERTER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 5) -/// For unichar streams -#define NS_BASE_STREAM_BAD_CONVERSION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 6) - -#define NS_BASE_STREAM_WOULD_BLOCK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 7) -//@} -%} diff --git a/mozilla/xpcom/io/nsIFile.idl b/mozilla/xpcom/io/nsIFile.idl index 6f7f97062aa..23cd42d5e3a 100644 --- a/mozilla/xpcom/io/nsIFile.idl +++ b/mozilla/xpcom/io/nsIFile.idl @@ -33,7 +33,6 @@ interface nsISimpleEnumerator; [scriptable, uuid(c8c0a080-0868-11d3-915f-d9d889d48e3c)] interface nsIFile : nsISupports { - /** * Create Types * @@ -42,28 +41,22 @@ interface nsIFile : nsISupports */ const unsigned long NORMAL_FILE_TYPE = 0; const unsigned long DIRECTORY_TYPE = 1; - /** * appendPath * - * This function is used for constructing a descendat of the - * current nsIFile. Non-terminal nodes will be resolved. An - * error will be returned if a non-terminal is a file - * (NS_ERROR_FILE_INVALID_PATH). + * This function is used for constructing a descendant of the + * current nsIFile. * * @param relativePath - * A unix style string which is intented to be a relative - * path of the nsIFile. Starting and trailing '/' will - * be ignored. If this path is not a unix style path, an - * error will be returned (NS_ERROR_FILE_UNRECONGNIZED_PATH). + * A string which is intented to be a child node of the + * nsIFile. */ + void append([const] in string node); - void appendPath([const] in string relativePath); - - /** - * Normalize the pathName (e.g. removing .. and . components on Unix). - */ + /** + * Normalize the pathName (e.g. removing .. and . components on Unix). + */ void normalize(); /** @@ -89,11 +82,10 @@ interface nsIFile : nsISupports void create(in unsigned long type, in unsigned long permissions); - /** * Accessor to the leaf name of the file itself. */ - readonly attribute string leafName; + attribute string leafName; /** * copyTo @@ -117,7 +109,6 @@ interface nsIFile : nsISupports * for the file to be copied. This can be nsnull. * */ - void copyTo(in nsIFile newParentDir, [const] in string newName); /** @@ -126,7 +117,6 @@ interface nsIFile : nsISupports * This function is identical to copyTo except it, as * the name implies, follows symbolic links. */ - void copyToFollowingLinks(in nsIFile newParentDir, [const] in string newName); /** @@ -220,8 +210,6 @@ interface nsIFile : nsISupports */ boolean isSpecial(); - - /** * clone() * @@ -233,7 +221,6 @@ interface nsIFile : nsISupports * with. * */ - nsIFile clone(); /** @@ -242,12 +229,11 @@ interface nsIFile : nsISupports boolean equals(in nsIFile inFile); /** - * Will determine the file is a descendant of the parameter inFile. + * Will determine the inFile is a descendant * If |recur| is true, it will descend subdirectories looking for */ boolean isContainedIn(in nsIFile inFile, in boolean recur); - /** * Parent will be nsnull when this is at the top of the volume. */ @@ -267,27 +253,35 @@ interface nsIFile : nsISupports #define NS_FILE_PROGID "component://netscape/file" #define NS_FILE_CLASSNAME "File Specification" +//////////////////////////////////////////////////////////////////////////////// +// Special Directories -#define NS_ERROR_FILE_UNRECOGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1) -#define NS_ERROR_FILE_UNRESOLVABLE_SYMLINK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 2) -#define NS_ERROR_FILE_EXECUTION_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 3) -#define NS_ERROR_FILE_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 4) -#define NS_ERROR_FILE_DESTINATION_NOT_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 5) -#define NS_ERROR_FILE_TARGET_DOES_NOT_EXIST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 6) -#define NS_ERROR_FILE_COPY_OR_MOVE_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 7) -#define NS_ERROR_FILE_ALREADY_EXISTS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 8) -#define NS_ERROR_FILE_INVALID_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 9) -#define NS_ERROR_FILE_DISK_FULL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 10) -#define NS_ERROR_FILE_CORRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 11) -#define NS_ERROR_FILE_NOT_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 12) -#define NS_ERROR_FILE_IS_DIRECTORY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 13) -#define NS_ERROR_FILE_IS_LOCKED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 14) -#define NS_ERROR_FILE_TOO_BIG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 15) -#define NS_ERROR_FILE_NO_DEVICE_SPACE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 16) -#define NS_ERROR_FILE_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 17) -#define NS_ERROR_FILE_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 18) -#define NS_ERROR_FILE_READ_ONLY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 19) -#define NS_ERROR_FILE_DIR_NOT_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 20) -#define NS_ERROR_FILE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 21) +#include "nsIServiceManager.h" +#include "nsIProperties.h" +#include "nsCOMPtr.h" + +#define NS_DIRECTORY_SERVICE_CID \ +{ /* f00152d0-b40b-11d3-8c9c-000064657374 */ \ + 0xf00152d0, \ + 0xb40b, \ + 0x11d3, \ + {0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} \ +} + +inline nsresult +NS_GetSpecialDirectory(const char* specialDirName, nsIFile* *result) +{ + nsresult rv; + static NS_DEFINE_CID(kDirectoryServiceCID, NS_DIRECTORY_SERVICE_CID); + NS_WITH_SERVICE(nsIProperties, serv, kDirectoryServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr dir; + rv = serv->Get(specialDirName, NS_GET_IID(nsIFile), getter_AddRefs(dir)); + if (NS_FAILED(rv)) return rv; + + *result = (nsIFile*)dir.get(); + return NS_OK; +} %} diff --git a/mozilla/xpcom/io/nsILocalFile.idl b/mozilla/xpcom/io/nsILocalFile.idl index 598761a340f..729185bb6e3 100644 --- a/mozilla/xpcom/io/nsILocalFile.idl +++ b/mozilla/xpcom/io/nsILocalFile.idl @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -28,45 +28,49 @@ %{C++ #include "prio.h" #include "prlink.h" +#include %} [ptr] native PRFileDescStar(PRFileDesc); [ptr] native PRLibraryStar(PRLibrary); +[ptr] native FILE(FILE); [scriptable, uuid(aa610f20-a889-11d3-8c81-000064657374)] interface nsILocalFile : nsIFile { /** - * initWithPath - * - * This function will initialize the nsIFile object. Any - * internal state information will be reset. Non-terminal - * nodes will be resolved. An error will be returned if a - * non-terminal is a file (NS_ERROR_FILE_INVALID_PATH) - * - * - * NOTE: This function has a known bug on the macintosh and - * other OSes which do not represent file locations - * as pathes. If you do use this function, be very - * aware of this problem as bugs. - * - * @param filePath - * A string which specifies a full file path to a - * location. Relative paths will be treated as an - * error (NS_ERROR_FILE_UNRECONGNIZED_PATH). This - * path must in native. - */ - - void initWithPath([const] in string filePath ); + * initWithPath + * + * This function will initialize the nsILocalFile object. Any + * internal state information will be reset. + * + * NOTE: This function has a known bug on the macintosh and + * other OSes which do not represent file locations + * as pathes. If you do use this function, be very + * aware of this problem as bugs. + * + * @param filePath + * A string which specifies a full file path to a + * location. Relative paths will be treated as an + * error (NS_ERROR_FILE_UNRECONGNIZED_PATH). This + * path must in native. + */ + void initWithPath([const] in string filePath); - [noscript] PRFileDescStar open(in long flags, in long mode); - [noscript] PRLibraryStar load(); - - readonly attribute PRInt64 diskSpaceAvailable; // maybe we should put this somewhere else. + [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode); + [noscript] FILE openANSIFileDesc(in string mode); - }; + [noscript] PRLibraryStar load(); + + readonly attribute PRInt64 diskSpaceAvailable; // maybe we should put this somewhere else. +}; %{C++ -#define NS_LOCAL_FILE_PROGID "component://netscape/file/local" + +#define NS_LOCAL_FILE_PROGID "component://mozilla/file/local" #define NS_LOCAL_FILE_CLASSNAME "Local File Specification" + +extern NS_COM nsresult +NS_NewLocalFile(const char* path, nsILocalFile* *result); + %} diff --git a/mozilla/xpcom/io/nsILocalFileMac.h b/mozilla/xpcom/io/nsILocalFileMac.h new file mode 100644 index 00000000000..2567fcb2635 --- /dev/null +++ b/mozilla/xpcom/io/nsILocalFileMac.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Steve Dagley + */ + +// Mac specific interfaces for nsLocalFileMac + +#ifndef _nsILocalFileMAC_H_ +#define _nsILocalFileMAC_H_ + +#include "nsISupports.h" + +#include + + +#define NS_ILOCALFILEMAC_IID_STR "614c3010-1dd2-11b2-be04-bcd57a64ffc9" + +#define NS_ILOCALFILEMAC_IID \ + {0x614c3010, 0x1dd2, 0x11b2, \ + { 0xbe, 0x04, 0xbc, 0xd5, 0x7a, 0x64, 0xcc, 0xc9 }} + + +typedef enum { + eNotInitialized = 0, + eInitWithPath, + eInitWithFSSpec +} nsLocalFileMacInitType; + +class nsILocalFileMac : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILOCALFILEMAC_IID) + + // We need to be able to determine what init method was used as that + // will affect how we clone a nsILocalFileMac + NS_IMETHOD GetInitType(nsLocalFileMacInitType *type) = 0; + + // Since the OS native way to represent a file on the Mac is an FSSpec + // we provide a way to initialize an nsLocalFile with one + NS_IMETHOD InitWithFSSpec(const FSSpec *fileSpec) = 0; + + // In case we need to get the FSSpecs at the heart of an nsLocalFileMac + NS_IMETHOD GetFSSpec(FSSpec *fileSpec) = 0; // The one we were inited with + NS_IMETHOD GetResolvedFSSpec(FSSpec *fileSpec) = 0; // The one we've resolved to + + // Since we may have both an FSSpec and an appended path we need methods + // to get/set just the appended path + NS_IMETHOD SetAppendedPath(const char *aPath) = 0; + NS_IMETHOD GetAppendedPath(char * *aPath) = 0; + + // Get/Set methods for the file type and creator codes + // Note that passing null for either the type or creator in the + // SetFileTypeAndCreator call will preserve the existing code + NS_IMETHOD GetFileTypeAndCreator(OSType *type, OSType *creator) = 0; + NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator) = 0; +}; + +#endif diff --git a/mozilla/xpcom/io/nsLocalFile.h b/mozilla/xpcom/io/nsLocalFile.h index 5d2fa43e87f..95ce0d22677 100644 --- a/mozilla/xpcom/io/nsLocalFile.h +++ b/mozilla/xpcom/io/nsLocalFile.h @@ -45,3 +45,5 @@ #endif /* XP_UNIX */ #endif /* XP_PC */ #endif + + diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index d0a3c21610c..36169bfbd0f 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -32,7 +32,9 @@ #include "nsISimpleEnumerator.h" #include "nsIComponentManager.h" #include "prtypes.h" -#include "prio.h" +#include "prerror.h" +#include "pprio.h" // Include this rather than prio.h so we get def of PR_ImportFile +#include "prmem.h" #include "FullPath.h" #include "FileCopy.h" @@ -42,6 +44,15 @@ #include #include +#include + +// Stupid @#$% header looks like its got extern mojo but it doesn't really +extern "C" +{ +#include +} + +#pragma mark [static util funcs] // Simple func to map Mac OS errors into nsresults static nsresult MacErrorMapper(OSErr inErr) { @@ -49,6 +60,10 @@ static nsresult MacErrorMapper(OSErr inErr) switch (inErr) { + case noErr: + outErr = NS_OK; + break; + case fnfErr: outErr = NS_ERROR_FILE_NOT_FOUND; break; @@ -57,16 +72,22 @@ static nsresult MacErrorMapper(OSErr inErr) outErr = NS_ERROR_FILE_ALREADY_EXISTS; break; + case dskFulErr: + outErr = NS_ERROR_FILE_DISK_FULL; + break; + + case fLckdErr: + outErr = NS_ERROR_FILE_IS_LOCKED; + break; + // Can't find good map for some case bdNamErr: outErr = NS_ERROR_FAILURE; break; - case noErr: - outErr = NS_OK; - default: outErr = NS_ERROR_FAILURE; + break; } return outErr; } @@ -91,7 +112,215 @@ static void myPLstrncpy(Str255 dst, const char* src, int inMax) memcpy(&dst[1], src, srcLength); } +// Aaargh!!!! Gotta roll my own equivalents of PR_OpenDir, PR_ReadDir and PR_CloseDir +// I can't use the NSPR versions as they expect a unix path and I can't easily adapt +// the directory iterator fucntion from MoreFIles as it wants to iterate things itself +// and use a callback function to operate on the iterated entries +typedef struct +{ + short ioVRefNum; + long ioDirID; + short ioFDirIndex; + char *currentEntryName; +} MyPRDir; + +static MyPRDir * My_OpenDir(FSSpec *fileSpec) +{ + MyPRDir *dir = NULL; + OSErr err; + long theDirID; + Boolean isDirectory; + + err = ::FSpGetDirectoryID(fileSpec, &theDirID, &isDirectory); + if (err == noErr) + { + if (isDirectory) + { + /* This is a directory, store away the pertinent information. + ** We post increment. I.e. index is always the nth. item we + ** should get on the next call + */ + dir = PR_NEW(MyPRDir); + if (dir) + { + dir->ioVRefNum = fileSpec->vRefNum; + dir->ioDirID = theDirID; + dir->currentEntryName = NULL; + dir->ioFDirIndex = 1; + } + } + } + + return dir; + +} + +static char * My_ReadDir(MyPRDir *mdDir, PRIntn flags) +{ + OSErr err; + CInfoPBRec pb; + char *returnedCStr; + Str255 pascalName = "\p"; + PRBool foundEntry; + + do + { + // Release the last name read + if (mdDir->currentEntryName) + { + PR_DELETE(mdDir->currentEntryName); + mdDir->currentEntryName = NULL; + } + + // WeÕve got all the info we need, just get info about this guy. + pb.hFileInfo.ioNamePtr = pascalName; + pb.hFileInfo.ioVRefNum = mdDir->ioVRefNum; + pb.hFileInfo.ioFDirIndex = mdDir->ioFDirIndex; + pb.hFileInfo.ioDirID = mdDir->ioDirID; + err = ::PBGetCatInfoSync(&pb); + if (err != noErr) + goto ErrorExit; + + // Convert the Pascal string to a C string (actual allocation occurs in CStrFromPStr) + unsigned long len = pascalName[0]; + returnedCStr = (char *)PR_MALLOC(len + 1); + if (returnedCStr) + { + ::BlockMoveData(&pascalName[1], returnedCStr, len); + returnedCStr[len] = NULL; + } + + mdDir->currentEntryName = returnedCStr; + mdDir->ioFDirIndex++; + + // If it is not a hidden file and the flags did not specify skipping, we are done. + if ((flags & PR_SKIP_HIDDEN) && (pb.hFileInfo.ioFlFndrInfo.fdFlags & fInvisible)) + foundEntry = PR_FALSE; + else + foundEntry = PR_TRUE; + + } while (!foundEntry); + + return (mdDir->currentEntryName); + +ErrorExit: + return NULL; +} + +static void My_CloseDir(MyPRDir *mdDir) +{ + if (mdDir->currentEntryName) + PR_DELETE(mdDir->currentEntryName); +} + +// The R**co FSSpec resolver - +// it slices, it dices, it juliannes fries and it even creates FSSpecs out of whatever you feed it +// This function will take a path and a starting FSSpec and generate a FSSpec to represent +// the target of the two. If the intial FSSpec is null the path alone will be resolved +static OSErr ResolvePathAndSpec(const char * filePath, FSSpec *inSpec, PRBool createDirs, FSSpec *outSpec) +{ + OSErr err = noErr; + size_t inLength = strlen(filePath); + Boolean isRelative = (inSpec && (strchr(filePath, ':') == 0 || *filePath == ':')); + + if (isRelative && inSpec) + { + outSpec->vRefNum = inSpec->vRefNum; + outSpec->parID = inSpec->parID; + } + else + { + outSpec->vRefNum = 0; + outSpec->parID = 0; + } + + // Try making an FSSpec from the path + if (inLength < 255) + { + Str255 pascalpath; + myPLstrcpy(pascalpath, filePath); + err = ::FSMakeFSSpec(outSpec->vRefNum, outSpec->parID, pascalpath, outSpec); + } + else if (!isRelative) + { + err = ::FSpLocationFromFullPath(inLength, filePath, outSpec); + } + else + { // If the path is relative and >255 characters we need to manually walk the + // path appending each node to the initial FSSpec so to reach that code we + // set the err to bdNamErr and fall into the code below + err = bdNamErr; + } + + // If we successfully created a spec then leave + if (err == noErr) + return err; + + // We get here when the directory hierarchy needs to be created or we're resolving + // a relative path >255 characters long + if (err == dirNFErr || err == bdNamErr) + { + const char* path = filePath; + outSpec->vRefNum = 0; + outSpec->parID = 0; + + do + { + // Locate the colon that terminates the node. + // But if we've a partial path (starting with a colon), find the second one. + const char* nextColon = strchr(path + (*path == ':'), ':'); + // Well, if there are no more colons, point to the end of the string. + if (!nextColon) + nextColon = path + strlen(path); + + // Make a pascal string out of this node. Include initial + // and final colon, if any! + Str255 ppath; + myPLstrncpy(ppath, path, nextColon - path + 1); + + // Use this string as a relative path using the directory created + // on the previous round (or directory 0,0 on the first round). + err = ::FSMakeFSSpec(outSpec->vRefNum, outSpec->parID, ppath, outSpec); + + // If this was the leaf node, then we are done. + if (!*nextColon) + break; + + // Since there's more to go, we have to get the directory ID, which becomes + // the parID for the next round. + if (err == noErr) + { + // The directory (or perhaps a file) exists. Find its dirID. + long dirID; + Boolean isDirectory; + err = ::FSpGetDirectoryID(outSpec, &dirID, &isDirectory); + if (!isDirectory) + err = dupFNErr; // oops! a file exists with that name. + if (err != noErr) + break; // bail if we've got an error + outSpec->parID = dirID; + } + else if ((err == fnfErr) && createDirs) + { + // If we got "file not found" and we're allowed to create directories + // then we need to create aone + err = ::FSpDirCreate(outSpec, smCurrentScript, &outSpec->parID); + // For some reason, this usually returns fnfErr, even though it works. + if (err == fnfErr) + err = noErr; + } + if (err != noErr) + break; + path = nextColon; // next round + } while (true); + } + + return err; +} + +#pragma mark - +#pragma mark [nsDirEnumerator] class nsDirEnumerator : public nsISimpleEnumerator { public: @@ -105,20 +334,22 @@ class nsDirEnumerator : public nsISimpleEnumerator nsresult Init(nsILocalFile* parent) { - char* filepath; - parent->GetTarget(&filepath); - - if (filepath == nsnull) + FSSpec fileSpec; + fileSpec.vRefNum = 0; + fileSpec.parID = 0; + + nsCOMPtr localFileMac = do_QueryInterface(parent); + if (localFileMac) { + localFileMac->GetResolvedFSSpec(&fileSpec); + } + + // See if we managed to get a FSSpec + if (!fileSpec.vRefNum && !fileSpec.parID) { - parent->GetPath(&filepath); + return NS_ERROR_FAILURE; } - if (filepath == nsnull) - { - return NS_ERROR_OUT_OF_MEMORY; - } - - mDir = PR_OpenDir(filepath); + mDir = My_OpenDir(&fileSpec); if (mDir == nsnull) // not a directory? return NS_ERROR_FAILURE; @@ -131,24 +362,34 @@ class nsDirEnumerator : public nsISimpleEnumerator nsresult rv; if (mNext == nsnull && mDir) { - PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH); - if (entry == nsnull) + char* name = My_ReadDir(mDir, PR_SKIP_BOTH); + if (name == nsnull) { // end of dir entries - - PRStatus status = PR_CloseDir(mDir); - if (status != PR_SUCCESS) - return NS_ERROR_FAILURE; + My_CloseDir(mDir); mDir = nsnull; - *result = PR_FALSE; return NS_OK; } - - nsCOMPtr file; - mParent->Clone(getter_AddRefs(file)); - - rv = file->AppendPath(entry->name); + + // Make a new nsILocalFile for the new element + nsCOMPtr file; + rv = NS_NewLocalFile("dummy:path", getter_AddRefs(file)); + if (NS_FAILED(rv)) + return rv; + + // Init with the FSSpec for the current dir + FSSpec tempSpec; + tempSpec.vRefNum = mDir->ioVRefNum; + tempSpec.parID = mDir->ioDirID; + tempSpec.name[0] = 0; + nsCOMPtr localFileMac = do_QueryInterface(file); + if (localFileMac) { + localFileMac->InitWithFSSpec(&tempSpec); + } + + // Now set the leaf name of the new nsILocalFile to the new element + rv = file->SetLeafName(name); if (NS_FAILED(rv)) return rv; @@ -176,44 +417,50 @@ class nsDirEnumerator : public nsISimpleEnumerator { if (mDir) { - PRStatus status = PR_CloseDir(mDir); - NS_ASSERTION(status == PR_SUCCESS, "close failed"); + My_CloseDir(mDir); } } protected: - PRDir* mDir; - nsCOMPtr mParent; - nsCOMPtr mNext; + MyPRDir* mDir; + nsCOMPtr mParent; + nsCOMPtr mNext; }; NS_IMPL_ISUPPORTS(nsDirEnumerator, NS_GET_IID(nsISimpleEnumerator)); - - - - - - - +#pragma mark - +#pragma mark [CTOR/DTOR] nsLocalFile::nsLocalFile() { NS_INIT_REFCNT(); MakeDirty(); + mLastResolveFlag = PR_FALSE; + + mWorkingPath.Assign(""); + mAppendedPath.Assign(""); + + mInitType = eNotInitialized; + + mSpec.vRefNum = 0; + mSpec.parID = 0; + mSpec.name[0] = 0; } nsLocalFile::~nsLocalFile() { } -/* nsISupports interface implementation. */ -NS_IMPL_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile) +#pragma mark - +#pragma mark [nsISupports interface implementation] +NS_IMPL_ISUPPORTS3(nsLocalFile, nsILocalFileMac, nsILocalFile, nsIFile) + NS_METHOD -nsLocalFile::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) +nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); - NS_ENSURE_PROPER_AGGREGATION(outer, aIID); + NS_ENSURE_NO_AGGREGATION(outer); nsLocalFile* inst = new nsLocalFile(); if (inst == NULL) @@ -232,29 +479,128 @@ nsLocalFile::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) void nsLocalFile::MakeDirty() { - mStatDirty = PR_TRUE; + mStatDirty = PR_TRUE; + + mResolvedSpec.vRefNum = 0; + mResolvedSpec.parID = 0; + mResolvedSpec.name[0] = 0; } + +NS_IMETHODIMP +nsLocalFile::ResolveAndStat(PRBool resolveTerminal) +{ + OSErr err = noErr; + char *filePath; + + if (!mStatDirty && resolveTerminal == mLastResolveFlag) + { + return NS_OK; + } + + mLastResolveFlag = resolveTerminal; + + // See if we have been initialized with a spec + switch (mInitType) + { + case eInitWithPath: + { + filePath = (char *)nsAllocator::Clone(mWorkingPath, strlen(mWorkingPath)+1); + err = ResolvePathAndSpec(filePath, nsnull, PR_FALSE, &mResolvedSpec); + nsAllocator::Free(filePath); + break; + } + + case eInitWithFSSpec: + { + if (strlen(mAppendedPath)) + { // We've got an FSSpec and an appended path so pass 'em both to ResolvePathAndSpec + filePath = (char *)nsAllocator::Clone(mAppendedPath, strlen(mAppendedPath)+1); + err = ResolvePathAndSpec(filePath, &mSpec, PR_FALSE, &mResolvedSpec); + nsAllocator::Free(filePath); + } + else + { + err = ::FSMakeFSSpec(mSpec.vRefNum, mSpec.parID, mSpec.name, &mResolvedSpec); + } + break; + } + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } + + if (resolveTerminal && err == noErr) + { + // Resolve the alias to the original file. + FSSpec spec = mResolvedSpec; + Boolean targetIsFolder; + Boolean wasAliased; + err = ::ResolveAliasFile(&spec, TRUE, &targetIsFolder, &wasAliased); + if (err != noErr) + return MacErrorMapper(err); + else + mResolvedSpec = spec; + } + + + if (err == noErr) + { + mStatDirty = PR_TRUE; + } + + return (MacErrorMapper(err)); +} + + NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { + nsresult rv; NS_ENSURE_ARG(file); *file = nsnull; - - nsCOMPtr localFile; - nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, - nsnull, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(localFile)); - if (NS_FAILED(rv)) - return rv; + + // Create the new nsLocalFile + nsCOMPtr localFile = new nsLocalFile(); + if (localFile == NULL) + return NS_ERROR_OUT_OF_MEMORY; - char* aFilePath; - GetPath(&aFilePath); - - rv = localFile->InitWithPath(aFilePath); + // See if it's a nsLocalFileMac (shouldn't be possible for it not to be) + nsCOMPtr localFileMac = do_QueryInterface(localFile); + if (localFileMac == NULL) + return NS_ERROR_NO_INTERFACE; - nsAllocator::Free(aFilePath); + // Now we figure out how we were initialized in order to determine how to + // initialize the clone + nsLocalFileMacInitType initializedAs; + localFileMac->GetInitType(&initializedAs); + switch (mInitType) + { + case eInitWithPath: + // The simple case + char *path; + GetPath(&path); + localFile->InitWithPath(path); + break; + + case eInitWithFSSpec: + // Slightly more complex as we need to set the FSSpec and any appended + // path info + // ????? Should we just set this to the resolved spec ????? + localFileMac->InitWithFSSpec(&mSpec); + // Now set any appended path info + char *appendedPath; + GetAppendedPath(&appendedPath); + localFileMac->SetAppendedPath(appendedPath); + break; + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } if (NS_FAILED(rv)) return rv; @@ -280,91 +626,134 @@ nsLocalFile::InitWithPath(const char *filePath) // about turniung it into an FSSpec until the Create() method is called mWorkingPath.SetString(filePath); + mInitType = eInitWithPath; + return NS_OK; } NS_IMETHODIMP -nsLocalFile::Open(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) +nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) { - return NS_ERROR_FAILURE; +// Macintosh doesn't really have mode bits, just drop them +#pragma unused (mode) + + NS_ENSURE_ARG(_retval); + + ResolveAndStat(PR_TRUE); + + OSErr err = noErr; + + // Resolve the alias to the original file. + FSSpec spec = mResolvedSpec; + Boolean targetIsFolder; + Boolean wasAliased; + err = ::ResolveAliasFile(&spec, TRUE, &targetIsFolder, &wasAliased); + if (err != noErr) + return MacErrorMapper(err); + + if (flags & PR_CREATE_FILE) + err = ::FSpCreate(&spec, 'MOSS', 'TEXT', 0); + + /* If opening with the PR_EXCL flag the existence of the file prior to opening is an error */ + if ((flags & PR_EXCL) && (err == dupFNErr)) + return MacErrorMapper(err); + + if (err == dupFNErr) + err = noErr; + if (err != noErr) + return MacErrorMapper(err); + + SInt8 perm; + if (flags & PR_RDWR) + perm = fsRdWrPerm; + else if (flags & PR_WRONLY) + perm = fsWrPerm; + else + perm = fsRdPerm; + + short refnum; + err = ::FSpOpenDF(&spec, perm, &refnum); + + if (err == noErr && (flags & PR_TRUNCATE)) + err = ::SetEOF(refnum, 0); + if (err == noErr && (flags & PR_APPEND)) + err = ::SetFPos(refnum, fsFromLEOF, 0); + if (err != noErr) + return MacErrorMapper(err); + + if ((*_retval = PR_ImportFile(refnum)) == 0) + return NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES,(PR_GetError() & 0xFFFF)); + + return NS_OK; } +NS_IMETHODIMP +nsLocalFile::OpenANSIFileDesc(const char *mode, FILE * *_retval) +{ + nsresult rv = ResolveAndStat(PR_TRUE); + if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) + return rv; + + + // Resolve the alias to the original file. + FSSpec spec = mResolvedSpec; + Boolean targetIsFolder; + Boolean wasAliased; + OSErr err = ::ResolveAliasFile(&spec, TRUE, &targetIsFolder, &wasAliased); + if (err != noErr) + return MacErrorMapper(err); + + + *_retval = FSp_fopen(&spec, mode); + + if (*_retval) + return NS_OK; + + return NS_ERROR_FAILURE; +} + + NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 attributes) { + OSErr err; + char *filePath; + if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE) return NS_ERROR_FILE_UNKNOWN_TYPE; - OSErr err = noErr; - char* filePath = (char*) nsAllocator::Clone( mWorkingPath, strlen(mWorkingPath)+1 ); - size_t inLength = strlen(filePath); - - if (inLength < 255) - { - Str255 pascalpath; - myPLstrcpy(pascalpath, filePath); - err = ::FSMakeFSSpec(0, 0, pascalpath, &mSpec); - } - else - err = FSpLocationFromFullPath(inLength, filePath, &mSpec); - - if ((err == dirNFErr || err == bdNamErr)) - { - const char* path = filePath; - mSpec.vRefNum = 0; - mSpec.parID = 0; - - do - { - // Locate the colon that terminates the node. - // But if we've a partial path (starting with a colon), find the second one. - const char* nextColon = strchr(path + (*path == ':'), ':'); - // Well, if there are no more colons, point to the end of the string. - if (!nextColon) - nextColon = path + strlen(path); - - // Make a pascal string out of this node. Include initial - // and final colon, if any! - Str255 ppath; - myPLstrncpy(ppath, path, nextColon - path + 1); - - // Use this string as a relative path using the directory created - // on the previous round (or directory 0,0 on the first round). - err = ::FSMakeFSSpec(mSpec.vRefNum, mSpec.parID, ppath, &mSpec); - - // If this was the leaf node, then we are done. - if (!*nextColon) - break; - - // Since there's more to go, we have to get the directory ID, which becomes - // the parID for the next round. - if (err == noErr) - { - // The directory (or perhaps a file) exists. Find its dirID. - long dirID; - Boolean isDirectory; - err = ::FSpGetDirectoryID(&mSpec, &dirID, &isDirectory); - if (!isDirectory) - err = dupFNErr; // oops! a file exists with that name. - if (err != noErr) - break; // bail if we've got an error - mSpec.parID = dirID; - } - else if (err == fnfErr) - { - // If we got "file not found", then we need to create a directory. - err = ::FSpDirCreate(&mSpec, smCurrentScript, &mSpec.parID); - // For some reason, this usually returns fnfErr, even though it works. - if (err == fnfErr) - err = noErr; - } - if (err != noErr) - break; - path = nextColon; // next round - } while (true); - } + switch (mInitType) + { + case eInitWithPath: + { + filePath = (char *)nsAllocator::Clone(mWorkingPath, strlen(mWorkingPath)+1); + err = ResolvePathAndSpec(filePath, nsnull, PR_FALSE, &mResolvedSpec); + nsAllocator::Free(filePath); + break; + } + + case eInitWithFSSpec: + { + if (strlen(mAppendedPath)) + { // We've got an FSSpec and an appended path so pass 'em both to ResolvePathAndSpec + filePath = (char *)nsAllocator::Clone(mAppendedPath, strlen(mAppendedPath)+1); + err = ResolvePathAndSpec(filePath, &mSpec, PR_FALSE, &mResolvedSpec); + nsAllocator::Free(filePath); + } + else + { + err = ::FSMakeFSSpec(mSpec.vRefNum, mSpec.parID, mSpec.name, &mResolvedSpec); + } + break; + } + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } - if (err != noErr) + if (err != noErr && err != fnfErr) return (MacErrorMapper(err)); switch (type) @@ -372,12 +761,12 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) case NORMAL_FILE_TYPE: // We really should use some sort of meaningful file type/creator but where // do we get the info from? - err = ::FSpCreate(&mSpec, '????', '????', smCurrentScript); + err = ::FSpCreate(&mResolvedSpec, '????', '????', smCurrentScript); return (MacErrorMapper(err)); break; case DIRECTORY_TYPE: - err = ::FSpDirCreate(&mSpec, smCurrentScript, &mSpec.parID); + err = ::FSpDirCreate(&mResolvedSpec, smCurrentScript, &mResolvedSpec.parID); // For some reason, this usually returns fnfErr, even though it works. if (err == fnfErr) err = noErr; @@ -394,318 +783,197 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) } NS_IMETHODIMP -nsLocalFile::AppendPath(const char *node) +nsLocalFile::Append(const char *node) { - if ( (node == nsnull) || (*node == '/') || strchr(node, '\\') ) + if ( (node == nsnull) ) return NS_ERROR_FILE_UNRECOGNIZED_PATH; MakeDirty(); - // We only can append relative unix styles strings. - - // Convert '\' to '/' - nsString path(node); - - char* nodeCString = path.ToNewCString(); - char* temp = nodeCString; - for (; *temp; temp++) + // Yee Hah! We only get a single node at a time so just append it + // to either the mWorkingPath or mAppendedPath, after adding the ':' + // directory delimeter, depending on how we were initialized + switch (mInitType) { - if (*temp == '/') - *temp = '\\'; - } - - // kill any trailing seperator - if(nodeCString) - { - temp = nodeCString; - int len = strlen(temp) - 1; - if(temp[len] == '\\') - temp[len] = '\0'; + case eInitWithPath: + mWorkingPath.Append(":"); + mWorkingPath.Append(node); + break; + + case eInitWithFSSpec: + mAppendedPath.Append(":"); + mAppendedPath.Append(node); + break; + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; } - mWorkingPath.Append("\\"); - mWorkingPath.Append(nodeCString); - - Recycle(nodeCString); - return NS_OK; } -NS_IMETHODIMP -nsLocalFile::Normalize() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsLocalFile::GetLeafName(char * *aLeafName) { NS_ENSURE_ARG_POINTER(aLeafName); - const char* temp = mWorkingPath.GetBuffer(); - if(temp == nsnull) - return NS_ERROR_FILE_UNRECOGNIZED_PATH; + switch (mInitType) + { + case eInitWithPath: + const char* temp = mWorkingPath.GetBuffer(); + if (temp == nsnull) + return NS_ERROR_FILE_UNRECOGNIZED_PATH; - const char* leaf = strrchr(temp, '\\'); - - // if the working path is just a node without any lashes. - if (leaf == nsnull) - leaf = temp; - else - leaf++; + const char* leaf = strrchr(temp, ':'); + + // if the working path is just a node without any directory delimeters. + if (leaf == nsnull) + leaf = temp; + else + leaf++; + + *aLeafName = (char*) nsAllocator::Clone(leaf, strlen(leaf)+1); + break; + + case eInitWithFSSpec: + // See if we've had a path appended + if (mAppendedPath.Length()) + { + const char* temp = mAppendedPath.GetBuffer(); + if (temp == nsnull) + return NS_ERROR_FILE_UNRECOGNIZED_PATH; + + const char* leaf = strrchr(temp, ':'); + + // if the working path is just a node without any directory delimeters. + if (leaf == nsnull) + leaf = temp; + else + leaf++; + + *aLeafName = (char*) nsAllocator::Clone(leaf, strlen(leaf)+1); + } + else + { + // We don't have an appended path so grab the leaf name from the FSSpec + // Convert the Pascal string to a C string + unsigned long len = mSpec.name[0]; + char * tempStr = (char *)PR_MALLOC(len); + if (tempStr) + { + ::BlockMoveData(&mSpec.name[1], tempStr, len); + tempStr[len] = NULL; + *aLeafName = (char*) nsAllocator::Clone(tempStr, strlen(tempStr)+1); + } + } + break; + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } - *aLeafName = (char*) nsAllocator::Clone(leaf, strlen(leaf)+1); return NS_OK; } +NS_IMETHODIMP +nsLocalFile::SetLeafName(const char * aLeafName) +{ + NS_ENSURE_ARG_POINTER(aLeafName); + + switch (mInitType) + { + case eInitWithPath: + PRInt32 offset = mWorkingPath.RFindChar(':'); + if (offset) + { + mWorkingPath.Truncate(offset + 1); + } + mWorkingPath.Append(aLeafName); + break; + + case eInitWithFSSpec: + // See if we've had a path appended + if (mAppendedPath.Length()) + { // Lop off the end of the appended path and replace it with the new leaf name + PRInt32 offset = mAppendedPath.RFindChar(':'); + if (offset) + { + mAppendedPath.Truncate(offset + 1); + } + mAppendedPath.Append(aLeafName); + } + else + { + // We don't have an appended path so directly modify the FSSpec + myPLstrcpy(mSpec.name, aLeafName); + } + break; + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } + + return NS_OK; +} NS_IMETHODIMP nsLocalFile::GetPath(char **_retval) { NS_ENSURE_ARG_POINTER(_retval); - *_retval = (char*) nsAllocator::Clone(mWorkingPath, strlen(mWorkingPath)+1); + + switch (mInitType) + { + case eInitWithPath: + *_retval = (char*) nsAllocator::Clone(mWorkingPath, strlen(mWorkingPath)+1); + break; + + case eInitWithFSSpec: + { // Now would be a good time to call the code that makes an FSSpec into a path + short fullPathLen; + Handle fullPathHandle; + OSErr err; + ResolveAndStat(PR_TRUE); + err = FSpGetFullPath(&mResolvedSpec, &fullPathLen, &fullPathHandle); + *_retval = (char*) nsAllocator::Clone(*fullPathHandle, fullPathLen+1); + DisposeHandle(fullPathHandle); + + ((*_retval)+fullPathLen)[0] = 0; + + break; + } + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } + return NS_OK; } - -nsresult -nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char * newName, PRBool followSymlinks, PRBool move) -{ - nsresult rv; - char* filePath; - - // get the path that we are going to copy to. - // Since windows does not know how to auto - // resolve shortcust, we must work with the - // target. - char* inFilePath; - destParent->GetTarget(&inFilePath); - nsCString destPath = inFilePath; - nsAllocator::Free(inFilePath); - - destPath.Append("\\"); - - if (newName == nsnull) - { - char *aFileName; - sourceFile->GetLeafName(&aFileName); - destPath.Append(aFileName); - nsAllocator::Free(aFileName); - } - else - { - destPath.Append(newName); - } - - - if (followSymlinks) - { - rv = sourceFile->GetTarget(&filePath); - } - else - { - rv = sourceFile->GetPath(&filePath); - } - - if (NS_FAILED(rv)) - return rv; - - //int copyOK; - - if (!move) - { - //copyOK = CopyFile(filePath, destPath, PR_TRUE); - } - else - { - //copyOK = MoveFile(filePath, destPath); - } - - //if (!copyOK) // CopyFile and MoveFile returns non-zero if succeeds (backward if you ask me). - - nsAllocator::Free(filePath); - - return rv; -} - - -nsresult -nsLocalFile::CopyMove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move) -{ - NS_ENSURE_ARG(newParentDir); - nsresult rv = NS_OK; - - // check to see if this exists, otherwise return an error. - PRBool sourceExists; - Exists(&sourceExists); - if (sourceExists == PR_FALSE) - { - return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST; - } - - // make sure destination exists and is a directory. Create it if not there. - PRBool parentExists; - newParentDir->Exists(&parentExists); - if (parentExists == PR_FALSE) - { - rv = newParentDir->Create(DIRECTORY_TYPE, 0); - if (NS_FAILED(rv)) - return rv; - } - else - { - PRBool isDir; - newParentDir->IsDirectory(&isDir); - if (isDir == PR_FALSE) - { - if (followSymlinks) - { - PRBool isLink; - newParentDir->IsSymlink(&isLink); - if (isLink) - { - char* target; - newParentDir->GetTarget(&target); - - nsCOMPtr realDest; - - rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, - nsnull, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(realDest)); - if (NS_FAILED(rv)) - return rv; - - rv = realDest->InitWithPath(target); - - nsAllocator::Free(target); - - if (NS_FAILED(rv)) - return rv; - - return CopyMove(realDest, newName, followSymlinks, move); - } - } - else - { - return NS_ERROR_FILE_DESTINATION_NOT_DIR; - } - } - } - - // check to see if we are a directory, if so enumerate it. - - PRBool isDir; - IsDirectory(&isDir); - if (!isDir) - { - rv = CopySingleFile(this, newParentDir, newName, followSymlinks, move); - if (NS_FAILED(rv)) - return rv; - } - else - { - // create a new target destination in the new parentDir; - nsCOMPtr target; - newParentDir->Clone(getter_AddRefs(target)); - - char *allocatedNewName; - if (!newName) - { - GetLeafName(&allocatedNewName);// this should be the leaf name of the - } - else - { - allocatedNewName = (char*) nsAllocator::Clone( newName, strlen(newName)+1 ); - } - - rv = target->AppendPath(allocatedNewName); - if (NS_FAILED(rv)) - return rv; - - nsAllocator::Free(allocatedNewName); - - target->Create(DIRECTORY_TYPE, 0); - if (NS_FAILED(rv)) - return rv; - - nsDirEnumerator* dirEnum = new nsDirEnumerator(); - if (!dirEnum) - return NS_ERROR_OUT_OF_MEMORY; - - rv = dirEnum->Init(this); - - nsCOMPtr iterator = do_QueryInterface(dirEnum); - - PRBool more; - iterator->HasMoreElements(&more); - while (more) - { - nsCOMPtr item; - nsCOMPtr file; - iterator->GetNext(getter_AddRefs(item)); - file = do_QueryInterface(item); - PRBool isDir, isLink; - - file->IsDirectory(&isDir); - file->IsSymlink(&isLink); - - if (move) - { - rv = file->MoveTo(target, nsnull); - } - else - { - if (followSymlinks) - rv = file->CopyToFollowingLinks(target, nsnull); - else - rv = file->CopyTo(target, nsnull); - } - - iterator->HasMoreElements(&more); - } - } - - - // If we moved, we want to adjust this. - if (move) - { - if (newName == nsnull) - { - char *aFileName; - GetLeafName(&aFileName); - InitWithFile(newParentDir); - AppendPath(aFileName); - nsAllocator::Free(aFileName); - } - else - { - InitWithFile(newParentDir); - AppendPath(newName); - } - MakeDirty(); - } - - return NS_OK; -} - NS_IMETHODIMP nsLocalFile::CopyTo(nsIFile *newParentDir, const char *newName) { - return CopyMove(newParentDir, newName, PR_FALSE, PR_FALSE); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const char *newName) { - return CopyMove(newParentDir, newName, PR_TRUE, PR_FALSE); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName) { - return CopyMove(newParentDir, newName, PR_FALSE, PR_TRUE); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP @@ -721,6 +989,31 @@ nsLocalFile::Spawn(const char *args) return NS_ERROR_FILE_EXECUTION_FAILED; } +NS_IMETHODIMP +nsLocalFile::Load(PRLibrary * *_retval) +{ + PRBool isFile; + nsresult rv = IsFile(&isFile); + + if (NS_FAILED(rv)) + return rv; + + if (! isFile) + return NS_ERROR_FILE_IS_DIRECTORY; + + // Use the new PR_LoadLibraryWithFlags which allows us to use a FSSpec + PRLibSpec libSpec; + libSpec.type = PR_LibSpec_MacIndexedFragment; + libSpec.value.mac_indexed_fragment.fsspec = &mResolvedSpec; + libSpec.value.mac_indexed_fragment.index = 0; + *_retval = PR_LoadLibraryWithFlags(libSpec, 0); + + if (*_retval) + return NS_OK; + + return NS_ERROR_NULL_POINTER; +} + NS_IMETHODIMP nsLocalFile::Delete(PRBool recursive) { @@ -808,31 +1101,6 @@ nsLocalFile::SetLastModificationDateOfLink(PRInt64 aLastModificationDate) return NS_OK; } -NS_IMETHODIMP -nsLocalFile::GetPermissions(PRUint32 *aPermissions) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NS_IMETHODIMP -nsLocalFile::SetPermissions(PRUint32 aPermissions) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissions) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsLocalFile::GetFileSize(PRInt64 *aFileSize) @@ -842,6 +1110,21 @@ nsLocalFile::GetFileSize(PRInt64 *aFileSize) aFileSize->hi = 0; aFileSize->lo = 0; + ResolveAndStat(PR_TRUE); + + long dataSize, resSize; + + OSErr err = FSpGetFileSize(&mResolvedSpec, &dataSize, &resSize); + + if (err != noErr) + return MacErrorMapper(err); + + // For now we've only got 32 bits of file size info + PRInt64 resInt64, dataInt64; + LL_I2L(resInt64, resSize); + LL_I2L(dataInt64, dataSize); + LL_ADD((*aFileSize), dataInt64, resInt64); + return NS_OK; } @@ -849,7 +1132,35 @@ nsLocalFile::GetFileSize(PRInt64 *aFileSize) NS_IMETHODIMP nsLocalFile::SetFileSize(PRInt64 aFileSize) { + PRBool exists; + + Exists(&exists); + if (exists) + { + short refNum; + OSErr err; + PRInt32 aNewLength; + + LL_L2I(aNewLength, aFileSize); + + // Need to open the file to set the size + if (::FSpOpenDF(&mResolvedSpec, fsWrPerm, &refNum) != noErr) + return NS_ERROR_FILE_ACCESS_DENIED; + err = ::SetEOF(refNum, aNewLength); + + // Close the file unless we got an error that it was already closed + if (err != fnOpnErr) + (void)::FSClose(refNum); + + if (err != noErr) + return MacErrorMapper(err); + } + else + { + return NS_ERROR_FILE_NOT_FOUND; + } + return NS_OK; } @@ -872,7 +1183,7 @@ nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable) pb.ioCompletion = nsnull; pb.ioVolIndex = 0; pb.ioNamePtr = nsnull; - pb.ioVRefNum = mSpec.vRefNum; + pb.ioVRefNum = mResolvedSpec.vRefNum; OSErr err = ::PBXGetVolInfoSync(&pb); @@ -892,23 +1203,39 @@ nsLocalFile::GetParent(nsIFile * *aParent) { NS_ENSURE_ARG_POINTER(aParent); - nsCString parentPath = mWorkingPath; + switch (mInitType) + { + case eInitWithPath: + { // The simple case when we have a full path to something + nsCString parentPath = mWorkingPath; - PRInt32 offset = parentPath.RFindChar('\\'); - if (offset == -1) - return NS_ERROR_FILE_UNRECOGNIZED_PATH; + PRInt32 offset = parentPath.RFindChar(':'); + if (offset == -1) + return NS_ERROR_FILE_UNRECOGNIZED_PATH; - parentPath.Truncate(offset); + parentPath.Truncate(offset); - const char* filePath = parentPath.GetBuffer(); + nsCOMPtr localFile; + nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile)); - nsLocalFile* file = new nsLocalFile(); - if (file == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - file->AddRef(); - file->InitWithPath(filePath); - *aParent = file; + if (NS_SUCCEEDED(rv) && localFile) + { + return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent); + } + return rv; + break; + } + + case eInitWithFSSpec: + { + break; + } + + default: + // !!!!! Danger Will Robinson !!!!! + // we really shouldn't get here + break; + } return NS_OK; } @@ -917,7 +1244,13 @@ NS_IMETHODIMP nsLocalFile::Exists(PRBool *_retval) { NS_ENSURE_ARG(_retval); - + *_retval = PR_FALSE; // Assume failure + (void)ResolveAndStat(PR_TRUE); + + FSSpec temp; + if (::FSMakeFSSpec(mResolvedSpec.vRefNum, mResolvedSpec.parID, mResolvedSpec.name, &temp) == noErr) + *_retval = PR_TRUE; + return NS_OK; } @@ -959,6 +1292,16 @@ nsLocalFile::IsDirectory(PRBool *_retval) NS_ENSURE_ARG(_retval); *_retval = PR_FALSE; + nsresult rv = ResolveAndStat(PR_TRUE); + + if (NS_FAILED(rv)) + return rv; + + long dirID; + Boolean isDirectory; + if ((::FSpGetDirectoryID(&mResolvedSpec, &dirID, &isDirectory) == noErr) && isDirectory) + *_retval = PR_TRUE; + return NS_OK; } @@ -968,6 +1311,16 @@ nsLocalFile::IsFile(PRBool *_retval) NS_ENSURE_ARG(_retval); *_retval = PR_FALSE; + nsresult rv = ResolveAndStat(PR_TRUE); + + if (NS_FAILED(rv)) + return rv; + + long dirID; + Boolean isDirectory; + if ((::FSpGetDirectoryID(&mResolvedSpec, &dirID, &isDirectory) == noErr) && !isDirectory) + *_retval = PR_TRUE; + return NS_OK; } @@ -986,12 +1339,6 @@ nsLocalFile::IsSymlink(PRBool *_retval) return NS_OK; } -NS_IMETHODIMP -nsLocalFile::IsSpecial(PRBool *_retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) { @@ -1017,9 +1364,27 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) NS_IMETHODIMP nsLocalFile::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) { - NS_ENSURE_ARG(_retval); *_retval = PR_FALSE; - return NS_ERROR_NOT_IMPLEMENTED; + + char* myFilePath; + if ( NS_FAILED(GetTarget(&myFilePath))) + GetPath(&myFilePath); + + PRInt32 myFilePathLen = strlen(myFilePath); + + char* inFilePath; + if ( NS_FAILED(inFile->GetTarget(&inFilePath))) + inFile->GetPath(&inFilePath); + + if ( strncmp( myFilePath, inFilePath, myFilePathLen) == 0) + { + *_retval = PR_TRUE; + } + + nsAllocator::Free(inFilePath); + nsAllocator::Free(myFilePath); + + return NS_OK; } @@ -1075,6 +1440,151 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) return NS_OK; } +#pragma mark - +#pragma mark [Methods that won't be implemented on Mac] + +NS_IMETHODIMP +nsLocalFile::Normalize() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsLocalFile::GetPermissions(PRUint32 *aPermissions) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} +NS_IMETHODIMP +nsLocalFile::SetPermissions(PRUint32 aPermissions) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissions) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsLocalFile::IsSpecial(PRBool *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +#pragma mark - +#pragma mark [nsILocalFileMac] +// Implementation of Mac specific finctions from nsILocalFileMac + + +NS_IMETHODIMP nsLocalFile::GetInitType(nsLocalFileMacInitType *type) +{ + NS_ENSURE_ARG(type); + *type = mInitType; + return NS_OK; +} + +NS_IMETHODIMP nsLocalFile::InitWithFSSpec(const FSSpec *fileSpec) +{ + MakeDirty(); + mSpec = *fileSpec; + mInitType = eInitWithFSSpec; + return NS_OK; +} + +NS_IMETHODIMP nsLocalFile::GetFSSpec(FSSpec *fileSpec) +{ + NS_ENSURE_ARG(fileSpec); + *fileSpec = mSpec; + return NS_OK; + +} + +NS_IMETHODIMP nsLocalFile::GetResolvedFSSpec(FSSpec *fileSpec) +{ + NS_ENSURE_ARG(fileSpec); + *fileSpec = mResolvedSpec; + return NS_OK; + +} + +NS_IMETHODIMP nsLocalFile::SetAppendedPath(const char *aPath) +{ + MakeDirty(); + + mAppendedPath.SetString(aPath); + + return NS_OK; +} + +NS_IMETHODIMP nsLocalFile::GetAppendedPath(char **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + *_retval = (char*) nsAllocator::Clone(mAppendedPath, strlen(mAppendedPath)+1); + return NS_OK; +} + +NS_IMETHODIMP nsLocalFile::GetFileTypeAndCreator(OSType *type, OSType *creator) +{ + NS_ENSURE_ARG(type); + NS_ENSURE_ARG(creator); + + ResolveAndStat(PR_TRUE); + + FInfo info; + OSErr err = ::FSpGetFInfo(&mResolvedSpec, &info); + if (err != noErr) + return NS_ERROR_FILE_NOT_FOUND; + *type = info.fdType; + *creator = info.fdCreator; + + return NS_OK; +} + +NS_IMETHODIMP nsLocalFile::SetFileTypeAndCreator(OSType type, OSType creator) +{ + FInfo info; + OSErr err = ::FSpGetFInfo(&mResolvedSpec, &info); + if (err != noErr) + return NS_ERROR_FILE_NOT_FOUND; + + // See if the user specified a type or creator before changing from what was read + if (type) + info.fdType = type; + if (creator) + info.fdCreator = creator; + + err = ::FSpSetFInfo(&mResolvedSpec, &info); + if (err != noErr) + return NS_ERROR_FILE_ACCESS_DENIED; + + return NS_OK; +} + + +// Handy dandy utility create routine for something or the other +NS_COM nsresult +NS_NewLocalFile(const char* path, nsILocalFile* *result) +{ + nsLocalFile* file = new nsLocalFile(); + if (file == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(file); + + nsresult rv = file->InitWithPath(path); + if (NS_FAILED(rv)) { + NS_RELEASE(file); + return rv; + } + *result = file; + return NS_OK; +} diff --git a/mozilla/xpcom/io/nsLocalFileMac.h b/mozilla/xpcom/io/nsLocalFileMac.h index 51ce1c11b75..439007de65b 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.h +++ b/mozilla/xpcom/io/nsLocalFileMac.h @@ -31,12 +31,13 @@ #include "nsCRT.h" #include "nsIFile.h" #include "nsILocalFile.h" +#include "nsILocalFileMac.h" #include "nsIFactory.h" #include "nsLocalFile.h" #include -class NS_COM nsLocalFile : public nsILocalFile +class NS_COM nsLocalFile : public nsILocalFile, public nsILocalFileMac { public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID) @@ -44,7 +45,7 @@ public: nsLocalFile(); virtual ~nsLocalFile(); - static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); + static NS_METHOD nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); // nsISupports interface NS_DECL_ISUPPORTS @@ -55,25 +56,46 @@ public: // nsILocalFile interface NS_DECL_NSILOCALFILE + NS_IMETHOD GetInitType(nsLocalFileMacInitType *type); + + NS_IMETHOD InitWithFSSpec(const FSSpec *fileSpec); + + NS_IMETHOD GetFSSpec(FSSpec *fileSpec); + NS_IMETHOD GetResolvedFSSpec(FSSpec *fileSpec); + + NS_IMETHOD SetAppendedPath(const char *aPath); + NS_IMETHOD GetAppendedPath(char * *aPath); + + NS_IMETHOD GetFileTypeAndCreator(OSType *type, OSType *creator); + NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator); + private: // this is the flag which indicates if I can used cached information about the file - PRBool mStatDirty; + PRBool mStatDirty; + PRBool mLastResolveFlag; - // this string will alway be in native format! - nsCString mWorkingPath; + // If we're inited with a path then we store it here + nsCString mWorkingPath; + // Any nodes added with AppendPath if we were initialized with an FSSpec are stored here + nsCString mAppendedPath; + // this will be the resolved path which will *NEVER* be returned to the user - nsCString mResolvedPath; + nsCString mResolvedPath; // The Mac data structure for a file system object - FSSpec mSpec; + FSSpec mSpec; // This is the raw spec from InitWIthPath or InitWithFSSpec + FSSpec mResolvedSpec; // This is the spec we've called ResolveAlias on + + // Is the mResolvedSpec member valid? Only after we resolve the mSpec or mWorkingPath + PRBool mHaveValidSpec; + + // It's important we keep track of how we were initialized + nsLocalFileMacInitType mInitType; void MakeDirty(); - - nsresult CopyMove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move); - nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const char * newName, PRBool followSymlinks, PRBool move); - + nsresult ResolveAndStat(PRBool resolveTerminal); }; #endif diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index 1186d4c4d97..64adcc976bb 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -28,26 +28,25 @@ /* we're going to need some autoconf loving, I can just tell */ #include -/* XXXautoconf for glibc */ -#define __USE_BSD #include #include #include #include #include +#include #include "nsCRT.h" #include "nsCOMPtr.h" -#include "nsFileUtils.h" #include "nsIAllocator.h" -#include "nsIDirectoryEnumerator.h" #include "nsIFile.h" +#include "nsILocalFile.h" #include "nsLocalFileUnix.h" +#include "nsIComponentManager.h" -#define FILL_STAT_CACHE() \ +#define VALIDATE_STAT_CACHE() \ PR_BEGIN_MACRO \ if (!mHaveCachedStat) { \ - fillStatCache(); \ + FillStatCache(); \ if (!mHaveCachedStat) \ return NSRESULT_FOR_ERRNO(); \ } \ @@ -59,6 +58,123 @@ return NS_ERROR_NOT_INITIALIZED; \ PR_END_MACRO +#define mLL_II2L(hi, lo, res) \ + LL_I2L(res, hi); \ + LL_SHL(res, res, 32); \ + LL_ADD(res, res, lo); + +#define mLL_L2II(a64, hi, lo) \ + PR_BEGIN_MACRO \ + PRInt64 tmp; \ + LL_SHR(tmp, a64, 32); \ + LL_L2I(hi, tmp); \ + LL_SHL(tmp, a64, 32); \ + LL_SHR(tmp, tmp, 32); \ + LL_L2I(lo, tmp); \ + PR_END_MACRO + +/* directory enumerator */ +class NS_COM +nsDirEnumeratorUnix : public nsISimpleEnumerator +{ + public: + nsDirEnumeratorUnix(); + virtual ~nsDirEnumeratorUnix(); + + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator interface + NS_DECL_NSISIMPLEENUMERATOR + + NS_IMETHOD Init(nsIFile *parent, PRBool ignored); + protected: + NS_IMETHOD GetNextEntry(); + + DIR *mDir; + struct dirent *mEntry; + nsXPIDLCString mParentPath; +}; + +nsDirEnumeratorUnix::nsDirEnumeratorUnix() : + mDir(nsnull), mEntry(nsnull) +{ + NS_INIT_REFCNT(); +} + +nsDirEnumeratorUnix::~nsDirEnumeratorUnix() +{ + if (mDir) + closedir(mDir); +} + +NS_IMPL_ISUPPORTS1(nsDirEnumeratorUnix, nsISimpleEnumerator) + +NS_IMETHODIMP +nsDirEnumeratorUnix::Init(nsIFile *parent, PRBool resolveSymlinks /*ignored*/) +{ + nsXPIDLCString dirPath; + if (NS_FAILED(parent->GetPath(getter_Copies(dirPath))) || + (const char *)dirPath == 0) + return NS_ERROR_FILE_INVALID_PATH; + + if (NS_FAILED(parent->GetPath(getter_Copies(mParentPath)))) + return NS_ERROR_FAILURE; + + mDir = opendir(dirPath); + if (!mDir) + return NSRESULT_FOR_ERRNO(); + return GetNextEntry(); +} + +NS_IMETHODIMP +nsDirEnumeratorUnix::HasMoreElements(PRBool *result) +{ + *result = mDir && mEntry; + return NS_OK; +} + +NS_IMETHODIMP +nsDirEnumeratorUnix::GetNext(nsISupports **_retval) +{ + nsresult rv; + if (!mDir || !mEntry) { + *_retval = nsnull; + return NS_OK; + } + + nsCOMPtr file = new nsLocalFile(); + if (!file) + return NS_ERROR_OUT_OF_MEMORY; + + if (NS_FAILED(rv = file->InitWithPath(mParentPath)) || + NS_FAILED(rv = file->Append(mEntry->d_name))) { + return rv; + } + *_retval = file; + NS_ADDREF(*_retval); + return GetNextEntry(); +} + +NS_IMETHODIMP +nsDirEnumeratorUnix::GetNextEntry() +{ + do { + errno = 0; + mEntry = readdir(mDir); + + /* end of dir or error */ + if (!mEntry) + return NSRESULT_FOR_ERRNO(); + + /* keep going past "." and ".." */ + } while (mEntry->d_name[0] == '.' && + (mEntry->d_name[1] == '\0' || /* .\0 */ + (mEntry->d_name[1] == '.' && + mEntry->d_name[2] == '\0'))); /* ..\0 */ + return NS_OK; +} + nsLocalFile::nsLocalFile() : mHaveCachedStat(PR_FALSE) { @@ -70,13 +186,13 @@ nsLocalFile::~nsLocalFile() { } -NS_IMPL_ISUPPORTS1(nsLocalFile, nsIFile); +NS_IMPL_ISUPPORTS2(nsLocalFile, nsIFile, nsILocalFile); nsresult -nsLocalFile::Create(nsISupports *outer, const nsIID &aIID, void **aInstancePtr) +nsLocalFile::nsLocalFileConstructor(nsISupports *outer, const nsIID &aIID, void **aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); - NS_ENSURE_PROPER_AGGREGATION(outer, aIID); + NS_ENSURE_NO_AGGREGATION(outer); *aInstancePtr = 0; @@ -86,24 +202,19 @@ nsLocalFile::Create(nsISupports *outer, const nsIID &aIID, void **aInstancePtr) return inst->QueryInterface(aIID, aInstancePtr); } - NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { + nsresult rv; NS_ENSURE_ARG(file); *file = nsnull; - nsCOMPtr localFile; - nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, - nsnull, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(localFile)); + nsCOMPtr localFile = new nsLocalFile(); + if (localFile == nsnull) + return NS_ERROR_OUT_OF_MEMORY; - if (NS_FAILED(rv)) - return rv; - - rv = localfile->InitWithPath(mPath); + rv = localFile->InitWithPath(mPath); if (NS_FAILED(rv)) return rv; @@ -115,28 +226,70 @@ nsLocalFile::Clone(nsIFile **file) } NS_IMETHODIMP -nsLocalFile::InitWithPath(PRUint32 pathType, const char *filePath) +nsLocalFile::InitWithPath(const char *filePath) { NS_ENSURE_ARG(filePath); - NS_ASSERTION(pathType == NATIVE_PATH || - pathType == UNIX_PATH || - pathType == NSPR_PATH, "unrecognized path type"); - - /* NATIVE_PATH == UNIX_PATH == NSPR_PATH for us */ mPath = filePath; - invalidateCache(); + InvalidateCache(); return NS_OK; } NS_IMETHODIMP -nsLocalFile::createAllParentDirectories(PRUint32 permissions) +nsLocalFile::CreateAllAncestors(PRUint32 permissions) { - return NS_ERROR_NOT_IMPLEMENTED; + /* I promise to play nice */ + char *buffer = NS_CONST_CAST(char *, (const char *)mPath), + *ptr = buffer; + +#ifdef DEBUG_NSIFILE + fprintf(stderr, "nsIFile: before: %s\n", buffer); +#endif + + while ((ptr = strchr(ptr + 1, '/'))) { + /* + * Sequences of '/' are equivalent to a single '/'. + */ + if (ptr[1] == '/') + continue; + + /* + * If the path has a trailing slash, don't make the last component here, + * because we'll get EEXISTS in Create when we try to build the final + * component again, and it's easier to condition the logic here than + * there. + */ + if (!ptr[1]) + break; + /* Temporarily NUL-terminate here */ + *ptr = '\0'; +#ifdef DEBUG_NSIFILE + fprintf(stderr, "nsIFile: mkdir(\"%s\")\n", buffer); +#endif + int result = mkdir(buffer, permissions); + /* Put the / back before we (maybe) return */ + *ptr = '/'; + + /* + * We could get EEXISTS for an existing file -- not directory -- + * with the name of one of our ancestors, but that's OK: we'll get + * ENOTDIR when we try to make the next component in the path, + * either here on back in Create, and error out appropriately. + */ + if (result == -1 && errno != EEXIST) + return NSRESULT_FOR_ERRNO(); + } + +#ifdef DEBUG_NSIFILE + fprintf(stderr, "nsIFile: after: %s\n", buffer); +#endif + + return NS_OK; + } NS_IMETHODIMP -nsLocalFile::Open(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) +nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) { CHECK_mPath(); @@ -148,7 +301,18 @@ nsLocalFile::Open(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsLocalFile::OpenANSIFileDesc(const char *mode, FILE * *_retval) +{ + CHECK_mPath(); + + *_retval = fopen(mPath, mode); + + if (*_retval) + return NS_OK; + return NS_ERROR_FAILURE; +} NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 permissions) @@ -166,11 +330,33 @@ nsLocalFile::Create(PRUint32 type, PRUint32 permissions) if (result == -1 && errno == ENOENT) { /* - * if we failed because of missing parent components, try to create them - * and then retry the original creation. + * If we failed because of missing ancestor components, try to create + * them and then retry the original creation. + * + * Ancestor directories get the same permissions as the file we're + * creating, with the X bit set for each of (user,group,other) with + * an R bit in the original permissions. If you want to do anything + * fancy like setgid or sticky bits, do it by hand. */ - if (NS_FAILED(createAllParentDirectories(permissions))) + int dirperm = permissions; + if (permissions & S_IRUSR) + dirperm |= S_IXUSR; + if (permissions & S_IRGRP) + dirperm |= S_IXGRP; + if (permissions & S_IROTH) + dirperm |= S_IXOTH; + +#ifdef DEBUG_NSIFILE + fprintf(stderr, "nsIFile: perm = %o, dirperm = %o\n", permissions, + dirperm); +#endif + + if (NS_FAILED(CreateAllAncestors(dirperm))) return NS_ERROR_FAILURE; + +#ifdef DEBUG_NSIFILE + fprintf(stderr, "nsIFile: Create(\"%s\") again\n", (const char *)mPath); +#endif result = creationFunc((const char *)mPath, permissions); } @@ -184,7 +370,7 @@ nsLocalFile::Create(PRUint32 type, PRUint32 permissions) } NS_IMETHODIMP -nsLocalFile::AppendPath(const char *fragment) +nsLocalFile::Append(const char *fragment) { NS_ENSURE_ARG(fragment); CHECK_mPath(); @@ -196,7 +382,7 @@ nsLocalFile::AppendPath(const char *fragment) strcat(newPath, "/"); strcat(newPath, fragment); mPath = newPath; - invalidateCache(); + InvalidateCache(); nsAllocator::Free(newPath); return NS_OK; } @@ -208,7 +394,7 @@ nsLocalFile::Normalize() } nsresult -nsLocalFile::getLeafNameRaw(const char **_retval) +nsLocalFile::GetLeafNameRaw(const char **_retval) { CHECK_mPath(); char *leafName = strrchr((const char *)mPath, '/'); @@ -224,7 +410,7 @@ nsLocalFile::GetLeafName(char **aLeafName) NS_ENSURE_ARG_POINTER(aLeafName); nsresult rv; const char *leafName; - if (NS_FAILED(rv = getLeafNameRaw(&leafName))) + if (NS_FAILED(rv = GetLeafNameRaw(&leafName))) return rv; *aLeafName = nsCRT::strdup(leafName); @@ -233,8 +419,33 @@ nsLocalFile::GetLeafName(char **aLeafName) return NS_OK; } + + NS_IMETHODIMP -nsLocalFile::GetPath(PRUint32 pathType, char **_retval) +nsLocalFile::SetLeafName(const char *aLeafName) +{ + NS_ENSURE_ARG(aLeafName); + CHECK_mPath(); + + nsresult rv; + char *leafName; + if (NS_FAILED(rv = GetLeafNameRaw((const char**)&leafName))) + return rv; + char* newPath = (char *)nsAllocator::Alloc(strlen(mPath) + + strlen(aLeafName) + 2); + *leafName = 0; + + strcpy(newPath, mPath); + strcat(newPath, "/"); + strcat(newPath, aLeafName); + mPath = newPath; + InvalidateCache(); + nsAllocator::Free(newPath); + return NS_OK; +} + +NS_IMETHODIMP +nsLocalFile::GetPath(char **_retval) { NS_ENSURE_ARG_POINTER(_retval); @@ -243,9 +454,6 @@ nsLocalFile::GetPath(PRUint32 pathType, char **_retval) return NS_OK; } - NS_ASSERTION(pathType == NATIVE_PATH || - pathType == UNIX_PATH || - pathType == NSPR_PATH, "unrecognized path type"); *_retval = nsCRT::strdup((const char *)mPath); if (!*_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -255,7 +463,204 @@ nsLocalFile::GetPath(PRUint32 pathType, char **_retval) NS_IMETHODIMP nsLocalFile::CopyTo(nsIFile *newParent, const char *newName) { - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv; + + // check to make sure that we have a new parent + // or have a new name + if (newParent == nsnull && newName == nsnull) + return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST; + + // check to make sure that this has been initialized properly + CHECK_mPath(); + + // check to see if we are a directory or if we are a file + PRBool isDirectory; + IsDirectory(&isDirectory); + + if (isDirectory) + { + // XXX + return NS_ERROR_NOT_IMPLEMENTED; + } + else + { + // ok, we're a file so this should be easy as pie. + // check to see if our target exists + PRBool targetExists; + newParent->Exists(&targetExists); + // check to see if we need to create it + if (targetExists == PR_FALSE) + { + // XXX create the new directory with some permissions + rv = newParent->Create(DIRECTORY_TYPE, 0755); + if (NS_FAILED(rv)) + return rv; + } + // make sure that the target is actually a directory + PRBool targetIsDirectory; + newParent->IsDirectory(&targetIsDirectory); + if (targetIsDirectory == PR_FALSE) + return NS_ERROR_FILE_DESTINATION_NOT_DIR; + // ok, we got this far. create the name of the new file. + nsXPIDLCString leafName; + nsXPIDLCString newPath; + const char *tmpConstChar; + char *tmpChar; + // get the leaf name of the new file if a name isn't supplied. + if (newName == nsnull) + { + if (NS_FAILED(rv = GetLeafNameRaw(&tmpConstChar))) + return rv; + leafName = tmpConstChar; + } + else + { + leafName = newName; + } + // get the path name + if (NS_FAILED(rv = newParent->GetPath(&tmpChar))) + return rv; + + // this is the full path to the dir of the new file + newPath = tmpChar; + nsAllocator::Free(tmpChar); + + // create the final name + char *newPathName; + newPathName = (char *)nsAllocator::Alloc(strlen(newPath) + strlen(leafName) + 2); + if (!newPathName) + return NS_ERROR_OUT_OF_MEMORY; + + strcpy(newPathName, newPath); + strcat(newPathName, "/"); + strcat(newPathName, leafName); + +#ifdef DEBUG_blizzard + printf("nsLocalFile::CopyTo() %s -> %s\n", (const char *)mPath, newPathName); +#endif + + nsXPIDLCString newPathNameAuto; + newPathNameAuto = newPathName; + nsAllocator::Free(newPathName); + + // actually create the file. + + nsLocalFile *newFile = new nsLocalFile(); + newFile->AddRef(); // we own this. + if (newFile == nsnull) + { + return NS_ERROR_OUT_OF_MEMORY; + } + + rv = newFile->InitWithPath(newPathNameAuto); + + if (NS_FAILED(rv)) + { + NS_RELEASE(newFile); + return rv; + } + + // get the old permissions + PRUint32 myPerms; + GetPermissions(&myPerms); + // create the new file with the same permissions + rv = newFile->Create(NORMAL_FILE_TYPE, myPerms); + if (NS_FAILED(rv)) + { + NS_RELEASE(newFile); + return rv; + } + + // open the new file. + + PRInt32 openFlags = PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE; + PRInt32 modeFlags = myPerms; + PRFileDesc *newFD = nsnull; + + rv = newFile->OpenNSPRFileDesc(openFlags, modeFlags, &newFD); + if (NS_FAILED(rv)) + { + NS_RELEASE(newFile); + return rv; + } + if (newFD == nsnull) + { + NS_RELEASE(newFile); + NSRESULT_FOR_ERRNO(); + } + + // open the old file, too + + openFlags = PR_RDONLY; + PRFileDesc *oldFD = nsnull; + + rv = OpenNSPRFileDesc(openFlags, modeFlags, &oldFD); + // make sure to clean up properly + if (NS_FAILED(rv)) + { + NS_RELEASE(newFile); + PR_Close(newFD); + return rv; + } + if (newFD == nsnull) + { + NS_RELEASE(newFile); + PR_Close(newFD); + NSRESULT_FOR_ERRNO(); + } + + // get the length of the file + + PRStatus status; + PRFileInfo fileInfo; + status = PR_GetFileInfo(mPath, &fileInfo); + if (status != PR_SUCCESS) + { + NS_RELEASE(newFile); + PR_Close(newFD); + NSRESULT_FOR_ERRNO(); + } + + // get the size of the file. + + PROffset32 fileSize; + fileSize = fileInfo.size; + PRInt32 bytesRead = 0; + PRInt32 bytesWritten = 0; + PRInt32 totalRead = 0; + PRInt32 totalWritten = 0; + + char buf[BUFSIZ]; + + while(1) + { + bytesRead = PR_Read(oldFD, &buf, BUFSIZ); + if (bytesRead == 0) + break; + if (bytesRead == -1) + return NS_ERROR_FAILURE; + totalRead += bytesRead; + bytesWritten = PR_Write(newFD, &buf, bytesRead); + if (bytesWritten == -1) + return NS_ERROR_FAILURE; + totalWritten += bytesWritten; + } + +#ifdef DEBUG_blizzard + printf("read %d bytes, wrote %d bytes\n", + totalRead, totalWritten); +#endif + + // close the files + PR_Close(newFD); + PR_Close(oldFD); + + // free our resources + NS_RELEASE(newFile); + + } + + return rv; } NS_IMETHODIMP @@ -270,37 +675,37 @@ nsLocalFile::MoveTo(nsIFile *newParent, const char *newName) return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -nsLocalFile::MoveToFollowingLinks(nsIFile *newParent, const char *newName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsLocalFile::Execute(const char *args) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsLocalFile::Delete(PRBool recursive) { - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); PRBool isDir = S_ISDIR(mCachedStat.st_mode); /* XXX ? * if (!isDir && recursive) * return NS_ERROR_INVALID_ARG; */ - invalidateCache(); + InvalidateCache(); if (isDir) { if (recursive) { - nsCOMPtr iterator; - nsresult rv = NS_NewDirectoryEnumerator(this, PR_FALSE, - getter_AddRefs(iterator)); - if (NS_FAILED(rv)) + nsDirEnumeratorUnix *dir = new nsDirEnumeratorUnix(); + if (!dir) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = dir->Init(this, PR_FALSE); + if (NS_FAILED(rv)) { + delete dir; return rv; + } + + nsCOMPtr iterator; + iterator = do_QueryInterface(dir, &rv); + if (NS_FAILED(rv)) { + delete dir; + return rv; + } + PRBool more; rv = iterator->HasMoreElements(&more); while (NS_SUCCEEDED(rv) && more) { @@ -329,39 +734,41 @@ nsLocalFile::Delete(PRBool recursive) } NS_IMETHODIMP -nsLocalFile::GetLastModificationDate(PRUint32 *aLastModificationDate) +nsLocalFile::GetLastModificationDate(PRInt64 *aLastModificationDate) { NS_ENSURE_ARG(aLastModificationDate); - FILL_STAT_CACHE(); - *aLastModificationDate = (PRUint32)mCachedStat.st_mtime; + VALIDATE_STAT_CACHE(); + mLL_II2L(0, (PRUint32)mCachedStat.st_mtime, *aLastModificationDate); return NS_OK; } NS_IMETHODIMP -nsLocalFile::SetLastModificationDate(PRUint32 aLastModificationDate) +nsLocalFile::SetLastModificationDate(PRInt64 aLastModificationDate) { int result; if (aLastModificationDate) { - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); struct utimbuf ut; ut.actime = mCachedStat.st_atime; - ut.modtime = (time_t)aLastModificationDate; + PRInt32 hi, lo; + mLL_L2II(aLastModificationDate, hi, lo); + ut.modtime = (time_t)lo; result = utime(mPath, &ut); } else { result = utime(mPath, NULL); } - invalidateCache(); + InvalidateCache(); return NSRESULT_FOR_RETURN(result); } NS_IMETHODIMP -nsLocalFile::GetLastModificationDateOfLink(PRUint32 *aLastModificationDateOfLink) +nsLocalFile::GetLastModificationDateOfLink(PRInt64 *aLastModificationDateOfLink) { NS_ENSURE_ARG(aLastModificationDateOfLink); struct stat sbuf; if (lstat(mPath, &sbuf) == -1) return NSRESULT_FOR_ERRNO(); - *aLastModificationDateOfLink = (PRUint32)sbuf.st_mtime; + mLL_II2L(0, (PRUint32)sbuf.st_mtime, *aLastModificationDateOfLink); return NS_OK; } @@ -369,7 +776,7 @@ nsLocalFile::GetLastModificationDateOfLink(PRUint32 *aLastModificationDateOfLink * utime(2) may or may not dereference symlinks, joy. */ NS_IMETHODIMP -nsLocalFile::SetLastModificationDateOfLink(PRUint32 aLastModificationDateOfLink) +nsLocalFile::SetLastModificationDateOfLink(PRInt64 aLastModificationDateOfLink) { return SetLastModificationDate(aLastModificationDateOfLink); } @@ -384,7 +791,7 @@ NS_IMETHODIMP nsLocalFile::GetPermissions(PRUint32 *aPermissions) { NS_ENSURE_ARG(aPermissions); - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); *aPermissions = NORMALIZE_PERMS(mCachedStat.st_mode); return NS_OK; } @@ -403,7 +810,7 @@ nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink) NS_IMETHODIMP nsLocalFile::SetPermissions(PRUint32 aPermissions) { - invalidateCache(); + InvalidateCache(); return NSRESULT_FOR_RETURN(chmod(mPath, aPermissions)); } @@ -414,28 +821,35 @@ nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissions) } NS_IMETHODIMP -nsLocalFile::GetFileSize(PRUint32 *aFileSize) +nsLocalFile::GetFileSize(PRInt64 *aFileSize) { NS_ENSURE_ARG_POINTER(aFileSize); - FILL_STAT_CACHE(); - if (sizeof(off_t) > 4 && mCachedStat.st_size > (off_t)0xffffffff) - *aFileSize = 0xffffffff; // return error code? - else - *aFileSize = (PRUint32)mCachedStat.st_size; + InvalidateCache(); + /* XXX autoconf for and use stat64 if available */ + mLL_II2L(0, (PRUint32)mCachedStat.st_size, *aFileSize); return NS_OK; } NS_IMETHODIMP -nsLocalFile::GetFileSizeOfLink(PRUint32 *aFileSize) +nsLocalFile::SetFileSize(PRInt64 aFileSize) +{ + PRInt32 hi, lo; + mLL_L2II(aFileSize, hi, lo); + /* XXX truncate64? */ + if (truncate((const char *)mPath, (off_t)lo) == -1) + return NSRESULT_FOR_ERRNO(); + return NS_OK; +} + +NS_IMETHODIMP +nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSize) { NS_ENSURE_ARG(aFileSize); struct stat sbuf; if (lstat(mPath, &sbuf) == -1) return NSRESULT_FOR_ERRNO(); - if (sizeof(off_t) > 4 && mCachedStat.st_size > (off_t)0xffffffff) - *aFileSize = 0xffffffff; // return error code? - else - *aFileSize = (PRUint32)sbuf.st_size; + /* XXX autoconf for and use lstat64 if available */ + mLL_II2L(0, (PRInt32)sbuf.st_size, *aFileSize); return NS_OK; } @@ -505,7 +919,7 @@ NS_IMETHODIMP nsLocalFile::IsDirectory(PRBool *_retval) { NS_ENSURE_ARG_POINTER(_retval); - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); *_retval = S_ISDIR(mCachedStat.st_mode); return NS_OK; } @@ -514,7 +928,7 @@ NS_IMETHODIMP nsLocalFile::IsFile(PRBool *_retval) { NS_ENSURE_ARG_POINTER(_retval); - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); *_retval = S_ISREG(mCachedStat.st_mode); return NS_OK; } @@ -525,7 +939,7 @@ nsLocalFile::IsHidden(PRBool *_retval) NS_ENSURE_ARG_POINTER(_retval); nsresult rv; const char *leafName; - if (NS_FAILED(rv = getLeafNameRaw(&leafName))) + if (NS_FAILED(rv = GetLeafNameRaw(&leafName))) return rv; *_retval = (leafName[0] == '.'); return NS_OK; @@ -535,7 +949,7 @@ NS_IMETHODIMP nsLocalFile::IsSymlink(PRBool *_retval) { NS_ENSURE_ARG_POINTER(_retval); - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); *_retval = S_ISLNK(mCachedStat.st_mode); return NS_OK; } @@ -544,7 +958,7 @@ NS_IMETHODIMP nsLocalFile::IsSpecial(PRBool *_retval) { NS_ENSURE_ARG_POINTER(_retval); - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); *_retval = !(S_ISLNK(mCachedStat.st_mode) || S_ISREG(mCachedStat.st_mode) || S_ISDIR(mCachedStat.st_mode)); return NS_OK; @@ -555,7 +969,18 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) { NS_ENSURE_ARG(inFile); NS_ENSURE_ARG_POINTER(_retval); - return NS_ERROR_NOT_IMPLEMENTED; + *_retval = PR_FALSE; + + nsresult rv; + nsXPIDLCString myPath, inPath; + + if (NS_FAILED(rv = GetPath(getter_Copies(myPath)))) + return rv; + if (NS_FAILED(rv = inFile->GetPath(getter_Copies(inPath)))) + return rv; + *_retval = !strcmp(inPath, myPath); + + return NS_OK; } NS_IMETHODIMP @@ -563,32 +988,62 @@ nsLocalFile::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) { NS_ENSURE_ARG(inFile); NS_ENSURE_ARG_POINTER(_retval); - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP -nsLocalFile::Truncate(PRUint32 aLength) -{ - return NSRESULT_FOR_RETURN(truncate(mPath, (off_t)aLength)); + nsXPIDLCString inPath; + nsresult rv; + + if (NS_FAILED(rv = inFile->GetPath(getter_Copies(inPath)))) + return rv; + + ssize_t inLen = strlen(inPath); + + /* remove trailing slashes */ + while (((const char *)mPath)[inLen - 1] == '/') + inLen--; + + /* + * See if the given path is a prefix of our path, but make sure that + * we don't treat /foo as a parent of /foobar/thing. + */ + if (strncmp(inPath, mPath, inLen) || ((const char *)mPath)[inLen] != '/') { + *_retval = PR_FALSE; + return NS_OK; + } + if (recur) { + /* good enough -- don't need to check for direct parentage */ + *_retval = PR_TRUE; + return NS_OK; + } + + const char *parentEnd = strrchr(mPath, '/'); + if (inLen == (parentEnd - (const char *)mPath)) { + *_retval = PR_TRUE; + return NS_OK; + } + + *_retval = PR_FALSE; + return NS_OK; } NS_IMETHODIMP nsLocalFile::GetTarget(char **_retval) { NS_ENSURE_ARG_POINTER(_retval); - FILL_STAT_CACHE(); + VALIDATE_STAT_CACHE(); if (!S_ISLNK(mCachedStat.st_mode)) return NS_ERROR_FILE_INVALID_PATH; - PRUint32 targetSize; - if (NS_FAILED(GetFileSizeOfLink(&targetSize))) + PRInt64 targetSize64; + if (NS_FAILED(GetFileSizeOfLink(&targetSize64))) return NS_ERROR_FAILURE; - char *target = (char *)nsAllocator::Alloc(targetSize); + PRInt32 hi, lo; + mLL_L2II(targetSize64, hi, lo); + char *target = (char *)nsAllocator::Alloc(lo); if (!target) return NS_ERROR_OUT_OF_MEMORY; - int result = readlink(mPath, target, (size_t)targetSize); + int result = readlink(mPath, target, (size_t)lo); if (!result) { *_retval = target; return NS_OK; @@ -596,3 +1051,54 @@ nsLocalFile::GetTarget(char **_retval) nsAllocator::Free(target); return NSRESULT_FOR_ERRNO(); } + +NS_IMETHODIMP +nsLocalFile::Spawn(const char *args) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries) +{ + nsDirEnumeratorUnix *dir = new nsDirEnumeratorUnix(); + if (!dir) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = dir->Init(this, PR_FALSE); + if (NS_FAILED(rv)) { + delete dir; + return rv; + } + + /* QI needed? */ + return dir->QueryInterface(NS_GET_IID(nsISimpleEnumerator), + (void **)entries); +} + +NS_IMETHODIMP +nsLocalFile::Load(PRLibrary **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + *_retval = PR_LoadLibrary(mPath); + if (!*_retval) + return NS_ERROR_FAILURE; + return NS_OK; +} + +NS_COM nsresult +NS_NewLocalFile(const char* path, nsILocalFile* *result) +{ + nsLocalFile* file = new nsLocalFile(); + if (file == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(file); + + nsresult rv = file->InitWithPath(path); + if (NS_FAILED(rv)) { + NS_RELEASE(file); + return rv; + } + *result = file; + return NS_OK; +} diff --git a/mozilla/xpcom/io/nsLocalFileUnix.h b/mozilla/xpcom/io/nsLocalFileUnix.h index 9c5b307b86f..c9375cef187 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.h +++ b/mozilla/xpcom/io/nsLocalFileUnix.h @@ -34,6 +34,7 @@ #include "nscore.h" #include "nsIFile.h" +#include "nsILocalFile.h" #include "nsLocalFile.h" #include "nsXPIDLString.h" @@ -65,7 +66,7 @@ nsresultForErrno(int err) #define NSRESULT_FOR_ERRNO() nsresultForErrno(errno) -class NS_COM nsLocalFile : public nsIFile +class NS_COM nsLocalFile : public nsILocalFile { public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID) @@ -73,7 +74,7 @@ public: nsLocalFile(); virtual ~nsLocalFile(); - static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); + static NS_METHOD nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); // nsISupports NS_DECL_ISUPPORTS @@ -81,17 +82,20 @@ public: // nsIFile NS_DECL_NSIFILE + // nsILocalFile + NS_DECL_NSILOCALFILE + protected: PRBool mHaveCachedStat; struct stat mCachedStat; nsXPIDLCString mPath; - nsresult createAllParentDirectories(PRUint32 permissions); - nsresult getLeafNameRaw(const char **_retval); + nsresult CreateAllAncestors(PRUint32 permissions); + nsresult GetLeafNameRaw(const char **_retval); - void invalidateCache() { mHaveCachedStat = PR_FALSE; } + void InvalidateCache() { mHaveCachedStat = PR_FALSE; } - nsresult fillStatCache() { + nsresult FillStatCache() { if (stat(mPath, &mCachedStat) == -1) { #ifdef DEBUG_shaver fprintf(stderr, "stat(%s) -> %d\n", (const char *)mPath, errno); diff --git a/mozilla/xpcom/io/nsLocalFileWin.cpp b/mozilla/xpcom/io/nsLocalFileWin.cpp index 3fc3a8e4d9b..91e932cb9ab 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.cpp +++ b/mozilla/xpcom/io/nsLocalFileWin.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -39,6 +39,7 @@ #include "shellapi.h" #include "shlguid.h" +#include // certainly not all the error that can be // encountered, but many of them common ones @@ -171,10 +172,18 @@ class nsDirEnumerator : public nsISimpleEnumerator nsCOMPtr file; mParent->Clone(getter_AddRefs(file)); - rv = file->AppendPath(entry->name); + rv = file->Append(entry->name); if (NS_FAILED(rv)) return rv; - + + // make sure the thing exists. If it does, try the next one. + PRBool exists; + rv = file->Exists(&exists); + if (NS_FAILED(rv) || !exists) + { + return HasMoreElements(result); + } + mNext = do_QueryInterface(file); } *result = mNext != nsnull; @@ -216,24 +225,20 @@ NS_IMPL_ISUPPORTS(nsDirEnumerator, NS_GET_IID(nsISimpleEnumerator)); nsLocalFile::nsLocalFile() { NS_INIT_REFCNT(); - CoInitialize(NULL); // FIX: we should probably move somewhere higher up during startup - - HRESULT hres; - - - // Get a pointer to the IShellLink interface. - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&mShellLink); - if (SUCCEEDED(hres)) - { - // Get a pointer to the IPersistFile interface. - hres = mShellLink->QueryInterface(IID_IPersistFile, (void**)&mPersistFile); - } + + mPersistFile = nsnull; + mShellLink = nsnull; MakeDirty(); } nsLocalFile::~nsLocalFile() { + PRBool uninitCOM = PR_FALSE; + if (mPersistFile || mShellLink) + { + uninitCOM = PR_TRUE; + } // Release the pointer to the IPersistFile interface. if (mPersistFile) mPersistFile->Release(); @@ -242,16 +247,18 @@ nsLocalFile::~nsLocalFile() if(mShellLink) mShellLink->Release(); - CoUninitialize(); + if (uninitCOM) + CoUninitialize(); } /* nsISupports interface implementation. */ NS_IMPL_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile) + NS_METHOD -nsLocalFile::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) +nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); - NS_ENSURE_PROPER_AGGREGATION(outer, aIID); + NS_ENSURE_NO_AGGREGATION(outer); nsLocalFile* inst = new nsLocalFile(); if (inst == NULL) @@ -270,7 +277,7 @@ nsLocalFile::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) void nsLocalFile::MakeDirty() { - mStatDirty = PR_TRUE; + mDirty = PR_TRUE; } //---------------------------------------------------------------------------------------- @@ -285,11 +292,27 @@ nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char** { nsresult rv = NS_OK; - - // Make sure that we were able to get the PersistFile interface during the - // construction of this object. if (mPersistFile == nsnull || mShellLink == nsnull) - return NS_ERROR_FILE_INVALID_PATH; + { + CoInitialize(NULL); // FIX: we should probably move somewhere higher up during startup + + HRESULT hres; + + // FIX. This should be in a service. + // Get a pointer to the IShellLink interface. + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&mShellLink); + if (SUCCEEDED(hres)) + { + // Get a pointer to the IPersistFile interface. + hres = mShellLink->QueryInterface(IID_IPersistFile, (void**)&mPersistFile); + } + + if (mPersistFile == nsnull || mShellLink == nsnull) + { + return NS_ERROR_FILE_INVALID_PATH; + } + } + // Get the native path for |this| char* filePath = (char*) nsAllocator::Clone( workingPath, strlen(workingPath)+1 ); @@ -309,7 +332,7 @@ nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char** if (slash == nsnull) { - if (filePath[1] == ':' && filePath[2] == '\0') + if (filePath[0] != nsnull && filePath[1] == ':' && filePath[2] == '\0') { // we have a drive letter and a colon (eg 'c:' // this is resolve already @@ -464,30 +487,51 @@ nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char** nsresult nsLocalFile::ResolveAndStat(PRBool resolveTerminal) { -// if (!mStatDirty) -// { -// return NS_OK; todo need to cache information about both the path and the target both -// follow this code path. -// } + if (!mDirty) + { + return NS_OK; + } - char *resolvePath; - nsresult rv = ResolvePath(mWorkingPath.GetBuffer(), resolveTerminal, &resolvePath); - if (NS_FAILED(rv)) - return rv; - mResolvedPath.SetString(resolvePath); - nsAllocator::Free(resolvePath); - - - const char *filePath = mResolvedPath.GetBuffer(); + const char *workingFilePath = mWorkingPath.GetBuffer(); BOOL result; - result = GetFileAttributesEx( filePath, GetFileExInfoStandard, &mFileAttrData); - if ( 0 == result ) + + // First we will see if the workingPath exists. If it does, then we + // can simply use that as the resolved path. This simplification can + // be done on windows cause its symlinks (shortcuts) use the .lnk + // file extension. + + // We are going to be checking the last error. + // Lets make sure that we clear it first. + + SetLastError(0); + + result = GetFileAttributesEx( workingFilePath, GetFileExInfoStandard, &mFileAttrData); + + if ( 0 != result ) { + mResolvedPath.SetString(workingFilePath); + } + else + { + // okay, something is wrong with the working path. We will try to resolve it. + + char *resolvePath; + nsresult rv = ResolvePath(workingFilePath, resolveTerminal, &resolvePath); + if (NS_FAILED(rv)) + return rv; + mResolvedPath.SetString(resolvePath); + nsAllocator::Free(resolvePath); + + // if we are not resolving the terminal node, we have to "fake" windows + // out and append the ".lnk" file extension before getting any information + // about the shortcut. If resoveTerminal was TRUE, than it the shortcut was + // resolved by the call to ResolvePath above. + if (resolveTerminal == false) { char linkStr[MAX_PATH]; - strcpy(linkStr, filePath); + strcpy(linkStr, mResolvedPath.GetBuffer()); strcat(linkStr, ".lnk"); result = GetFileAttributesEx( linkStr, GetFileExInfoStandard, &mFileAttrData); @@ -499,38 +543,28 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) return ConvertWinError(GetLastError()); } - mStatDirty = PR_FALSE; + mDirty = PR_FALSE; return NS_OK; } NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { - NS_ENSURE_ARG(file); - *file = nsnull; - - nsCOMPtr localFile; - nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, - nsnull, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(localFile)); - if (NS_FAILED(rv)) - return rv; - - char* aFilePath; + nsresult rv; + char * aFilePath; GetPath(&aFilePath); - rv = localFile->InitWithPath(aFilePath); - + nsCOMPtr localFile; + + rv = NS_NewLocalFile(aFilePath, getter_AddRefs(localFile)); nsAllocator::Free(aFilePath); - if (NS_FAILED(rv)) - return rv; - - *file = localFile; - NS_ADDREF(*file); - - return NS_OK; + if (NS_SUCCEEDED(rv) && localFile) + { + return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)file); + } + + return rv; } NS_IMETHODIMP @@ -544,7 +578,7 @@ nsLocalFile::InitWithPath(const char *filePath) // just do a sanity check. if it has any forward slashes, it is not a Native path // on windows. Also, it must have a colon at after the first char. - if ( ( (filePath[1] == ':') && ( strchr(filePath, '/') == 0) ) || // normal windows path + if ( ( (filePath[0] != 0) && (filePath[1] == ':') && (strchr(filePath, '/') == 0) ) || // normal windows path ( (filePath[0] == '\\') && (filePath[1] == '\\') ) ) // netwerk path { // This is a native path @@ -566,7 +600,7 @@ nsLocalFile::InitWithPath(const char *filePath) } NS_IMETHODIMP -nsLocalFile::Open(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) +nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) { nsresult rv = ResolveAndStat(PR_TRUE); if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) @@ -574,6 +608,22 @@ nsLocalFile::Open(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) *_retval = PR_Open(mResolvedPath, flags, mode); + if (*_retval) + return NS_OK; + + return NS_ErrorAccordingToNSPR(); +} + + +NS_IMETHODIMP +nsLocalFile::OpenANSIFileDesc(const char *mode, FILE * *_retval) +{ + nsresult rv = ResolveAndStat(PR_TRUE); + if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) + return rv; + + *_retval = fopen(mResolvedPath, mode); + if (*_retval) return NS_OK; @@ -627,40 +677,19 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) } NS_IMETHODIMP -nsLocalFile::AppendPath(const char *node) +nsLocalFile::Append(const char *node) { - if ( (node == nsnull) || (*node == '/') || strchr(node, '\\') ) + if ( (node == nsnull) || + (*node == '/') || + (*node == '.') || + strchr(node, '\\') || + strchr(node, '/') ) + { return NS_ERROR_FILE_UNRECOGNIZED_PATH; - + } MakeDirty(); - - // We only can append relative unix styles strings. - - // Convert '\' to '/' - nsString path(node); - - char* nodeCString = path.ToNewCString(); - char* temp = nodeCString; - for (; *temp; temp++) - { - if (*temp == '/') - *temp = '\\'; - } - - // kill any trailing seperator - if(nodeCString) - { - temp = nodeCString; - int len = strlen(temp) - 1; - if(temp[len] == '\\') - temp[len] = '\0'; - } - mWorkingPath.Append("\\"); - mWorkingPath.Append(nodeCString); - - Recycle(nodeCString); - + mWorkingPath.Append(node); return NS_OK; } @@ -691,6 +720,27 @@ nsLocalFile::GetLeafName(char * *aLeafName) return NS_OK; } +NS_IMETHODIMP +nsLocalFile::SetLeafName(const char * aLeafName) +{ + MakeDirty(); + + const char* temp = mWorkingPath.GetBuffer(); + if(temp == nsnull) + return NS_ERROR_FILE_UNRECOGNIZED_PATH; + + const char* leaf = strrchr(temp, '\\'); + + PRInt32 offset = mWorkingPath.RFindChar('\\'); + if (offset) + { + mWorkingPath.Truncate(offset+1); + } + mWorkingPath.Append(aLeafName); + + return NS_OK; +} + NS_IMETHODIMP nsLocalFile::GetPath(char **_retval) @@ -745,6 +795,11 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char return rv; int copyOK; + + // We are going to be checking the last error. + // Lets make sure that we clear it first. + + SetLastError(0); if (!move) copyOK = CopyFile(filePath, destPath, PR_TRUE); @@ -797,14 +852,9 @@ nsLocalFile::CopyMove(nsIFile *newParentDir, const char *newName, PRBool followS char* target; newParentDir->GetTarget(&target); - nsCOMPtr realDest; - - rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, - nsnull, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(realDest)); - if (NS_FAILED(rv)) - return rv; + nsCOMPtr realDest = new nsLocalFile(); + if (realDest == nsnull) + return NS_ERROR_OUT_OF_MEMORY; rv = realDest->InitWithPath(target); @@ -869,7 +919,7 @@ nsLocalFile::CopyMove(nsIFile *newParentDir, const char *newName, PRBool followS allocatedNewName = (char*) nsAllocator::Clone( newName, strlen(newName)+1 ); } - rv = target->AppendPath(allocatedNewName); + rv = target->Append(allocatedNewName); if (NS_FAILED(rv)) return rv; @@ -938,12 +988,12 @@ nsLocalFile::CopyMove(nsIFile *newParentDir, const char *newName, PRBool followS char *aFileName; GetLeafName(&aFileName); - AppendPath(aFileName); + Append(aFileName); nsAllocator::Free(aFileName); } else { - AppendPath(newName); + SetLeafName(newName); } nsAllocator::Free(newParentPath); @@ -1017,8 +1067,6 @@ nsLocalFile::Load(PRLibrary * *_retval) NS_IMETHODIMP nsLocalFile::Delete(PRBool recursive) { - MakeDirty(); - PRBool isDir; nsresult rv = IsDirectory(&isDir); @@ -1060,6 +1108,7 @@ nsLocalFile::Delete(PRBool recursive) remove(filePath); // todo: save return value? } + MakeDirty(); return NS_OK; } @@ -1075,8 +1124,8 @@ nsLocalFile::GetLastModificationDate(PRInt64 *aLastModificationDate) if (NS_FAILED(rv)) return rv; - PRUint32 high = mFileAttrData.ftLastAccessTime.dwHighDateTime; - PRUint32 low = mFileAttrData.ftLastAccessTime.dwLowDateTime; + PRUint32 high = mFileAttrData.ftLastWriteTime.dwHighDateTime; + PRUint32 low = mFileAttrData.ftLastWriteTime.dwLowDateTime; myLL_II2L(high, low, aLastModificationDate); @@ -1086,14 +1135,12 @@ nsLocalFile::GetLastModificationDate(PRInt64 *aLastModificationDate) NS_IMETHODIMP nsLocalFile::SetLastModificationDate(PRInt64 aLastModificationDate) { - MakeDirty(); - nsresult rv = ResolveAndStat(PR_TRUE); if (NS_FAILED(rv)) return rv; - FILETIME time = mFileAttrData.ftLastAccessTime; + FILETIME time = mFileAttrData.ftLastWriteTime; PRInt32 hi, lo; myLL_L2II(aLastModificationDate, &hi, &lo ); @@ -1114,12 +1161,14 @@ nsLocalFile::SetLastModificationDate(PRInt64 aLastModificationDate) if (!file) { // could not open file for writing. + MakeDirty(); return NS_ERROR_FAILURE; //TODO better error code } if ( 0 == SetFileTime(file, NULL, &time, &time) ) { // could not set time + MakeDirty(); return NS_ERROR_FAILURE; } @@ -1142,7 +1191,7 @@ nsLocalFile::GetLastModificationDateOfLink(PRInt64 *aLastModificationDate) if (NS_FAILED(rv)) return rv; - FILETIME time = mFileAttrData.ftLastAccessTime; + FILETIME time = mFileAttrData.ftLastWriteTime; myLL_II2L(time.dwHighDateTime, time.dwLowDateTime, aLastModificationDate); @@ -1152,8 +1201,6 @@ nsLocalFile::GetLastModificationDateOfLink(PRInt64 *aLastModificationDate) NS_IMETHODIMP nsLocalFile::SetLastModificationDateOfLink(PRInt64 aLastModificationDate) { - MakeDirty(); - nsresult rv = ResolveAndStat(PR_FALSE); if (NS_FAILED(rv)) @@ -1162,7 +1209,7 @@ nsLocalFile::SetLastModificationDateOfLink(PRInt64 aLastModificationDate) PRInt32 hi, lo; myLL_L2II(aLastModificationDate, &hi, &lo ); - FILETIME time = mFileAttrData.ftLastAccessTime; + FILETIME time = mFileAttrData.ftLastWriteTime; time.dwHighDateTime = hi; time.dwLowDateTime = lo; @@ -1180,12 +1227,14 @@ nsLocalFile::SetLastModificationDateOfLink(PRInt64 aLastModificationDate) if (!file) { // could not open file for writing. + MakeDirty(); return NS_ERROR_FAILURE; //TODO better error code } if ( 0 == SetFileTime(file, NULL, &time, &time) ) { // could not set time + MakeDirty(); return NS_ERROR_FAILURE; } @@ -1266,7 +1315,10 @@ nsLocalFile::SetFileSize(PRInt64 aFileSize) NULL); if (hFile == INVALID_HANDLE_VALUE) + { + MakeDirty(); return NS_ERROR_FAILURE; + } // Seek to new, desired end of file PRInt32 hi, lo; @@ -1283,9 +1335,11 @@ nsLocalFile::SetFileSize(PRInt64 aFileSize) if (!CloseHandle(hFile)) return NS_ERROR_FAILURE; + MakeDirty(); return NS_OK; error: + MakeDirty(); CloseHandle(hFile); return NS_ERROR_FAILURE; } @@ -1376,23 +1430,21 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentPath.Truncate(offset); - const char* filePath = parentPath.GetBuffer(); - - nsLocalFile* file = new nsLocalFile(); - if (file == nsnull) - return NS_ERROR_OUT_OF_MEMORY; + nsCOMPtr localFile; + nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile)); - file->AddRef(); - file->InitWithPath(filePath); - *aParent = file; - - return NS_OK; + if(NS_SUCCEEDED(rv) && localFile) + { + return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent); + } + return rv; } + NS_IMETHODIMP nsLocalFile::Exists(PRBool *_retval) { NS_ENSURE_ARG(_retval); - + nsresult rv = ResolveAndStat( PR_TRUE ); if (NS_SUCCEEDED(rv)) @@ -1424,8 +1476,6 @@ nsLocalFile::IsWritable(PRBool *_retval) *_retval = (PRBool) !( mFileAttrData.dwFileAttributes & FILE_ATTRIBUTE_READONLY); return NS_OK; - - } NS_IMETHODIMP @@ -1597,45 +1647,34 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) NS_IMETHODIMP nsLocalFile::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) { - nsresult rv = NS_OK; - nsCOMPtr iter = this; - nsCOMPtr parent; - *_retval = PR_FALSE; - char* inFilePath; - inFile->GetPath(&inFilePath); - PRInt32 inFilePathLen = strlen(inFilePath); + char* myFilePath; + if ( NS_FAILED(GetTarget(&myFilePath))) + GetPath(&myFilePath); - if (inFilePathLen > 257) - return NS_ERROR_FAILURE; + PRInt32 myFilePathLen = strlen(myFilePath); + + char* inFilePath; + if ( NS_FAILED(inFile->GetTarget(&inFilePath))) + inFile->GetPath(&inFilePath); - while (1) + if ( strncmp( myFilePath, inFilePath, myFilePathLen) == 0) { - char* iterPath; - iter->GetPath(&iterPath); + // now make sure that the |inFile|'s path has a trailing + // separator. - if ( strncmp( inFilePath, iterPath, inFilePathLen) == 0) + if (inFilePath[myFilePathLen] == '\\') { - nsAllocator::Free(iterPath); - *_retval = PR_FALSE; - break; + *_retval = PR_TRUE; } - nsAllocator::Free(iterPath); - - rv = iter->GetParent(getter_AddRefs(parent)); - if (NS_FAILED(rv)) - { - break; - } - - iter = parent; } - + nsAllocator::Free(inFilePath); + nsAllocator::Free(myFilePath); - return rv; + return NS_OK; } @@ -1694,5 +1733,24 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) } +NS_COM nsresult +NS_NewLocalFile(const char* path, nsILocalFile* *result) +{ + nsLocalFile* file = new nsLocalFile(); + if (file == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(file); + + nsresult rv = file->InitWithPath(path); + if (NS_FAILED(rv)) { + NS_RELEASE(file); + return rv; + } + *result = file; + return NS_OK; +} + + + diff --git a/mozilla/xpcom/io/nsLocalFileWin.h b/mozilla/xpcom/io/nsLocalFileWin.h index e50e20c9976..8ca965d9a01 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.h +++ b/mozilla/xpcom/io/nsLocalFileWin.h @@ -55,7 +55,7 @@ public: nsLocalFile(); virtual ~nsLocalFile(); - static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); + static NS_METHOD nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); // nsISupports interface NS_DECL_ISUPPORTS @@ -69,7 +69,7 @@ public: private: // this is the flag which indicates if I can used cached information about the file - PRBool mStatDirty; + PRBool mDirty; // this string will alway be in native format! nsCString mWorkingPath; diff --git a/mozilla/xpcom/macbuild/XPCOMIDL.mcp b/mozilla/xpcom/macbuild/XPCOMIDL.mcp index 794644ee3f21dc14d6c268970ff5e6170c1d2ec8..961f7f1a062c28509ae20f93fe880eae8c8b6286 100644 GIT binary patch delta 1740 zcmai!Yiv|S6vt=o-t9gp-CKIQyIt7b+Sj&LN*@$xNmnXb7HOcSl@DlCC?%HkfwYmt z52f%)DfAOlVt6!m!_e9JR5zUMQ&Xe5NG!Zh z*>IY4v=HL%5H}C~L)kze5DOU&hQw>Zl~ioMvqSebwJfiwZ>YMygf{L+hT+_17g0y(TNXK~*eKdrLH$}h9#9e$c_&4n51>qw*9baAcIViEVA za9Bi1vW@oUn_9dL^@#mY8j)3|o5ESBX<~!dLD`C$gDgSJU{~EU#CVO(VDqy&9<+ap zn5c_dXq?zt|5%}zIvQ^k-V!erx4YvtS$g(YMk37+&P;=*R4lK2MxKf3XYM!JR^rsQ z(i740q5qrv6%LQg4@LF2vhI*+M@REzm&NTI-6F;gOutREs(=|Kb}{2~7Zulv9h$68 zw913*MBqJyX7X9F4saTiAb2CMZt-d^VBI ztF|)#pp!cB&Mr+Xy!75IF|Tc#pTAf@BfivA^3XQ6v~I?w`3-TW#TDTv3#i+dya*L; z2XA_m=iK7g3ux`!U5%{`%~*p%J&>deu(GkF{?R4gI^I@D-I_1T_Y~4R&8746@>z6? z-^J5cGKny@O`GdB5Iy&M#0aT~i>*9dgmuq_`066ea|Pgcs(DLgDdbs!B;DZqi>N1M z0(OGJwO_)PcLGwK%Lft0XF4$mEADEAJx@|X%m|;9d|waJxT1J*DS+Gp^3j_-Z$3S& zd7kD!%%{ufY91)YZX1DAGM0N|u*>9JL~G?MixDjw^(6x;nsyVmyq%Dbzu;|>*U0Ec z6c0TQyIfMN|BUxY-t{f6c)a3u`vI25Fmda6GoFkvN12Z$ly7 zCkcsD*%^_h`(LU58r_2otU2-8{ln-=R5Aho_58L90Yq;@eA8|kK~@y z7^|KbU9!DV#m!xOSn|NH7_U?758`pbWEQRNlVxOOWL9yau@8Q^d46IA>tH1M?z_sD8`Rk?hyMF;X)0>@JU83bnCND6|b!>0>KYEFWx}LQ~T6u#gxb zp^Y(yR3t9bc2JD9G*Y!dks*p-fcmAv2Q-l?ZDK8$MjH)PfyO>$J+rf^c9OaG%=w)& z^S@`#Zr{9O`o6+)xUum#LP$mkdlAmbMR6qOfA}sw#rp$fMd#q}-msvMRKgR9j++Azwu%do`@eSRk`k*KNeaf2jo{ zGGGZP)UYoZ?oB1rE*ClN%O+zsA9+66LmY($)||W(laMn>-LpM29PS=tudI6n(TO(U z7)S%h0}OjB$j=vJ@mjWW(S#ibf+gF^wOVaXj5f8V_DEertvmQaN!hLvvQqPwxUCdW z&=D%hf!A@ix@iq2zg;^>uKL!qKl2PK_RpwBVw1hwaVR*+uJopXeD4&AJ(9|9+|WtP zQz%3mv!y&) zW?y}(m7g5--37e_=joM9cg4u7)C7?~@_LVif_g#p`;KbayH`)@Nqe16sVhcE3kMn{ zcHw?^9GhDBGL}uaI~Dx?+3kfonSJ}sDQJ-?7HB`2q=8#g!L6kb_l%o4GrUTO8CEd+ zOpse63ObsOcSy^x)75lr%XOTDrae{P+yad+{~En*co}!Vt#NVK=x+YDK1qXd4-C$>lF!OC{@WD3rT2Q5maQWdf zFn^RU(jp(E^KgSm|9uzOIRbCc(FRDDp1DKc^x=NVl282^xXdvC*doFc_Jh4ygj*(Q zR|f1h4a=w)G6Z&!!13GZcm{~s6c1wTBK@@$V8w#lw$Me+UBAHEFL=*gu(t|ckU(9T zpeET$H)i5eDQ$_iXX0!bd#dRW0B3q0uYG+>Q!^y+pMP}3Ez?`TRUY7|vSG9H3(zy-D@^)DV4Z@8Z_;tjy;X3STI8QK1M3oeuZJ#j z{t@Iz3c>CDz@qUum{W{qE)?oNvrn~)+?l=YuQDakUE7)f^MaY^& z+c~%KB1PqGz6|y`P7%rv&>_w%0#Ax;T!ez7o(M*jW%L&3t`=B}A{+mH8|?Q4zw{S1 z1VCOPEWHu+#@R`*-xt``M~ec`cdpNALjbl(hQ^A1hUSm6V1Fp$YF6k6oPV+kGHyop S(eB#_tWWUEb95$vXa5D`^`|`m diff --git a/mozilla/xpcom/macbuild/xpcomPPC.mcp b/mozilla/xpcom/macbuild/xpcomPPC.mcp index f314a3d2f19f9a73c931a3847d7bd051c1c6db76..68c5cbca6cfb38e7e41b4063c5e5bc2ff4f219b2 100644 GIT binary patch delta 1904 zcmZ8i4NMeA6rMN7EgbBffQWcd;6PD8!EhB*u@tP*q9>j|sGuGJdeD=fJCAGYPr+6Z z6YAe(qN7c;#2-YZmS);)(nPCPZM6n-ZBmn}Xc}WpYpmLsw2Gl`cd^>OWOv`Z@BP1- z*@vNshoOkRY_KgSgscI40f7Vf-h@vVAqk%nlB7yE1&c?qYUl_@9Y7s+4>Cs>K_@gq z>3)_$cQU(F!yXvpN3TH98j3GU;IL|%Jpc}S3Vk!$a zI84Y7hu9@mpsP66YnE9<(%Kv3_qRU``35 zVXFje!Q|=aMP{}6Z?gPCYk2Qq8zE!b(9079i{e$m(9ng6DEJ%Lh+`{l_a)g|?`?KB z7}?H5xvHw(-CWh&Qo1nUcULz#JS_nxhrcQg6>O(s@$4unT0$n^Wuak>-|}9>2Rb;PtOr==Q(ssdX!L zi=fdUemnEK+1Q2UZ{#1GhEzOOupd_}=6t%OA3$ZtW#|dx(W@a{InfR->`5hVgb4gD z!g6Icr_?O^o;<>i%n&!$S4h~ar?JL4>Iqgp%!EG>h*A1t!I7!#bHTJE#d#V=T8sy^ zpw0`B9@ec#v_)uV6i1=PoMFUiRf6cd)ooU8t_5F-i2G@JlCtGGO!>cij_#wB&;#hq zG>}ubxhs*DSg+kCB=$~Iz}JWk#v>&wBeqn-iIH!$(a~cJMYtR; zJEUGn>YamRE&lY|>4gENBadB41zdVe5or)6T_>&K)czHiAdUSkN zHu7()sCspBOFB+VQ3{0jd2$WawVwO@Ffif_ZML&LQA(tFns iIIF>=tB((i!+zs5$pj5Hdv+mzUWX%#6-x%aMgIYiVE4NK delta 2235 zcmaJ?dr(wW7(d_H-Mh=OyW%6jW#c6RE4mgCInk)RK?yd>G%du}627=0X=&gyET@E> zQyzN=%wWp+ZjQOrADWo2(o8fX3qi}VvWB1;XH0A8JNIHVHPe|n=YHS$eXrkl&b{}y zcFS+=mIF!f&@4j8OMnXyXvTFtPJD*r(AM;vgJ5%r=HDA%V$4XQpD`sZ$MjE zf47;bQyc*7+_V$2U*i4rddhmz6}CSu)ZBV;O@IG|hsCwxyTDFO&^8E(_!c*A11sA% zRUEQAL7dInq=?js!Blwaf+(sXz@s-pnAW~!e4#~*o6!*?ekh&^V$$SAU~0jdxBD}y zQOg71tUN1Pyty|FMB8drkwpo0N;-(%;v2xbjWAT~`}2;$?=_1`zZpc?Dk~K)H}nUI zGbKiY7++_hLe0${w72l*wnB*CTaSln63@15GKi78tN@WLZubwa?YRYoIaokTUdc4? zz@-~XD=JYO!lL%PD0c3#(XmJH=6*cn5nl+g(4#nykq~+upQlM8{S4(VQT`fjzQGH} z`ntnK+qD^Hai3_n2M+qcNX3oLpY5h5ypQYIzMBcKBGBlA;ikajZIJHrd!NR#pV9C0 z)B?LWaQ7A-U#93@U7`ev?NDU+@D>~zVk(fYVPLHrenog_;J`2_bc-8DpAQ#nFE7B3 zBq2kiPR@noYT2&cb4Kw0BbF!`PY(UA;wb6xu93>H-)&{&(kGfMb!}YwgvD$g&U@xT zi-{wN6@2M@c$Z(B4~eE%QIF!KWiaZ$B9e@`$59DfT?uM#AZ-Q=cbHmaD|D~zGN9~7 zrin+_fQ>g4K@Q)065PD43PQOz1A=&79c1x_LNM`E7AUg)oA~~r{FUp72u_7AloLTyn_EvrsL+x4~1-L$>a8^+kyDdq?5fHuk>7PppG{meQBc-A_V1KYRvadBR!TTGgi& zHsFJKC;7b=dFiNU4)4o@NSVjYJ3fbe!(d{!aiO{ZlSTv(eQ4Of4w>U22M5~wV3XSb z>3{Ij2%76Wb`#I($0gP3Vo5|hA#HJg!H*!WBnjMJ%&jgu#yKtuujSY!>aq&_sQfr+ zJ28b9xu}Qk_%2ZEq7LfhRfH%uwQ7NnK-Vv5I8itLY6RaANq0~~HZO{zp>#rk`=Zd% zypnH;qPbKV#=CIeX_$@nR^2~SMfow^-`vR^(TE4tU{T>Zp71DQ#X4^Ll~0tor5SaP zj=!Ca^5Z(bS>;Qkk#rlroqv=5$3J5HRDKTqlW8d0hhS5X=)j*v3$Usb^Qud#7t2@r zAAa;R9vVYE&f;T(yr(y!%~P5ils59x7#cd#9zcJyUe}cch|SP&LirmpG;AbXM|FU9 zyZmy`yayjf*qJ;Jy%o)yCSE{D{t0my6yAf;orXoIIP~Z>V^GFwM<+zT2xD#ccLAppendPath(appendPath); + rv = file->Append(appendPath); VerifyResult(rv); printf("Getting Filename\n"); @@ -143,7 +143,7 @@ void CreationTest(char* creationPath, char* appendPath, VerifyResult(rv); printf("Appending %s\n", appendPath); - rv = file->AppendPath(appendPath); + rv = file->Append(appendPath); VerifyResult(rv); printf("Check For Existance\n"); @@ -171,6 +171,47 @@ void CreationTest(char* creationPath, char* appendPath, } } + +void +CopyTest(char *testFile, char *targetDir) +{ + nsCOMPtr file; + nsCOMPtr dir; + + printf("start copy test\n"); + + nsresult rv = + nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, NULL, + nsCOMTypeInfo::GetIID(), + (void**)getter_AddRefs(file)); + + if (NS_FAILED(rv) || (!file)) + { + printf("create nsILocalFile failed\n"); + return; + } + + rv = file->InitWithPath(testFile); + VerifyResult(rv); + + rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, NULL, + nsCOMTypeInfo::GetIID(), + (void**)getter_AddRefs(dir)); + + if (NS_FAILED(rv) || (!dir)) + { + printf("create nsILocalFile failed\n"); + return; + } + + rv = dir->InitWithPath(targetDir); + VerifyResult(rv); + + rv = file->CopyTo(dir, NULL); + VerifyResult(rv); + + printf("end copy test\n"); +} void DeletionTest(char* creationPath, char* appendPath, PRBool recursive) @@ -194,7 +235,7 @@ DeletionTest(char* creationPath, char* appendPath, PRBool recursive) VerifyResult(rv); printf("Appending %s\n", appendPath); - rv = file->AppendPath(appendPath); + rv = file->Append(appendPath); VerifyResult(rv); printf("Check For Existance\n"); @@ -247,6 +288,8 @@ int main(void) CreationTest("/tmp", "mumble/a/b/c/d/e/f/g/h/i/j/k/", nsIFile::DIRECTORY_TYPE, 0644); DeletionTest("/tmp", "mumble", PR_TRUE); + CopyTest("/tmp/test.txt", "/tmp/foo"); + #endif /* XP_UNIX */ #endif /* XP_PC */ } diff --git a/mozilla/xpcom/tests/services/Makefile.in b/mozilla/xpcom/tests/services/Makefile.in index 298df950d49..5588cc8e963 100644 --- a/mozilla/xpcom/tests/services/Makefile.in +++ b/mozilla/xpcom/tests/services/Makefile.in @@ -26,6 +26,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk +IS_COMPONENT = 1 LIBRARY_NAME = MyService CPPSRCS = MyService.cpp diff --git a/mozilla/xpcom/tests/services/makefile.win b/mozilla/xpcom/tests/services/makefile.win index d8504ce76a8..a027769660b 100644 --- a/mozilla/xpcom/tests/services/makefile.win +++ b/mozilla/xpcom/tests/services/makefile.win @@ -47,4 +47,4 @@ MODULE = xpcom include <$(DEPTH)\config\rules.mak> install:: $(DLL) - $(MAKE_INSTALL) $(DLL) $(DIST)\bin + $(MAKE_INSTALL) $(DLL) $(DIST)\bin\components diff --git a/mozilla/xpcom/tests/utils/cp.js b/mozilla/xpcom/tests/utils/cp.js index 197497be0df..edcd55cb244 100644 --- a/mozilla/xpcom/tests/utils/cp.js +++ b/mozilla/xpcom/tests/utils/cp.js @@ -4,11 +4,11 @@ var prefix = ""; function cp(source, dest, followLinks, newName) { try { - var sourceFile = Components.classes["component://netscape/file/local"]. + var sourceFile = Components.classes["component://mozilla/file/local"]. createInstance(nsILocalFile); sourceFile.initWithPath(source); - var destFile = Components.classes["component://netscape/file/local"]. + var destFile = Components.classes["component://mozilla/file/local"]. createInstance(nsILocalFile); destFile.initWithPath(dest); @@ -48,11 +48,11 @@ function cp(source, dest, followLinks, newName) function mv(source, dest, followLinks, newName) { try { - var sourceFile = Components.classes["component://netscape/file/local"]. + var sourceFile = Components.classes["component://mozilla/file/local"]. createInstance(nsILocalFile); sourceFile.initWithPath(source); - var destFile = Components.classes["component://netscape/file/local"]. + var destFile = Components.classes["component://mozilla/file/local"]. createInstance(nsILocalFile); destFile.initWithPath(dest); diff --git a/mozilla/xpcom/tests/utils/ls.js b/mozilla/xpcom/tests/utils/ls.js index 0fb4b07b1de..f74f811c51a 100644 --- a/mozilla/xpcom/tests/utils/ls.js +++ b/mozilla/xpcom/tests/utils/ls.js @@ -3,7 +3,7 @@ var prefix = ""; function ls(path, recur) { - var file = Components.classes["component://netscape/file/local"]. + var file = Components.classes["component://mozilla/file/local"]. createInstance(nsILocalFile); try { file.initWithPath( path ); diff --git a/mozilla/xpcom/tools/registry/regxpcom.cpp b/mozilla/xpcom/tools/registry/regxpcom.cpp index 20cc91c41f4..92c4129ac69 100644 --- a/mozilla/xpcom/tools/registry/regxpcom.cpp +++ b/mozilla/xpcom/tools/registry/regxpcom.cpp @@ -26,6 +26,7 @@ #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" +#include "nsILocalFile.h" static PRBool gUnreg = PR_FALSE; @@ -51,13 +52,22 @@ void print_err(nsresult err) nsresult Register(const char *path) { - nsCOMPtr spec; - nsresult res = NS_NewFileSpec(getter_AddRefs(spec)); - if (NS_FAILED(res)) return res; - res = spec->SetNativePath((char *)path); - if (NS_FAILED(res)) return res; - res = nsComponentManager::AutoRegisterComponent(nsIComponentManager::NS_Startup, spec); - return res; + nsCOMPtr spec; + nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID, + nsnull, + nsCOMTypeInfo::GetIID(), + getter_AddRefs(spec)); + + if (NS_FAILED(rv) || (!spec)) + { + printf("create nsILocalFile failed\n"); + return NS_ERROR_FAILURE; + } + + rv = spec->InitWithPath((char *)path); + if (NS_FAILED(rv)) return rv; + rv = nsComponentManager::AutoRegisterComponent(nsIComponentManager::NS_Startup, spec); + return rv; } nsresult Unregister(const char *path) diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index f7c7c39d2fe..159df332c5b 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -478,6 +478,7 @@ static nsresult main1(int argc, char* argv[]) // _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF); #endif + #ifndef XP_MAC // Unbuffer debug output (necessary for automated QA performance scripts). setbuf( stdout, 0 ); diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 135245dbb0d..7081a917c01 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -28,7 +28,8 @@ */ #include "nsCOMPtr.h" -#include "nsFileSpec.h" +#include "nsIFileSpec.h" +#include "nsCRT.h" #include "nsFileStream.h" #include "nsIBookmarksService.h" #include "nsIComponentManager.h" @@ -4423,7 +4424,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsBookmarksServiceModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -4455,7 +4456,7 @@ nsBookmarksServiceModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsBookmarksServiceModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -4496,7 +4497,7 @@ nsBookmarksServiceModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToU static nsBookmarksServiceModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp index 7cd2036e015..a7f3c79ebd2 100644 --- a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp @@ -32,6 +32,7 @@ #include "jsapi.h" #include "nsCOMPtr.h" +#include "nsCRT.h" #include "nsEscape.h" #include "nsNetUtil.h" #include "nsIContentViewer.h" @@ -1238,7 +1239,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsDirectoryViewerModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -1271,7 +1272,7 @@ nsDirectoryViewerModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsDirectoryViewerModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -1312,7 +1313,7 @@ nsDirectoryViewerModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUn static nsDirectoryViewerModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp index d83c2db06b6..201df7699df 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -32,7 +32,8 @@ */ #include "nsCOMPtr.h" -#include "nsFileSpec.h" +#include "nsIFileSpec.h" +#include "nsCRT.h" #include "nsFileStream.h" #include "nsIModule.h" #include "nsIEnumerator.h" @@ -1990,7 +1991,7 @@ nsGlobalHistoryModule::GetClassObject(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsGlobalHistoryModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -2013,7 +2014,7 @@ nsGlobalHistoryModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsGlobalHistoryModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -2040,7 +2041,7 @@ nsGlobalHistoryModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnlo static nsGlobalHistoryModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpfe/components/public/nsIAppShellComponentImpl.h b/mozilla/xpfe/components/public/nsIAppShellComponentImpl.h index 733ac594c72..f81c35bdc24 100644 --- a/mozilla/xpfe/components/public/nsIAppShellComponentImpl.h +++ b/mozilla/xpfe/components/public/nsIAppShellComponentImpl.h @@ -64,7 +64,7 @@ static _class *g##_class; \ extern "C" NS_EXPORT nsresult \ NSGetModule(nsIComponentManager *servMgr, \ - nsIFileSpec* location, \ + nsIFile* aPath, \ nsIModule** aResult) \ { \ nsresult rv = NS_OK; \ @@ -303,7 +303,7 @@ NS_IMPL_ISUPPORTS1(className##Module, nsIModule) \ /* NSRegisterSelf implementation */\ NS_IMETHODIMP \ className##Module::RegisterSelf(nsIComponentManager *compMgr, \ - nsIFileSpec *path, \ + nsIFile* aPath, \ const char *registryLocation, \ const char *componentType) \ { \ @@ -314,7 +314,7 @@ className##Module::RegisterSelf(nsIComponentManager *compMgr, \ if (NS_FAILED(rv)) return rv; \ /* Register our component. */ \ rv = compMgr->RegisterComponentSpec( className::GetCID(), #className, \ - progId, path, PR_TRUE, PR_TRUE ); \ + progId, aPath, PR_TRUE, PR_TRUE ); \ if ( NS_SUCCEEDED( rv ) ) { \ DEBUG_PRINTF( PR_STDOUT, #className " registration successful\n" ); \ if ( autoInit ) { \ @@ -351,7 +351,7 @@ className##Module::RegisterSelf(nsIComponentManager *compMgr, \ /* UnregisterSelf implementation */ \ NS_IMETHODIMP \ className##Module::UnregisterSelf( nsIComponentManager *compMgr, \ - nsIFileSpec* path, \ + nsIFile* aPath, \ const char *registryLocation) { \ nsresult rv = NS_OK; \ if (NS_FAILED(rv)) \ @@ -361,7 +361,7 @@ className##Module::UnregisterSelf( nsIComponentManager *compMgr, \ } \ \ /* Unregister our component. */ \ - rv = compMgr->UnregisterComponentSpec( className::GetCID(), path ); \ + rv = compMgr->UnregisterComponentSpec( className::GetCID(), aPath); \ if ( NS_SUCCEEDED( rv ) ) { \ DEBUG_PRINTF( PR_STDOUT, #className " unregistration successful\n" ); \ } else { \ diff --git a/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp b/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp index 526c821d7d9..82301ac4485 100644 --- a/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp +++ b/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp @@ -28,6 +28,7 @@ */ #include "nsCOMPtr.h" +#include "nsIFileSpec.h" #include "nsIModule.h" #include "nsEnumeratorUtils.h" #include "nsIComponentManager.h" @@ -42,6 +43,7 @@ #include "nsXPIDLString.h" #include "plstr.h" #include "rdf.h" +#include "nsCRT.h" static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID); @@ -972,7 +974,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsRegistryDataSourceModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -1003,7 +1005,7 @@ nsRegistryDataSourceModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsRegistryDataSourceModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -1040,7 +1042,7 @@ nsRegistryDataSourceModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okT static nsRegistryDataSourceModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp b/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp index 6bc5466e418..2e29c9dfc61 100644 --- a/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp +++ b/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp @@ -28,6 +28,7 @@ */ #include "nsCOMPtr.h" +#include "nsCRT.h" #include "nsEnumeratorUtils.h" #include "nsIGenericFactory.h" #include "nsIInputStream.h" @@ -1213,7 +1214,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsRelatedLinksModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -1246,7 +1247,7 @@ nsRelatedLinksModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsRelatedLinksModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -1287,7 +1288,7 @@ nsRelatedLinksModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnloa static nsRelatedLinksModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpfe/components/search/src/nsRegisterSearch.cpp b/mozilla/xpfe/components/search/src/nsRegisterSearch.cpp index d664593a457..44a90e3dc9e 100755 --- a/mozilla/xpfe/components/search/src/nsRegisterSearch.cpp +++ b/mozilla/xpfe/components/search/src/nsRegisterSearch.cpp @@ -31,6 +31,7 @@ #include "nsIServiceManager.h" #include "nsIRDFDataSource.h" #include "nsISearchService.h" +#include "nsCRT.h" static NS_DEFINE_CID(kLocalSearchServiceCID, NS_RDFFINDDATASOURCE_CID); static NS_DEFINE_CID(kInternetSearchServiceCID, NS_RDFSEARCHDATASOURCE_CID); @@ -196,7 +197,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsSearchModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -229,7 +230,7 @@ nsSearchModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsSearchModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -270,7 +271,7 @@ nsSearchModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) static nsSearchModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* aPath, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpfe/components/shistory/src/nsSHistory.cpp b/mozilla/xpfe/components/shistory/src/nsSHistory.cpp index 338830926f2..0f2d85fcbe8 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHistory.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHistory.cpp @@ -25,7 +25,7 @@ #include "nsSHistory.h" #include "nsIGenericFactory.h" #include "nsXPIDLString.h" - +#include "nsString.h" #ifdef XXX_NS_DEBUG // XXX: we'll need a logging facility for debugging diff --git a/mozilla/xpfe/components/xfer/src/nsStreamXferOp.cpp b/mozilla/xpfe/components/xfer/src/nsStreamXferOp.cpp index 1752f71763b..4de1a14f3a3 100644 --- a/mozilla/xpfe/components/xfer/src/nsStreamXferOp.cpp +++ b/mozilla/xpfe/components/xfer/src/nsStreamXferOp.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -38,6 +38,7 @@ #include "nsIFileTransportService.h" #include "nsIOutputStream.h" #include "nsNetUtil.h" +#include "nsILocalFile.h" #include "prprf.h" @@ -159,10 +160,13 @@ nsStreamXferOp::Start( void ) { if ( NS_SUCCEEDED( rv ) ) { // Next, create output file channel. - nsFileSpec target; + nsFileSpec target; // XXX eliminate mOutputSpec->GetFileSpec( &target ); - rv = fts->CreateTransport( target, "load", 0, 0, - getter_AddRefs( mOutputChannel ) ); + nsCOMPtr file; + rv = NS_NewLocalFile(target, getter_AddRefs(file)); + if (NS_SUCCEEDED(rv)) + rv = fts->CreateTransport(file, PR_RDONLY, "load", 0, 0, + getter_AddRefs( mOutputChannel)); if ( NS_SUCCEEDED( rv ) ) { // reset the channel's interface requestor so we receive status diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index e3e334c49b0..6c874311602 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -74,6 +74,7 @@ #include "nsAppleSingleDecoder.h" #endif +#include "nsILocalFile.h" static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); @@ -2167,8 +2168,13 @@ nsInstall::Confirm(nsString& string, PRBool* aReturn) PRInt32 nsInstall::OpenJARFile(void) -{ - nsresult rv = mJarFileData->Init(mJarFileLocation); +{ + nsresult rv; + nsCOMPtr file; + rv = NS_NewLocalFile(mJarFileLocation, getter_AddRefs(file)); // XXX until mJarFileLocation is an nsIFile + if (NS_FAILED(rv)) + return UNEXPECTED_ERROR; + rv = mJarFileData->Init(file); if (NS_FAILED(rv)) return UNEXPECTED_ERROR; @@ -2234,7 +2240,11 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa // We will overwrite what is in the way. is this something that we want to do? extractHereSpec->Delete(PR_FALSE); - nsresult rv = mJarFileData->Extract( nsAutoCString(aJarfile), *extractHereSpec ); + nsresult rv; + nsCOMPtr file; + rv = NS_NewLocalFile(*extractHereSpec, getter_AddRefs(file)); + if (NS_SUCCEEDED(rv)) + rv = mJarFileData->Extract(nsAutoCString(aJarfile), file); if (NS_FAILED(rv)) { if (extractHereSpec != nsnull) diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index 24778265006..027aafc08ea 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -28,6 +28,7 @@ #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" +#include "nsCRT.h" #include "nspr.h" #include "prlock.h" @@ -656,7 +657,7 @@ static Components gComponents[] = { NS_IMETHODIMP nsSoftwareUpdateModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation, const char* componentType) { @@ -717,7 +718,7 @@ nsSoftwareUpdateModule::RegisterSelf(nsIComponentManager *aCompMgr, NS_IMETHODIMP nsSoftwareUpdateModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, + nsIFile* aPath, const char* registryLocation) { #ifdef DEBUG @@ -754,7 +755,7 @@ nsSoftwareUpdateModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnl static nsSoftwareUpdateModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* location, + nsIFile* location, nsIModule** return_cobj) { nsresult rv = NS_OK; diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index 05d0c414e81..a2573640b68 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -45,6 +45,7 @@ #include "nsCOMPtr.h" #include "nsIEventQueueService.h" +#include "nsILocalFile.h" static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); @@ -135,7 +136,11 @@ GetInstallScriptFromJarfile(nsFileSpec& jarFile, char** scriptBuffer, PRUint32 * if (NS_FAILED(rv)) return nsInstall::CANT_READ_ARCHIVE; - rv = hZip->Init(jarFile); + nsCOMPtr jFile; + rv = NS_NewLocalFile(jarFile, getter_AddRefs(jFile)); + if (NS_SUCCEEDED(rv)) + rv = hZip->Init(jFile); + if (NS_FAILED(rv)) return nsInstall::CANT_READ_ARCHIVE; @@ -149,7 +154,10 @@ GetInstallScriptFromJarfile(nsFileSpec& jarFile, char** scriptBuffer, PRUint32 * installJSFileSpec.MakeUnique(); // Extract the install.js file. - rv = hZip->Extract("install.js", installJSFileSpec); + nsCOMPtr iFile; + rv = NS_NewLocalFile(installJSFileSpec, getter_AddRefs(iFile)); + if (NS_SUCCEEDED(rv)) + rv = hZip->Extract("install.js", iFile); if ( NS_SUCCEEDED(rv) ) { // Read it into a buffer diff --git a/mozilla/xpinstall/stub/xpistub.cpp b/mozilla/xpinstall/stub/xpistub.cpp index ec63db901e6..ffb2303525f 100644 --- a/mozilla/xpinstall/stub/xpistub.cpp +++ b/mozilla/xpinstall/stub/xpistub.cpp @@ -28,8 +28,8 @@ #include "nsRepository.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" - #include "nsSpecialSystemDirectory.h" +#include "nsILocalFile.h" #include "nscore.h" #include "nspr.h" @@ -50,6 +50,8 @@ #ifdef XP_MAC #define COMPONENT_REG "\pComponent Registry" #include "MoreFilesExtras.h" +#include "nsLocalFileMac.h" +#include "nsILocalFileMac.h" #endif #ifdef XP_UNIX @@ -91,24 +93,23 @@ PR_PUBLIC_API(nsresult) XPI_Init( // Initialize XPCOM and AutoRegister() its components //-------------------------------------------------------------------- #ifdef XP_MAC - OSErr err = noErr; - long xpiStubDirID = 0; - Boolean isDir = false; + nsLocalFile* localFile = new nsLocalFile; + if (localFile) + { + localFile->InitWithFSSpec(&aXPIStubDir); + rv = NS_InitXPCOM(&gServiceMgr, localFile); + } + else + { + rv = NS_ERROR_FAILURE; + } +#elif defined(XP_PC) || defined(XP_UNIX) - FSpGetDirectoryID(&aXPIStubDir, &xpiStubDirID, &isDir); - nsfsDirectory = aXPIStubDir; - rv = NS_InitXPCOM(&gServiceMgr, &nsfsDirectory); -#elif defined(XP_PC) - char componentPath[_MAX_PATH]; - - getcwd(componentPath, _MAX_PATH); - nsfsDirectory = componentPath; - - rv = NS_InitXPCOM(&gServiceMgr, &nsfsDirectory); -#elif defined(XP_UNIX) - nsfsDirectory = aProgramDir; - - rv = NS_InitXPCOM(&gServiceMgr, &nsfsDirectory); + nsCOMPtr file; + NS_NewLocalFile(aProgramDir, getter_AddRefs(file)); + + rv = NS_InitXPCOM(&gServiceMgr, file); + #else rv = NS_InitXPCOM(&gServiceMgr, NULL); #endif