From dc3430b7024b35b1b47909ef9fcf1804a785f115 Mon Sep 17 00:00:00 2001 From: "dougt%meer.net" Date: Wed, 29 Jun 2005 22:23:55 +0000 Subject: [PATCH] fixes a mailnews regression. We need to be able to create a unique directory. sr=dveditz, a=dveditz, bug 299133 --- xpcom/obsolete/nsFileSpec.cpp | 10 +++++----- xpcom/obsolete/nsFileSpec.h | 4 ++-- xpcom/obsolete/nsFileSpecImpl.cpp | 16 ++++++++++++++++ xpcom/obsolete/nsIFileSpec.idl | 5 ++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/xpcom/obsolete/nsFileSpec.cpp b/xpcom/obsolete/nsFileSpec.cpp index 0bc073a3337..e835cf223a5 100644 --- a/xpcom/obsolete/nsFileSpec.cpp +++ b/xpcom/obsolete/nsFileSpec.cpp @@ -896,17 +896,16 @@ nsFileSpec::nsFileSpec(const nsFileURL& inURL) } //---------------------------------------------------------------------------------------- -void nsFileSpec::MakeUnique(const char* inSuggestedLeafName) +void nsFileSpec::MakeUnique(const char* inSuggestedLeafName, PRBool inCreateFile) //---------------------------------------------------------------------------------------- { if (inSuggestedLeafName && *inSuggestedLeafName) SetLeafName(inSuggestedLeafName); - - MakeUnique(); + MakeUnique(inCreateFile); } // nsFileSpec::MakeUnique //---------------------------------------------------------------------------------------- -void nsFileSpec::MakeUnique() +void nsFileSpec::MakeUnique(PRBool inCreateFile) //---------------------------------------------------------------------------------------- { // XXX: updated path starts empty. In case of error this will cause @@ -917,7 +916,8 @@ void nsFileSpec::MakeUnique() NS_NewNativeLocalFile(nsDependentCString(*this), PR_TRUE, getter_AddRefs(localFile)); if (localFile) { - nsresult rv = localFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); + nsresult rv = localFile->CreateUnique(inCreateFile ? nsIFile::NORMAL_FILE_TYPE : + nsIFile::DIRECTORY_TYPE, 0600); if (NS_SUCCEEDED(rv)) localFile->GetNativePath(path); } diff --git a/xpcom/obsolete/nsFileSpec.h b/xpcom/obsolete/nsFileSpec.h index e7f20c3e9ed..639f3d4841d 100644 --- a/xpcom/obsolete/nsFileSpec.h +++ b/xpcom/obsolete/nsFileSpec.h @@ -474,8 +474,8 @@ class NS_COM_OBSOLETE nsFileSpec //-------------------------------------------------- // For security reasons, these create the file. - void MakeUnique(); - void MakeUnique(const char* inSuggestedLeafName); + void MakeUnique(PRBool inCreateFile = PR_TRUE); + void MakeUnique(const char* inSuggestedLeafName, PRBool inCreateFile = PR_TRUE); // Called for the spec of an alias. Modifies the spec to // point to the original. Sets mError. diff --git a/xpcom/obsolete/nsFileSpecImpl.cpp b/xpcom/obsolete/nsFileSpecImpl.cpp index b0e3cc15efe..884125fdf2b 100644 --- a/xpcom/obsolete/nsFileSpecImpl.cpp +++ b/xpcom/obsolete/nsFileSpecImpl.cpp @@ -314,6 +314,22 @@ NS_IMETHODIMP nsFileSpecImpl::MakeUniqueWithSuggestedName(const char *suggestedN return mFileSpec.Error(); } +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsFileSpecImpl::MakeUniqueDir() +//---------------------------------------------------------------------------------------- +{ + mFileSpec.MakeUnique(PR_FALSE); + return mFileSpec.Error(); +} + +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP nsFileSpecImpl::MakeUniqueDirWithSuggestedName(const char *suggestedName) +//---------------------------------------------------------------------------------------- +{ + mFileSpec.MakeUnique(suggestedName, PR_FALSE); + return mFileSpec.Error(); +} + //---------------------------------------------------------------------------------------- NS_IMETHODIMP nsFileSpecImpl::GetModDate(PRUint32 *aModDate) //---------------------------------------------------------------------------------------- diff --git a/xpcom/obsolete/nsIFileSpec.idl b/xpcom/obsolete/nsIFileSpec.idl index 78abd9e751c..097ae91eb9b 100644 --- a/xpcom/obsolete/nsIFileSpec.idl +++ b/xpcom/obsolete/nsIFileSpec.idl @@ -75,7 +75,7 @@ interface nsIInputStream; [ref] native nsFileSpecRef(nsFileSpec); [ptr] native nsFileSpecPtr(nsFileSpec); -[scriptable, uuid(d8c0a080-0868-11d3-915f-d9d889d48e3c)] +[scriptable, uuid(37ef2e71-edef-46c7-acd9-f0b6e0b15083)] interface nsIFileSpec : nsISupports { void fromFileSpec([const] in nsIFileSpec original); @@ -106,6 +106,9 @@ interface nsIFileSpec : nsISupports void makeUnique(); void makeUniqueWithSuggestedName(in string suggestedName); + void makeUniqueDir(); + void makeUniqueDirWithSuggestedName(in string suggestedName); + readonly attribute unsigned long modDate; boolean modDateChanged(in unsigned long oldStamp);