зеркало из 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;
|
*aURL = nsnull;
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsXPIDLCString ePath;
|
char* ePath = nsnull;
|
||||||
nsCAutoString escPath;
|
nsCAutoString escPath;
|
||||||
|
|
||||||
rv = aFile->GetPath(getter_Copies(ePath));
|
rv = aFile->GetPath(&ePath);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
|
||||||
SwapSlashColon((char*)ePath.get());
|
SwapSlashColon(ePath);
|
||||||
|
|
||||||
// Escape the path with the directory mask
|
// Escape the path with the directory mask
|
||||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
|
||||||
// colons [originally slashes, before SwapSlashColon() usage above]
|
|
||||||
// need encoding
|
|
||||||
escPath.ReplaceSubstring(":", "%2F");
|
|
||||||
|
|
||||||
if (escPath[escPath.Length() - 1] != '/') {
|
if (escPath[escPath.Length() - 1] != '/') {
|
||||||
|
|
||||||
PRBool dir;
|
PRBool dir;
|
||||||
|
@ -102,6 +98,7 @@ NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL)
|
||||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CRTFREEIF(ePath);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,12 +136,6 @@ NS_IMETHODIMP nsIOService::InitFileFromURLSpec(nsIFile* aFile, const char * aURL
|
||||||
{
|
{
|
||||||
nsStdEscape(directory, esc_Directory, component);
|
nsStdEscape(directory, esc_Directory, component);
|
||||||
path += 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());
|
SwapSlashColon((char*)path.get());
|
||||||
}
|
}
|
||||||
if (fileBaseName)
|
if (fileBaseName)
|
||||||
|
|
|
@ -88,11 +88,8 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nsIFileStreams.h"
|
#include "nsFileSpec.h"
|
||||||
#include "nsIOutputStream.h"
|
#include "nsFileStream.h"
|
||||||
#include "nsIFile.h"
|
|
||||||
#include "nsIFileChannel.h"
|
|
||||||
#include "nsAString.h"
|
|
||||||
#include "nsIDTD.h"
|
#include "nsIDTD.h"
|
||||||
#include "nsIRDFPurgeableDataSource.h"
|
#include "nsIRDFPurgeableDataSource.h"
|
||||||
#include "nsIInputStream.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
|
// XXX Replace this with channels someday soon...
|
||||||
// if we didn't care what kind of stream this was...
|
nsFileURL url(mOriginalURLSpec, PR_TRUE);
|
||||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mURL);
|
nsFileSpec path(url);
|
||||||
if (fileURL) {
|
|
||||||
nsCOMPtr<nsIFile> file;
|
|
||||||
fileURL->GetFile(getter_AddRefs(file));
|
|
||||||
|
|
||||||
if (file) {
|
nsOutputFileStream out(path);
|
||||||
nsCOMPtr<nsIOutputStream> out;
|
if (! out.is_open())
|
||||||
NS_NewLocalFileOutputStream(getter_AddRefs(out), file);
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
nsCOMPtr<nsIOutputStream> bufferedOut;
|
nsCOMPtr<nsIOutputStream> outIStream = out.GetIStream();
|
||||||
if (out)
|
if (NS_FAILED(rv = Serialize(outIStream)))
|
||||||
NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
|
goto done;
|
||||||
|
|
||||||
if (bufferedOut) {
|
|
||||||
rv = Serialize(bufferedOut);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsDirty = PR_FALSE;
|
mIsDirty = PR_FALSE;
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,8 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nsNetUtil.h"
|
#include "nsIFileSpec.h"
|
||||||
#include "nsIURI.h"
|
#include "nsFileStream.h"
|
||||||
#include "nsIIOService.h"
|
|
||||||
#include "nsIOutputStream.h"
|
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsILocalStore.h"
|
#include "nsILocalStore.h"
|
||||||
#include "nsIRDFDataSource.h"
|
#include "nsIRDFDataSource.h"
|
||||||
|
@ -398,42 +396,34 @@ LocalStoreImpl::LoadData()
|
||||||
// directory. Bomb if we can't find it.
|
// directory. Bomb if we can't find it.
|
||||||
|
|
||||||
nsCOMPtr<nsIFile> aFile;
|
nsCOMPtr<nsIFile> aFile;
|
||||||
|
nsCOMPtr<nsIFileSpec> tempSpec;
|
||||||
|
|
||||||
rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile));
|
rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> aURI;
|
// Turn the nsIFile into a nsFileSpec.
|
||||||
rv = NS_NewFileURI(getter_AddRefs(aURI), aFile);
|
// 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;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
nsFileSpec spec((const char *)pathBuf);
|
||||||
|
|
||||||
PRBool fileExistsFlag = PR_FALSE;
|
if (! spec.Exists()) {
|
||||||
(void)aFile->Exists(&fileExistsFlag);
|
{
|
||||||
if (!fileExistsFlag) {
|
nsOutputFileStream os(spec);
|
||||||
nsCOMPtr<nsIOutputStream> outStream;
|
|
||||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStream), aFile);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
const char defaultRDF[] =
|
os << "<?xml version=\"1.0\"?>" << nsEndl;
|
||||||
"<?xml version=\"1.0\"?>\n" \
|
os << "<RDF:RDF xmlns:RDF=\"" << RDF_NAMESPACE_URI << "\"" << nsEndl;
|
||||||
"<RDF:RDF xmlns:RDF=\"" RDF_NAMESPACE_URI "\"\n" \
|
os << " xmlns:NC=\"" << NC_NAMESPACE_URI << "\">" << nsEndl;
|
||||||
" xmlns:NC=\"" NC_NAMESPACE_URI "\">\n" \
|
os << " <!-- Empty -->" << nsEndl;
|
||||||
" <!-- Empty -->\n" \
|
os << "</RDF:RDF>" << nsEndl;
|
||||||
"</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;
|
|
||||||
|
|
||||||
// Okay, now see if the file exists _for real_. If it's still
|
// Okay, now see if the file exists _for real_. If it's still
|
||||||
// not there, it could be that the profile service gave us
|
// not there, it could be that the profile service gave us
|
||||||
// back a read-only directory. Whatever.
|
// back a read-only directory. Whatever.
|
||||||
fileExistsFlag = PR_FALSE;
|
if (! spec.Exists())
|
||||||
(void)aFile->Exists(&fileExistsFlag);
|
|
||||||
if (!fileExistsFlag)
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,11 +433,7 @@ LocalStoreImpl::LoadData()
|
||||||
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner, &rv);
|
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner, &rv);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
nsXPIDLCString spec;
|
rv = remote->Init((const char*) nsFileURL(spec));
|
||||||
rv = aURI->GetSpec(getter_Copies(spec));
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = remote->Init(spec);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
// Read the datasource synchronously.
|
// Read the datasource synchronously.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче