fixes bug 15320 "Forms/Necko: Temp file (formpost) left after file upload"

r=dougt, sr=mscott
This commit is contained in:
darin%netscape.com 2001-12-07 00:40:55 +00:00
Родитель bfbe71bf7e
Коммит b639381424
7 изменённых файлов: 56 добавлений и 12 удалений

Просмотреть файл

@ -428,7 +428,8 @@ nsFormSubmitter::OnSubmit(nsIForm* form,
NS_NewLocalFileInputStream(getter_AddRefs(rawStream),
multipartDataFile,
PR_RDONLY,
0600);
0600,
PR_TRUE);
if (rawStream) {
NS_NewBufferedInputStream(getter_AddRefs(postDataStream),
rawStream, 8192);

Просмотреть файл

@ -269,7 +269,7 @@ function EditorExecuteScript(theFile)
var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance();
inputStream = inputStream.QueryInterface(Components.interfaces.nsIFileInputStream);
inputStream.init(theFile, 1, 0); // open read only
inputStream.init(theFile, 1, 0, false); // open read only
var scriptableInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance();
scriptableInputStream = scriptableInputStream.QueryInterface(Components.interfaces.nsIScriptableInputStream);

Просмотреть файл

@ -151,7 +151,7 @@ nsresult nsMailboxProtocol::OpenFileSocketForReuse(nsIURI * aURL, PRUint32 aStar
m_multipleMsgMoveCopyStream = do_QueryInterface(fileStream, &rv);
NS_ENSURE_SUCCESS(rv, rv);
fileStream->Init(file, PR_RDONLY, 0664); //just have to read the messages
fileStream->Init(file, PR_RDONLY, 0664, PR_FALSE); //just have to read the messages
PRUint32 length;
PRInt64 fileSize;
rv = file->GetFileSize( &fileSize);

Просмотреть файл

@ -44,18 +44,34 @@ interface nsIFile;
[scriptable, uuid(e3d56a20-c7ec-11d3-8cda-0060b0fc14a3)]
interface nsIFileInputStream : nsIInputStream
{
void init(in nsIFile file, in long ioFlags, in long perm);
/**
* @param file - file to read from (must QI to nsILocalFile)
* @param ioFlags - file open flags listed in prio.h
* @param perm - file mode bits listed in prio.h
* @param deleteOnClose - if true, the file is deleted from the filesystem
* after the file stream is closed.
*/
void init(in nsIFile file, in long ioFlags, in long perm, in boolean deleteOnClose);
};
[scriptable, uuid(e6f68040-c7ec-11d3-8cda-0060b0fc14a3)]
interface nsIFileOutputStream : nsIOutputStream
{
/**
* @param file - file to write to (must QI to nsILocalFile)
* @param ioFlags - file open flags listed in prio.h
* @param perm - file mode bits listed in prio.h
*/
void init(in nsIFile file, in long ioFlags, in long perm);
};
[scriptable, uuid(616f5b48-da09-11d3-8cda-0060b0fc14a3)]
interface nsIBufferedInputStream : nsIInputStream
{
/**
* @param fillFromStream - add buffering to this stream
* @param bufferSize - specifies the maximum buffer size
*/
void init(in nsIInputStream fillFromStream,
in unsigned long bufferSize);
};
@ -63,6 +79,10 @@ interface nsIBufferedInputStream : nsIInputStream
[scriptable, uuid(6476378a-da09-11d3-8cda-0060b0fc14a3)]
interface nsIBufferedOutputStream : nsIOutputStream
{
/**
* @param sinkToStream - add buffering to this stream
* @param bufferSize - specifies the maximum buffer size
*/
void init(in nsIOutputStream sinkToStream,
in unsigned long bufferSize);
};
@ -155,7 +175,8 @@ inline nsresult
NS_NewLocalFileInputStream(nsIInputStream* *result,
nsIFile* file,
PRInt32 ioFlags = -1,
PRInt32 perm = -1)
PRInt32 perm = -1,
PRBool deleteOnClose = PR_FALSE)
{
nsresult rv;
nsCOMPtr<nsIFileInputStream> in;
@ -165,7 +186,7 @@ NS_NewLocalFileInputStream(nsIInputStream* *result,
NS_GET_IID(nsIFileInputStream),
getter_AddRefs(in));
if (NS_FAILED(rv)) return rv;
rv = in->Init(file, ioFlags, perm);
rv = in->Init(file, ioFlags, perm, deleteOnClose);
if (NS_FAILED(rv)) return rv;
*result = in;

Просмотреть файл

@ -266,7 +266,7 @@ nsFileIO::GetInputStream(nsIInputStream * *aInputStream)
if (fileIn == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(fileIn);
rv = fileIn->Init(mFile, mIOFlags, mPerm);
rv = fileIn->Init(mFile, mIOFlags, mPerm, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
#ifdef NS_NO_INPUT_BUFFERING
*aInputStream = fileIn;
@ -448,7 +448,7 @@ nsFileInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
}
NS_IMETHODIMP
nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm)
nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm, PRBool deleteOnClose)
{
NS_ASSERTION(mFD == nsnull, "already inited");
if (mFD != nsnull)
@ -463,7 +463,18 @@ nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm)
mLineBuffer = nsnull;
return localFile->OpenNSPRFileDesc(ioFlags, perm, &mFD);
rv = localFile->OpenNSPRFileDesc(ioFlags, perm, &mFD);
if (NS_FAILED(rv)) return rv;
if (deleteOnClose) {
#if defined(XP_UNIX) || defined(XP_WIN)
rv = file->Remove(PR_FALSE);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to delete file");
#else
mFileToDelete = file;
#endif
}
return NS_OK;
}
NS_IMETHODIMP
@ -471,7 +482,15 @@ nsFileInputStream::Close()
{
PR_FREEIF(mLineBuffer);
mLineBuffer = nsnull; // in case Close() is called again after failing
return nsFileStream::Close();
nsresult rv = nsFileStream::Close();
#if !defined(XP_UNIX) && !defined(XP_WIN)
if (NS_FAILED(rv)) return rv;
if (mFileToDelete) {
rv = mFileToDelete->Remove(PR_FALSE);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to delete file");
}
#endif
return rv;
}
NS_IMETHODIMP

Просмотреть файл

@ -110,6 +110,9 @@ public:
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
protected:
nsLineBuffer * mLineBuffer;
#if !defined(XP_UNIX) && !defined(XP_WIN)
nsCOMPtr<nsIFile> mFileToDelete;
#endif
};
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -334,7 +334,7 @@ CreateInputStream(const nsAString& aFilename,
nsCOMPtr<nsIFileInputStream> fileStream(do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
rv = fileStream->Init(file, -1, -1);
rv = fileStream->Init(file, -1, -1, PR_FALSE);
if (NS_FAILED(rv))
return rv;
@ -903,7 +903,7 @@ GetHandlerAndDescriptionFromMailcapFile(const nsAString& aFilename,
nsCOMPtr<nsIFileInputStream> mailcapFile(do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
rv = mailcapFile->Init(file, -1, -1);
rv = mailcapFile->Init(file, -1, -1, PR_FALSE);
if (NS_FAILED(rv))
return rv;