NuCache Streams now hold the filename for smoother reopening. Not in build as yet.

This commit is contained in:
gagan%netscape.com 1998-10-16 01:29:26 +00:00
parent 5254996718
commit 8eb4d30a1b
3 changed files with 52 additions and 23 deletions

View File

@ -28,11 +28,12 @@
//#include "nsISupports.h"
#include "nsStream.h"
#include "prio.h" // PRFileDesc
class nsFileStream: public nsStream
{
public:
nsFileStream(PRFileDesc* i_pFile);
nsFileStream(const char* i_Filename);
virtual ~nsFileStream();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
@ -48,10 +49,13 @@ public:
protected:
PRBool Open(void);
private:
nsFileStream(const nsFileStream& o);
nsFileStream& operator=(const nsFileStream& o);
PRFileDesc* m_pFile;
char* m_pFilename;
};
inline

View File

@ -295,25 +295,26 @@ nsStream* nsDiskModule::GetStreamFor(const nsCacheObject* i_pObject)
MonitorLocker ml(this);
if (i_pObject)
{
/*
if (Contains((nsCacheObject*)i_pObject))
{
nsStream* pStream = i_pObject->Stream();
if (pStream)
return pStream;
}
*/
nsStream* pStream = i_pObject->Stream();
if (pStream)
return pStream;
PR_ASSERT(*i_pObject->Filename());
char* fullname = FullFilename(i_pObject->Filename());
// Set up a new stream for this object
PRFileDesc* pFD = PR_Open(
fullname ? fullname : i_pObject->Filename(),
PR_CREATE_FILE | PR_RDWR,
600);// Read and write by owner only
if (pFD)
if (fullname)
{
return new nsFileStream(pFD);
return new nsFileStream(fullname);
}
return 0;

View File

@ -18,16 +18,27 @@
*/
#include "nsFileStream.h"
#include "plstr.h"
#include "prlog.h"
nsFileStream::nsFileStream(PRFileDesc* i_pFile):m_pFile(i_pFile)
nsFileStream::nsFileStream(const char* i_Filename):m_pFile(0),m_pFilename(0)
{
PR_ASSERT(m_pFile);
PR_ASSERT(i_Filename);
if (i_Filename)
{
m_pFilename = new char[PL_strlen(i_Filename)+1];
PL_strcpy(m_pFilename, i_Filename);
Open();
}
}
nsFileStream::~nsFileStream()
{
//close the file if not closed. todo
if (m_pFilename)
{
delete[] m_pFilename;
m_pFilename = 0;
}
if (m_pFile)
PR_Close(m_pFile);
}
@ -54,27 +65,40 @@ nsresult nsFileStream::QueryInterface(const nsIID& aIID,
}
*/
PRInt32 nsFileStream::Read(void* o_Buffer, PRUint32 i_Len)
PRBool nsFileStream::Open()
{
if (m_pFile)
PR_Close(m_pFile);
PR_ASSERT(m_pFilename);
if (m_pFilename)
{
return PR_Read(m_pFile, o_Buffer, i_Len);
m_pFile = PR_Open(
m_pFilename,
PR_CREATE_FILE | PR_RDWR,
600);// Read and write by owner only
PR_ASSERT(m_pFile);
if (m_pFile)
return PR_TRUE;
}
return 0;
return PR_FALSE;
}
PRInt32 nsFileStream::Read(void* o_Buffer, PRUint32 i_Len)
{
if (!m_pFile && !Open())
return 0;
return PR_Read(m_pFile, o_Buffer, i_Len);
}
void nsFileStream::Reset()
{
return;
if (m_pFile)
PR_Close(m_pFile);
Open();
}
PRInt32 nsFileStream::Write(const void* i_Buffer, PRUint32 i_Len)
{
if (m_pFile)
{
return PR_Write(m_pFile, i_Buffer, i_Len);
}
return 0;
if (!m_pFile && !Open())
return 0;
return PR_Write(m_pFile, i_Buffer, i_Len);
}