зеркало из https://github.com/mozilla/pjs.git
I'm sorry Dave, I'm afraid I can't allow this checkin. Backing out rjc's change from earlier (121546). r=jrgm
This commit is contained in:
Родитель
97e8c20f29
Коммит
802ed3d657
|
@ -68,22 +68,18 @@ NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL)
|
|||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
nsXPIDLCString ePath;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = aFile->GetPath(getter_Copies(ePath));
|
||||
rv = aFile->GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
SwapSlashColon((char*)ePath.get());
|
||||
SwapSlashColon(ePath);
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// colons [originally slashes, before SwapSlashColon() usage above]
|
||||
// need encoding
|
||||
escPath.ReplaceSubstring(":", "%2F");
|
||||
|
||||
if (escPath[escPath.Length() - 1] != '/') {
|
||||
|
||||
PRBool dir;
|
||||
|
@ -102,6 +98,7 @@ NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL)
|
|||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -139,12 +136,6 @@ NS_IMETHODIMP nsIOService::InitFileFromURLSpec(nsIFile* aFile, const char * aURL
|
|||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
|
||||
// "%2F"s need to become slashes, while all other slashes need to
|
||||
// become colons. If we start out by changing "%2F"s to colons, we
|
||||
// can then rely on SwapSlashColon() to do what we need
|
||||
path.ReplaceSubstring("%2F", ":");
|
||||
|
||||
SwapSlashColon((char*)path.get());
|
||||
}
|
||||
if (fileBaseName)
|
||||
|
|
|
@ -88,11 +88,8 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIFileChannel.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsIDTD.h"
|
||||
#include "nsIRDFPurgeableDataSource.h"
|
||||
#include "nsIInputStream.h"
|
||||
|
@ -822,27 +819,17 @@ RDFXMLDataSourceImpl::Flush(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Is it a file? If so, we can write to it. Some day, it'd be nice
|
||||
// if we didn't care what kind of stream this was...
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mURL);
|
||||
if (fileURL) {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
fileURL->GetFile(getter_AddRefs(file));
|
||||
// XXX Replace this with channels someday soon...
|
||||
nsFileURL url(mOriginalURLSpec, PR_TRUE);
|
||||
nsFileSpec path(url);
|
||||
|
||||
if (file) {
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
NS_NewLocalFileOutputStream(getter_AddRefs(out), file);
|
||||
nsOutputFileStream out(path);
|
||||
if (! out.is_open())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> bufferedOut;
|
||||
if (out)
|
||||
NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
|
||||
|
||||
if (bufferedOut) {
|
||||
rv = Serialize(bufferedOut);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIOutputStream> outIStream = out.GetIStream();
|
||||
if (NS_FAILED(rv = Serialize(outIStream)))
|
||||
goto done;
|
||||
|
||||
mIsDirty = PR_FALSE;
|
||||
|
||||
|
|
|
@ -42,10 +42,8 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsILocalStore.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
|
@ -398,42 +396,34 @@ LocalStoreImpl::LoadData()
|
|||
// directory. Bomb if we can't find it.
|
||||
|
||||
nsCOMPtr<nsIFile> aFile;
|
||||
nsCOMPtr<nsIFileSpec> tempSpec;
|
||||
|
||||
rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> aURI;
|
||||
rv = NS_NewFileURI(getter_AddRefs(aURI), aFile);
|
||||
// Turn the nsIFile into a nsFileSpec.
|
||||
// This is evil! nsOutputFileStream needs
|
||||
// to take an nsILocalFile (bug #46394)
|
||||
nsXPIDLCString pathBuf;
|
||||
rv = aFile->GetPath(getter_Copies(pathBuf));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsFileSpec spec((const char *)pathBuf);
|
||||
|
||||
PRBool fileExistsFlag = PR_FALSE;
|
||||
(void)aFile->Exists(&fileExistsFlag);
|
||||
if (!fileExistsFlag) {
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStream), aFile);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (! spec.Exists()) {
|
||||
{
|
||||
nsOutputFileStream os(spec);
|
||||
|
||||
const char defaultRDF[] =
|
||||
"<?xml version=\"1.0\"?>\n" \
|
||||
"<RDF:RDF xmlns:RDF=\"" RDF_NAMESPACE_URI "\"\n" \
|
||||
" xmlns:NC=\"" NC_NAMESPACE_URI "\">\n" \
|
||||
" <!-- Empty -->\n" \
|
||||
"</RDF:RDF>\n";
|
||||
|
||||
PRUint32 count;
|
||||
rv = outStream->Write(defaultRDF, sizeof(defaultRDF)-1, &count);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (count != sizeof(defaultRDF)-1)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
os << "<?xml version=\"1.0\"?>" << nsEndl;
|
||||
os << "<RDF:RDF xmlns:RDF=\"" << RDF_NAMESPACE_URI << "\"" << nsEndl;
|
||||
os << " xmlns:NC=\"" << NC_NAMESPACE_URI << "\">" << nsEndl;
|
||||
os << " <!-- Empty -->" << nsEndl;
|
||||
os << "</RDF:RDF>" << nsEndl;
|
||||
}
|
||||
|
||||
// Okay, now see if the file exists _for real_. If it's still
|
||||
// not there, it could be that the profile service gave us
|
||||
// back a read-only directory. Whatever.
|
||||
fileExistsFlag = PR_FALSE;
|
||||
(void)aFile->Exists(&fileExistsFlag);
|
||||
if (!fileExistsFlag)
|
||||
if (! spec.Exists())
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
@ -443,11 +433,7 @@ LocalStoreImpl::LoadData()
|
|||
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString spec;
|
||||
rv = aURI->GetSpec(getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = remote->Init(spec);
|
||||
rv = remote->Init((const char*) nsFileURL(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Read the datasource synchronously.
|
||||
|
|
Загрузка…
Ссылка в новой задаче