mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Fix nsFileSpec to take native paths in constructors and assignment operators. Fix += to work with relative paths on Macintosh. Remove dependency of nsFileSpec on streams (so that dp can move nsFileSpec).
This commit is contained in:
parent
9ece6fc6eb
commit
ff58eed078
@ -37,6 +37,7 @@ EXPORTS = \
|
||||
nsFileStream.h \
|
||||
nsIFileStream.h \
|
||||
nsIStringStream.h \
|
||||
nsFileSpecStreaming.h \
|
||||
nsSpecialSystemDirectory.h \
|
||||
nsIObserverService.h \
|
||||
nsIObserverList.h \
|
||||
|
@ -29,6 +29,7 @@ EXPORTS = \
|
||||
nsISizeOfHandler.h \
|
||||
nsEscape.h \
|
||||
nsFileSpec.h \
|
||||
nsFileSpecStreaming.h \
|
||||
nsFileStream.h \
|
||||
nsIFileStream.h \
|
||||
nsIString.h \
|
||||
|
@ -53,7 +53,7 @@
|
||||
//
|
||||
// nsFilePath myPath("/Development/iotest.txt");
|
||||
//
|
||||
// nsOutputFileStream testStream(myPath);
|
||||
// nsOutputFileStream testStream(nsFileSpec(myPath));
|
||||
// testStream << "Hello World" << nsEndl;
|
||||
//
|
||||
// 4. Handy methods for manipulating file specifiers safely, e.g. MakeUnique(),
|
||||
@ -63,35 +63,35 @@
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// Initialize a URL from a string without suffix
|
||||
// Initialize a URL from a string
|
||||
//
|
||||
// nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
||||
//
|
||||
// Initialize a Unix path from a URL
|
||||
// Initialize a Unix-style path from a URL
|
||||
//
|
||||
// nsFilePath filePath(fileURL);
|
||||
//
|
||||
// Initialize a native file spec from a URL
|
||||
// Initialize a file spec from a URL
|
||||
//
|
||||
// nsFileSpec fileSpec(fileURL);
|
||||
//
|
||||
// Make the spec unique (this one has no suffix).
|
||||
// Make the spec unique.
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
// Assign the spec to a URL
|
||||
// Assign the spec to a URL (causing conversion)
|
||||
//
|
||||
// fileURL = fileSpec;
|
||||
//
|
||||
// Assign a unix path using a string with a suffix.
|
||||
// Assign a unix path using a string
|
||||
//
|
||||
// filePath = "/Development/MPW/SysErrs.err";
|
||||
//
|
||||
// Assign to a file spec using a unix path.
|
||||
// Assign to a file spec using a unix path (causing conversion).
|
||||
//
|
||||
// fileSpec = filePath;
|
||||
//
|
||||
// Make this unique (this one has a suffix).
|
||||
// Make this unique.
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
@ -103,10 +103,6 @@
|
||||
// is solved by holding a "private" native file spec inside the
|
||||
// nsFilePath and nsFileURL classes, which is used when appropriate.
|
||||
//
|
||||
// Not yet done:
|
||||
//
|
||||
// Equality operators... much more.
|
||||
//
|
||||
//========================================================================================
|
||||
|
||||
#ifndef _FILESPEC_H_
|
||||
@ -153,8 +149,9 @@
|
||||
//========================================================================================
|
||||
|
||||
class nsFileSpec; // Preferred. For i/o use nsInputFileStream, nsOutputFileStream
|
||||
class nsFilePath; // This can be passed to NSPR file I/O routines, if you must.
|
||||
class nsFilePath;
|
||||
class nsFileURL;
|
||||
class nsNSPRPath; // This can be passed to NSPR file I/O routines, if you must.
|
||||
class nsPersistentFileDescriptor; // Used for storage across program launches.
|
||||
|
||||
#define kFileURLPrefix "file://"
|
||||
@ -167,6 +164,7 @@ class nsIInputStream;
|
||||
class nsOutputFileStream;
|
||||
class nsInputFileStream;
|
||||
class nsOutputConsoleStream;
|
||||
|
||||
class nsString;
|
||||
|
||||
//========================================================================================
|
||||
@ -269,8 +267,12 @@ protected:
|
||||
void ReleaseData();
|
||||
void ReallocData(PRUint32 inLength);
|
||||
|
||||
// DATA
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
struct Data {
|
||||
int mRefCount;
|
||||
PRUint32 mLength;
|
||||
@ -289,8 +291,8 @@ class NS_BASE nsFileSpec
|
||||
nsFileSpec();
|
||||
|
||||
// These two meathods take *native* file paths.
|
||||
NS_EXPLICIT nsFileSpec(const char* inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const nsString& inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const char* inNativePath, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const nsString& inNativePath, PRBool inCreateDirs = PR_FALSE);
|
||||
|
||||
|
||||
NS_EXPLICIT nsFileSpec(const nsFilePath& inPath);
|
||||
@ -300,10 +302,10 @@ class NS_BASE nsFileSpec
|
||||
virtual ~nsFileSpec();
|
||||
|
||||
// These two operands take *native* file paths.
|
||||
void operator = (const char* inPath);
|
||||
void operator = (const nsString& inPath)
|
||||
void operator = (const char* inNativePath);
|
||||
void operator = (const nsString& inNativePath)
|
||||
{
|
||||
const nsAutoCString path(inPath);
|
||||
const nsAutoCString path(inNativePath);
|
||||
*this = path;
|
||||
}
|
||||
|
||||
@ -317,14 +319,19 @@ class NS_BASE nsFileSpec
|
||||
|
||||
operator const char* () const { return GetCString(); }
|
||||
// Same as GetCString (please read the comments).
|
||||
// Do not try to free this!
|
||||
const char* GetNativePathCString() const { return GetCString(); }
|
||||
// Same as GetCString (please read the comments).
|
||||
// Do not try to free this!
|
||||
const char* GetCString() const;
|
||||
// This is the only conversion to const char*
|
||||
// that is provided, and it allows the
|
||||
// Returns a native path, and allows the
|
||||
// path to be "passed" to legacy code. This practice
|
||||
// is VERY EVIL and should only be used to support legacy
|
||||
// code. Using it guarantees bugs on Macintosh.
|
||||
// The path is cached and freed by the nsFileSpec destructor
|
||||
// so do not delete (or free) it.
|
||||
// so do not delete (or free) it. See also nsNSPRPath below,
|
||||
// if you really must pass a string to PR_OpenFile().
|
||||
// Doing so will introduce two automatic bugs.
|
||||
|
||||
#ifdef XP_MAC
|
||||
// For Macintosh people, this is meant to be useful in its own right as a C++ version
|
||||
@ -367,22 +374,15 @@ class NS_BASE nsFileSpec
|
||||
{
|
||||
#ifndef XP_MAC
|
||||
if (mPath.IsEmpty() && NS_SUCCEEDED(mError))
|
||||
((nsFileSpec*)this)->mError = NS_FILE_FAILURE;
|
||||
((nsFileSpec*)this)->mError = NS_ERROR_NOT_INITIALIZED;
|
||||
#endif
|
||||
return mError;
|
||||
}
|
||||
PRBool Failed() const { return (PRBool)NS_FAILED(Error()); }
|
||||
|
||||
|
||||
friend NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream& s,
|
||||
const nsFileSpec& spec); // THIS IS FOR DEBUGGING ONLY.
|
||||
// see PersistentFileDescriptor for the real deal.
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
char* GetLeafName() const; // Allocated. Use nsCRT::free().
|
||||
void SetLeafName(const char* inLeafName);
|
||||
@ -422,14 +422,14 @@ class NS_BASE nsFileSpec
|
||||
PRUint32 GetFileSize() const;
|
||||
PRUint32 GetDiskSpaceAvailable() const;
|
||||
|
||||
nsFileSpec operator + (const char* inRelativePath) const;
|
||||
nsFileSpec operator + (const nsString& inRelativePath) const
|
||||
nsFileSpec operator + (const char* inRelativeUnixPath) const;
|
||||
nsFileSpec operator + (const nsString& inRelativeUnixPath) const
|
||||
{
|
||||
const nsAutoCString
|
||||
relativePath(inRelativePath);
|
||||
relativePath(inRelativeUnixPath);
|
||||
return *this + relativePath;
|
||||
}
|
||||
void operator += (const char* inRelativePath);
|
||||
void operator += (const char* inRelativeUnixPath);
|
||||
// Concatenate the relative path to this directory.
|
||||
// Used for constructing the filespec of a descendant.
|
||||
// This must be a directory for this to work. This differs
|
||||
@ -438,9 +438,9 @@ class NS_BASE nsFileSpec
|
||||
// away its leaf information, whereas this one assumes
|
||||
// this is a directory, and the relative path starts
|
||||
// "below" this.
|
||||
void operator += (const nsString& inRelativePath)
|
||||
void operator += (const nsString& inRelativeUnixPath)
|
||||
{
|
||||
const nsAutoCString relativePath(inRelativePath);
|
||||
const nsAutoCString relativePath(inRelativeUnixPath);
|
||||
*this += relativePath;
|
||||
}
|
||||
|
||||
@ -458,9 +458,9 @@ class NS_BASE nsFileSpec
|
||||
// More stringent than Exists()
|
||||
PRBool Exists() const;
|
||||
|
||||
//--------------------------------------------------
|
||||
// Creation and deletion of objects. These can modify the disk.
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Creation and deletion of objects. These can modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
void CreateDirectory(int mode = 0700 /* for unix */);
|
||||
void CreateDir(int mode = 0700) { CreateDirectory(mode); }
|
||||
@ -481,9 +481,9 @@ class NS_BASE nsFileSpec
|
||||
const nsAutoCString argsString(args);
|
||||
return Execute(argsString);
|
||||
}
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
friend class nsFilePath;
|
||||
@ -509,8 +509,8 @@ class NS_BASE nsFileURL
|
||||
{
|
||||
public:
|
||||
nsFileURL(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFileURL(const char* inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsString& inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const char* inURLString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsString& inURLString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFileURL(const nsFileSpec& inPath);
|
||||
virtual ~nsFileURL();
|
||||
@ -520,10 +520,10 @@ class NS_BASE nsFileURL
|
||||
// but should not provide a conversion constructor.
|
||||
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const char* inString);
|
||||
void operator = (const nsString& inString)
|
||||
void operator = (const char* inURLString);
|
||||
void operator = (const nsString& inURLString)
|
||||
{
|
||||
const nsAutoCString string(inString);
|
||||
const nsAutoCString string(inURLString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const nsFilePath& inOther);
|
||||
@ -532,16 +532,20 @@ class NS_BASE nsFileURL
|
||||
void operator +=(const char* inRelativeUnixPath);
|
||||
nsFileURL operator +(const char* inRelativeUnixPath) const;
|
||||
operator const char* () const { return (const char*)mURL; } // deprecated.
|
||||
const char* GetURLString() const { return (const char*)mURL; }
|
||||
// Not allocated, so don't free it.
|
||||
const char* GetAsString() const { return (const char*)mURL; }
|
||||
|
||||
friend NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream& s, const nsFileURL& spec);
|
||||
// Not allocated, so don't free it.
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Accessor to allow quick assignment to a mFileSpec
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
friend class nsFilePath; // to allow construction of nsFilePath
|
||||
nsSimpleCharString mURL;
|
||||
@ -562,8 +566,8 @@ class NS_BASE nsFilePath
|
||||
{
|
||||
public:
|
||||
nsFilePath(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFilePath(const char* inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsString& inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const char* inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsString& inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFilePath(const nsFileSpec& inPath);
|
||||
virtual ~nsFilePath();
|
||||
@ -572,13 +576,13 @@ class NS_BASE nsFilePath
|
||||
operator const char* () const { return mPath; }
|
||||
// This will return a UNIX string. If you
|
||||
// need a string that can be passed into
|
||||
// NSPR, take a look at the nsprPath class.
|
||||
// NSPR, take a look at the nsNSPRPath class.
|
||||
|
||||
void operator = (const nsFilePath& inPath);
|
||||
void operator = (const char* inString);
|
||||
void operator = (const nsString& inString)
|
||||
void operator = (const char* inUnixPathString);
|
||||
void operator = (const nsString& inUnixPathString)
|
||||
{
|
||||
const nsAutoCString string(inString);
|
||||
const nsAutoCString string(inUnixPathString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const nsFileURL& inURL);
|
||||
@ -593,6 +597,10 @@ class NS_BASE nsFilePath
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsSimpleCharString mPath;
|
||||
@ -622,8 +630,11 @@ class NS_BASE nsPersistentFileDescriptor
|
||||
NS_EXPLICIT nsPersistentFileDescriptor(const nsFileSpec& inPath);
|
||||
void operator = (const nsFileSpec& inPath);
|
||||
|
||||
nsresult Read(nsIInputStream* aStream);
|
||||
nsresult Write(nsIOutputStream* aStream);
|
||||
// The following four functions are declared here (as friends). Their implementations
|
||||
// are in mozilla/base/src/nsFileSpecStreaming.cpp.
|
||||
|
||||
friend nsresult Read(nsIInputStream* aStream, nsPersistentFileDescriptor&);
|
||||
friend nsresult Write(nsIOutputStream* aStream, const nsPersistentFileDescriptor&);
|
||||
// writes the data to a file
|
||||
friend NS_BASE nsInputStream& operator >> (nsInputStream&, nsPersistentFileDescriptor&);
|
||||
// reads the data from a file
|
||||
@ -631,11 +642,15 @@ class NS_BASE nsPersistentFileDescriptor
|
||||
// writes the data to a file
|
||||
friend class nsFileSpec;
|
||||
|
||||
private:
|
||||
|
||||
void GetData(nsSimpleCharString& outData) const;
|
||||
void SetData(const nsSimpleCharString& inData);
|
||||
void GetData(nsSimpleCharString& outData, PRInt32& outSize) const;
|
||||
void SetData(const nsSimpleCharString& inData, PRInt32 inSize);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
nsSimpleCharString mDescriptorString;
|
||||
@ -654,7 +669,7 @@ class NS_BASE nsDirectoryIterator
|
||||
//
|
||||
// or:
|
||||
//
|
||||
// for (nsDirectoryIterator i(parentDir, PR_FALSE); i.Exists(); i--)
|
||||
// for (nsDirectoryIterator i(parentDir, -1); i.Exists(); i--)
|
||||
// {
|
||||
// // do something with i.Spec()
|
||||
// }
|
||||
@ -681,6 +696,17 @@ class NS_BASE nsDirectoryIterator
|
||||
nsFileSpec& Spec() { return mCurrent; }
|
||||
|
||||
private:
|
||||
|
||||
#if defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsFileSpec mCurrent;
|
||||
PRBool mExists;
|
||||
|
||||
@ -689,35 +715,44 @@ class NS_BASE nsDirectoryIterator
|
||||
#elif defined(XP_PC)
|
||||
PRDir* mDir; // XXX why not use PRDir for Unix too?
|
||||
#elif defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
short mIndex;
|
||||
short mMaxIndex;
|
||||
#endif
|
||||
}; // class nsDirectoryIterator
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsprPath
|
||||
class NS_BASE nsNSPRPath
|
||||
// This class will allow you to pass any one of the nsFile* classes directly into NSPR
|
||||
// without the need to worry about whether you have the right kind of filepath or not.
|
||||
// It will also take care of cleaning up any allocated memory.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
NS_EXPLICIT nsprPath(const nsFileSpec& other)
|
||||
: mFilePath(other), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsprPath(const nsFileURL& other)
|
||||
: mFilePath(other), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsprPath(const nsFilePath& other)
|
||||
: mFilePath(other), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFileSpec& inSpec)
|
||||
: mFilePath(inSpec), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFileURL& inURL)
|
||||
: mFilePath(inURL), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFilePath& inUnixPath)
|
||||
: mFilePath(inUnixPath), modifiedNSPRPath(nsnull) {}
|
||||
|
||||
virtual ~nsprPath();
|
||||
virtual ~nsNSPRPath();
|
||||
|
||||
operator const char*() const;
|
||||
// actually, can modify modifiedNSPRPath, but
|
||||
// that's really just "mutable".
|
||||
// Returns the path
|
||||
// that NSPR file routines expect on each platform.
|
||||
// Concerning constness, this can modify
|
||||
// modifiedNSPRPath, but it's really just "mutable".
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
nsFilePath mFilePath;
|
||||
char* modifiedNSPRPath; // Currently used only on XP_PC
|
||||
}; // class nsprPath
|
||||
|
||||
nsFilePath mFilePath;
|
||||
char* modifiedNSPRPath; // Currently used only on XP_PC
|
||||
}; // class nsNSPRPath
|
||||
|
||||
typedef nsNSPRPath nsprPath; // old name.
|
||||
|
||||
#endif // _FILESPEC_H_
|
||||
|
@ -40,6 +40,7 @@ CPPSRCS = \
|
||||
nsDeque.cpp \
|
||||
nsEscape.cpp \
|
||||
nsFileSpec.cpp \
|
||||
nsFileSpecStreaming.cpp \
|
||||
nsFileStream.cpp \
|
||||
nsIFileStream.cpp \
|
||||
nsIStringStream.cpp \
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -78,6 +78,7 @@ CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsUnicharInputStream.obj \
|
||||
.\$(OBJDIR)\nsVoidArray.obj \
|
||||
.\$(OBJDIR)\nsFileSpec.obj \
|
||||
.\$(OBJDIR)\nsFileSpecStreaming.obj \
|
||||
.\$(OBJDIR)\nsFileStream.obj \
|
||||
.\$(OBJDIR)\nsEscape.obj \
|
||||
.\$(OBJDIR)\nsIFileStream.obj \
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "nsFileStream.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
@ -596,13 +595,6 @@ void nsFileURL::operator = (const nsFileSpec& inOther)
|
||||
} // nsFileURL::operator =
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsFileURL& url)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (s << url.mURL);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsFilePath implementation
|
||||
//========================================================================================
|
||||
@ -691,15 +683,12 @@ void nsFilePath::operator = (const nsFileSpec& inOther)
|
||||
}
|
||||
#endif // XP_UNIX
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsFilePath::operator = (const char* inString)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_ASSERTION(strstr(inString, kFileURLPrefix) != inString, "URL passed as path");
|
||||
#ifdef XP_MAC
|
||||
mFileSpec = inString;
|
||||
mPath = (const char*)nsFilePath(mFileSpec);
|
||||
#else
|
||||
mPath = inString;
|
||||
#ifdef XP_PC
|
||||
nsFileSpecHelpers::UnixToNative(mPath);
|
||||
@ -709,8 +698,8 @@ void nsFilePath::operator = (const char* inString)
|
||||
#ifdef XP_PC
|
||||
nsFileSpecHelpers::NativeToUnix(mPath);
|
||||
#endif
|
||||
#endif // XP_MAC
|
||||
}
|
||||
#endif // XP_MAC
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -945,23 +934,6 @@ void nsFileSpec::operator = (const char* inString)
|
||||
}
|
||||
#endif //XP_UNIX
|
||||
|
||||
#if (defined(XP_UNIX) || defined(XP_PC))
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsFileSpec& spec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool warnedOnce = PR_FALSE;
|
||||
if (!warnedOnce)
|
||||
{
|
||||
NS_WARNING("This is for debugging only. Do not call this in shipped version!");
|
||||
warnedOnce = PR_TRUE;
|
||||
}
|
||||
#endif // NS_DEBUG
|
||||
return (s << spec.GetCString());
|
||||
}
|
||||
#endif // DEBUG ONLY!
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsFileSpec nsFileSpec::operator + (const char* inRelativePath) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1077,6 +1049,20 @@ nsPersistentFileDescriptor::~nsPersistentFileDescriptor()
|
||||
{
|
||||
} // nsPersistentFileDescriptor::~nsPersistentFileDescriptor
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsPersistentFileDescriptor::GetData(nsSimpleCharString& outData) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
outData = mDescriptorString;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsPersistentFileDescriptor::SetData(const nsSimpleCharString& inData)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
SetData(inData, inData.Length());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsPersistentFileDescriptor::GetData(nsSimpleCharString& outData, PRInt32& outSize) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1092,70 +1078,6 @@ void nsPersistentFileDescriptor::SetData(const nsSimpleCharString& inData, PRInt
|
||||
mDescriptorString.CopyFrom((const char*)inData, inSize);
|
||||
}
|
||||
|
||||
#define MAX_PERSISTENT_DATA_SIZE 1000
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsPersistentFileDescriptor::Read(nsIInputStream* aStream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsInputStream inputStream(aStream);
|
||||
inputStream >> *this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsPersistentFileDescriptor::Write(nsIOutputStream* aStream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsOutputStream outputStream(aStream);
|
||||
outputStream << *this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStream& operator >> (nsInputStream& s, nsPersistentFileDescriptor& d)
|
||||
// reads the data from a file
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char bigBuffer[MAX_PERSISTENT_DATA_SIZE + 1];
|
||||
// The first 8 bytes of the data should be a hex version of the data size to follow.
|
||||
PRInt32 bytesRead = 8;
|
||||
bytesRead = s.read(bigBuffer, bytesRead);
|
||||
if (bytesRead != 8)
|
||||
return s;
|
||||
bigBuffer[8] = '\0';
|
||||
sscanf(bigBuffer, "%x", (PRUint32*)&bytesRead);
|
||||
if (bytesRead > MAX_PERSISTENT_DATA_SIZE)
|
||||
{
|
||||
// Try to tolerate encoded values with no length header
|
||||
bytesRead = 8 + s.read(bigBuffer + 8, MAX_PERSISTENT_DATA_SIZE - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now we know how many bytes to read, do it.
|
||||
bytesRead = s.read(bigBuffer, bytesRead);
|
||||
}
|
||||
d.SetData(bigBuffer, bytesRead);
|
||||
return s;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsPersistentFileDescriptor& d)
|
||||
// writes the data to a file
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char littleBuf[9];
|
||||
PRInt32 dataSize;
|
||||
nsSimpleCharString data;
|
||||
d.GetData(data, dataSize);
|
||||
// First write (in hex) the length of the data to follow. Exactly 8 bytes
|
||||
sprintf(littleBuf, "%0.8x", dataSize);
|
||||
s << littleBuf;
|
||||
// Now write the data itself
|
||||
s << (const char*)data;
|
||||
return s;
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// class nsAutoCString
|
||||
//========================================================================================
|
||||
@ -1168,11 +1090,11 @@ nsAutoCString::~nsAutoCString()
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// class nsprPath
|
||||
// class nsNSPRPath
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsprPath::operator const char*() const
|
||||
nsNSPRPath::operator const char*() const
|
||||
// NSPR expects a UNIX path on unix and Macintosh, but a native path on windows. NSPR
|
||||
// cannot be changed, so we have to do the dirty work.
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1186,7 +1108,7 @@ nsprPath::operator const char*() const
|
||||
if (!unixPath)
|
||||
return nsnull;
|
||||
|
||||
((nsprPath*)this)->modifiedNSPRPath
|
||||
((nsNSPRPath*)this)->modifiedNSPRPath
|
||||
= nsCRT::strdup(*unixPath == '/' ? unixPath + 1: unixPath);
|
||||
|
||||
// Replace the bar
|
||||
@ -1205,7 +1127,7 @@ nsprPath::operator const char*() const
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsprPath::~nsprPath()
|
||||
nsNSPRPath::~nsNSPRPath()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_PC
|
||||
|
@ -177,7 +177,7 @@ PRBool nsFileSpec::Exists() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
return !mPath.IsEmpty() && 0 == stat(nsprPath(*this), &st);
|
||||
return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st);
|
||||
} // nsFileSpec::Exists
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -185,7 +185,7 @@ void nsFileSpec::GetModDate(TimeStamp& outStamp) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
if (!mPath.IsEmpty() && stat(nsprPath(*this), &st) == 0)
|
||||
if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
|
||||
outStamp = st.st_mtime;
|
||||
else
|
||||
outStamp = 0;
|
||||
@ -196,7 +196,7 @@ PRUint32 nsFileSpec::GetFileSize() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
if (!mPath.IsEmpty() && stat(nsprPath(*this), &st) == 0)
|
||||
if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
|
||||
return (PRUint32)st.st_size;
|
||||
return 0;
|
||||
} // nsFileSpec::GetFileSize
|
||||
@ -206,7 +206,7 @@ PRBool nsFileSpec::IsFile() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
return !mPath.IsEmpty() && 0 == stat(nsprPath(*this), &st) && (_S_IFREG & st.st_mode);
|
||||
return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFREG & st.st_mode);
|
||||
} // nsFileSpec::IsFile
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -214,7 +214,7 @@ PRBool nsFileSpec::IsDirectory() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
return !mPath.IsEmpty() && 0 == stat(nsprPath(*this), &st) && (_S_IFDIR & st.st_mode);
|
||||
return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFDIR & st.st_mode);
|
||||
} // nsFileSpec::IsDirectory
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -253,7 +253,7 @@ void nsFileSpec::CreateDirectory(int /*mode*/)
|
||||
{
|
||||
// Note that mPath is canonical!
|
||||
if (!mPath.IsEmpty())
|
||||
mkdir(nsprPath(*this));
|
||||
mkdir(nsNSPRPath(*this));
|
||||
} // nsFileSpec::CreateDirectory
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -270,11 +270,11 @@ void nsFileSpec::Delete(PRBool inRecursive) const
|
||||
child.Delete(inRecursive);
|
||||
}
|
||||
}
|
||||
rmdir(nsprPath(*this));
|
||||
rmdir(nsNSPRPath(*this));
|
||||
}
|
||||
else if (!mPath.IsEmpty())
|
||||
{
|
||||
remove(nsprPath(*this));
|
||||
remove(nsNSPRPath(*this));
|
||||
}
|
||||
} // nsFileSpec::Delete
|
||||
|
||||
|
@ -43,6 +43,7 @@ struct FilesTest
|
||||
int CanonicalPath(const char* relativePath);
|
||||
int Persistence(const char* relativePath);
|
||||
int FileSpecEquality(const char *aFile, const char *bFile);
|
||||
int FileSpecAppend(nsFileSpec& parent, const char* relativePath);
|
||||
int Copy(const char* sourceFile, const char* targDir);
|
||||
int Move(const char* sourceFile, const char* targDir);
|
||||
int Rename(const char* sourceFile, const char* newName);
|
||||
@ -51,12 +52,12 @@ struct FilesTest
|
||||
|
||||
int SpecialSystemDirectories();
|
||||
|
||||
int NSPRCompatiblity(const char* sourceFile);
|
||||
int NSPRCompatibility(const char* sourceFile);
|
||||
|
||||
void Banner(const char* bannerString);
|
||||
int Passed();
|
||||
int Failed(const char* explanation = nsnull);
|
||||
void Inspect();
|
||||
int Inspect();
|
||||
|
||||
nsOutputConsoleStream mConsole;
|
||||
};
|
||||
@ -92,10 +93,11 @@ int FilesTest::Failed(const char* explanation)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Inspect()
|
||||
int FilesTest::Inspect()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << nsEndl << "^^^^^^^^^^ PLEASE INSPECT OUTPUT FOR ERRORS" << nsEndl;
|
||||
return 0; // for convenience
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -136,12 +138,12 @@ void FilesTest::WriteStuff(nsOutputStream& s)
|
||||
} // WriteStuff
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::OutputStream(const char* relativePath)
|
||||
int FilesTest::OutputStream(const char* relativeUnixPath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFilePath myTextFilePath(relativeUnixPath, PR_TRUE); // convert to full path.
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
const char* pathAsString = (const char*)mySpec;
|
||||
{
|
||||
mConsole << "WRITING IDENTICAL OUTPUT TO " << pathAsString << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(mySpec);
|
||||
@ -166,7 +168,7 @@ int FilesTest::OutputStream(const char* relativePath)
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
FileSizeAndDate(relativePath);
|
||||
FileSizeAndDate(relativeUnixPath);
|
||||
return Passed();
|
||||
}
|
||||
|
||||
@ -310,8 +312,7 @@ int FilesTest::InputStream(const char* relativePath)
|
||||
testStream2.readline(line, sizeof(line));
|
||||
mConsole << line << nsEndl;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
return Inspect();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -356,8 +357,7 @@ int FilesTest::Parent(
|
||||
<< "\n or as a URL"
|
||||
<< "\n\t" << (const char*)url
|
||||
<< nsEndl;
|
||||
Inspect();
|
||||
return 0;
|
||||
return Inspect();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -429,17 +429,18 @@ int FilesTest::CreateDirectory(nsFileSpec& dirSpec)
|
||||
int FilesTest::CreateDirectoryRecursive(const char* aPath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirSpec(aPath, PR_TRUE);
|
||||
nsFilePath dirPath(aPath, PR_TRUE);
|
||||
mConsole
|
||||
<< "Testing nsFilePath(X, PR_TRUE) using"
|
||||
<< "\n\t" << (const char*)aPath
|
||||
<< nsEndl;
|
||||
|
||||
return Passed();
|
||||
|
||||
nsFileSpec spec(dirPath);
|
||||
if (spec.Valid())
|
||||
return Passed();
|
||||
return Failed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -465,8 +466,7 @@ int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
nsCRT::free(itemName);
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
return Inspect();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -491,13 +491,38 @@ int FilesTest::CanonicalPath(
|
||||
return Passed();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::FileSpecAppend(nsFileSpec& parent, const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath initialPath(parent);
|
||||
const char* initialPathString = (const char*)initialPath;
|
||||
mConsole << "Initial nsFileSpec:\n\t\"" << initialPathString << "\"" << nsEndl;
|
||||
|
||||
nsFileSpec fileSpec(initialPath);
|
||||
|
||||
mConsole << "Appending:\t\"" << relativePath << "\"" << nsEndl;
|
||||
|
||||
fileSpec += relativePath;
|
||||
|
||||
nsFilePath resultPath(fileSpec);
|
||||
const char* resultPathString = (const char*)resultPath;
|
||||
mConsole << "Result:\n\t\"" << resultPathString << "\"" << nsEndl;
|
||||
|
||||
return Inspect();
|
||||
} // FilesTest::FileSpecAppend
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::FileSpecEquality(const char *aFile, const char *bFile)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec aFileSpec(aFile, PR_FALSE);
|
||||
nsFileSpec bFileSpec(bFile, PR_FALSE);
|
||||
nsFileSpec cFileSpec(bFile, PR_FALSE); // this should == bFile
|
||||
nsFilePath aFilePath(aFile, PR_TRUE);
|
||||
nsFilePath bFilePath(bFile, PR_TRUE);
|
||||
|
||||
|
||||
nsFileSpec aFileSpec(aFilePath);
|
||||
nsFileSpec bFileSpec(bFilePath);
|
||||
nsFileSpec cFileSpec(bFilePath); // this should == bFile
|
||||
|
||||
if (aFileSpec != bFileSpec &&
|
||||
bFileSpec == cFileSpec )
|
||||
@ -506,26 +531,26 @@ int FilesTest::FileSpecEquality(const char *aFile, const char *bFile)
|
||||
}
|
||||
|
||||
return Failed();
|
||||
}
|
||||
} // FilesTest::FileSpecEquality
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Copy(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
nsFileSpec dirPath(nsFilePath(dir, PR_TRUE));
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec mySpec(file, PR_TRUE); // relative path.
|
||||
nsFileSpec mySpec(nsFilePath(file, PR_TRUE)); // relative path.
|
||||
{
|
||||
nsIOFileStream testStream(mySpec); // creates the file
|
||||
// Scope ends here, file gets closed
|
||||
}
|
||||
|
||||
nsFileSpec filePath(file);
|
||||
nsFileSpec filePath(nsFilePath(file, PR_TRUE));
|
||||
if (! filePath.Exists())
|
||||
return Failed();
|
||||
|
||||
@ -545,14 +570,14 @@ int FilesTest::Copy(const char* file, const char* dir)
|
||||
int FilesTest::Move(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
nsFileSpec dirPath(nsFilePath(dir, PR_TRUE));
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec srcSpec(file, PR_TRUE); // relative path.
|
||||
nsFileSpec srcSpec(nsFilePath(file, PR_TRUE)); // relative path.
|
||||
{
|
||||
nsIOFileStream testStream(srcSpec); // creates the file
|
||||
// file gets closed here because scope ends here.
|
||||
@ -576,11 +601,12 @@ int FilesTest::Move(const char* file, const char* dir)
|
||||
int FilesTest::Execute(const char* appName, const char* args)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec appPath(appName, PR_FALSE);
|
||||
if (!appPath.Exists())
|
||||
mConsole << "Attempting to execute " << appName << nsEndl;
|
||||
nsFileSpec appSpec(appName, PR_FALSE);
|
||||
if (!appSpec.Exists())
|
||||
return Failed();
|
||||
|
||||
nsresult error = appPath.Execute(args);
|
||||
nsresult error = appSpec.Execute(args);
|
||||
if (NS_FAILED(error))
|
||||
return Failed();
|
||||
|
||||
@ -588,11 +614,13 @@ int FilesTest::Execute(const char* appName, const char* args)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
int FilesTest::NSPRCompatibility(const char* relativeUnixFilePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
nsFileSpec createTheFileSpec(sourceFile, PR_TRUE); // relative path.
|
||||
nsFilePath filePath(relativeUnixFilePath, PR_TRUE); // relative path
|
||||
|
||||
nsFileSpec createTheFileSpec(filePath);
|
||||
{
|
||||
nsIOFileStream testStream(createTheFileSpec); // creates the file
|
||||
// file gets closed here because scope ends here.
|
||||
@ -600,10 +628,10 @@ int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
|
||||
|
||||
|
||||
nsFilePath filePath(sourceFile, PR_TRUE);
|
||||
PRFileDesc* fOut = NULL;
|
||||
|
||||
fOut = PR_Open( nsprPath(filePath), PR_RDONLY, 0 );
|
||||
// From an nsFilePath
|
||||
fOut = PR_Open( nsNSPRPath(filePath), PR_RDONLY, 0 );
|
||||
if ( fOut == NULL )
|
||||
{
|
||||
return Failed();
|
||||
@ -614,9 +642,10 @@ int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
fOut = NULL;
|
||||
}
|
||||
|
||||
// From an nsFileSpec
|
||||
nsFileSpec fileSpec(filePath);
|
||||
|
||||
fOut = PR_Open( nsprPath(fileSpec), PR_RDONLY, 0 );
|
||||
fOut = PR_Open( nsNSPRPath(fileSpec), PR_RDONLY, 0 );
|
||||
if ( fOut == NULL )
|
||||
{
|
||||
return Failed();
|
||||
@ -627,9 +656,10 @@ int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
fOut = NULL;
|
||||
}
|
||||
|
||||
// From an nsFileURL
|
||||
nsFileURL fileURL(fileSpec);
|
||||
|
||||
fOut = PR_Open( nsprPath(fileURL), PR_RDONLY, 0 );
|
||||
fOut = PR_Open( nsNSPRPath(fileURL), PR_RDONLY, 0 );
|
||||
if ( fOut == NULL )
|
||||
{
|
||||
return Failed();
|
||||
@ -887,84 +917,118 @@ int FilesTest::RunAllTests()
|
||||
// For use with DEBUG defined.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// Test of mConsole output
|
||||
|
||||
int rv = 0;
|
||||
|
||||
// Test of mConsole output
|
||||
mConsole << "WRITING TEST OUTPUT TO CONSOLE" << nsEndl << nsEndl;
|
||||
|
||||
// Test of nsFileSpec
|
||||
|
||||
Banner("Interconversion");
|
||||
WriteStuff(mConsole);
|
||||
Inspect();
|
||||
|
||||
rv = Inspect();
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("Canonical Path");
|
||||
if (CanonicalPath("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = CanonicalPath("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("OutputStream");
|
||||
if (OutputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = OutputStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("InputStream");
|
||||
if (InputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = InputStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("IOStream");
|
||||
if (IOStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = IOStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
FileSizeAndDate("mumble/iotest.txt");
|
||||
|
||||
if (InputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = InputStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("StringStream");
|
||||
if (StringStream() != 0)
|
||||
return -1;
|
||||
rv = StringStream();
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("Parent");
|
||||
nsFileSpec parent;
|
||||
if (Parent("mumble/iotest.txt", parent) != 0)
|
||||
return -1;
|
||||
rv = Parent("mumble/iotest.txt", parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("FileSpec Append using Unix relative path");
|
||||
rv = FileSpecAppend(parent, "nested/unix/file.txt");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
Banner("FileSpec Append using Native relative path");
|
||||
#ifdef XP_PC
|
||||
rv = FileSpecAppend(parent, "nested\\windows\\file.txt");
|
||||
#elif defined(XP_MAC)
|
||||
rv = FileSpecAppend(parent, ":nested:mac:file.txt");
|
||||
#else
|
||||
rv = Passed();
|
||||
#endif // XP_MAC
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Delete");
|
||||
if (Delete(parent) != 0)
|
||||
return -1;
|
||||
rv = Delete(parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("CreateDirectory");
|
||||
if (CreateDirectory(parent) != 0)
|
||||
return -1;
|
||||
rv = CreateDirectory(parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("CreateDirectoryRecursive Relative (using nsFileSpec)");
|
||||
if (CreateDirectoryRecursive("mumble/dir1/dir2/dir3/") != 0)
|
||||
return -1;
|
||||
rv = CreateDirectoryRecursive("mumble/dir1/dir2/dir3/");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
#ifdef XP_PC
|
||||
Banner("CreateDirectoryRecursive Absolute (using nsFileSpec)");
|
||||
if (CreateDirectoryRecursive("c:\\temp\\dir1\\dir2\\dir3\\") != 0)
|
||||
return -1;
|
||||
rv = CreateDirectoryRecursive("c:\\temp\\dir1\\dir2\\dir3\\");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
#endif
|
||||
|
||||
Banner("IterateDirectoryChildren");
|
||||
if (IterateDirectoryChildren(parent) != 0)
|
||||
return -1;
|
||||
rv = IterateDirectoryChildren(parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("nsFileSpec equality");
|
||||
if (FileSpecEquality("mumble/a", "mumble/b") != 0)
|
||||
return -1;
|
||||
rv = FileSpecEquality("mumble/a", "mumble/b");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Copy");
|
||||
if (Copy("mumble/copyfile.txt", "mumble/copy") != 0)
|
||||
return -1;
|
||||
rv = Copy("mumble/copyfile.txt", "mumble/copy");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Move");
|
||||
if (Move("mumble/moveFile.txt", "mumble/move") != 0)
|
||||
return -1;
|
||||
rv = Move("mumble/moveFile.txt", "mumble/move");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Execute");
|
||||
#ifdef XP_MAC
|
||||
// This path is hard-coded to test on jrm's machine. Finding an app
|
||||
// on an arbitrary Macintosh would cost more trouble than it's worth.
|
||||
// Change path to suit.
|
||||
if NS_FAILED(Execute("/Projects/Nav45_BRANCH/ns/cmd/macfe/"\
|
||||
"projects/client45/Client45PPC", ""))
|
||||
// Change path to suit. This is currently a native path, as you can see.
|
||||
if NS_FAILED(Execute("Projects:Nav45_BRANCH:ns:cmd:macfe:"\
|
||||
"projects:client45:Client45PPC", ""))
|
||||
#elif XP_PC
|
||||
if NS_FAILED(Execute("c:\\windows\\notepad.exe", ""))
|
||||
#else
|
||||
@ -972,23 +1036,26 @@ int FilesTest::RunAllTests()
|
||||
#endif
|
||||
return -1;
|
||||
|
||||
Banner("NSPR Compatiblity");
|
||||
if (NSPRCompatiblity("mumble/aFile.txt") != 0)
|
||||
return -1;
|
||||
Banner("NSPR Compatibility");
|
||||
rv = NSPRCompatibility("mumble/aFile.txt");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Special System Directories");
|
||||
if (SpecialSystemDirectories() != 0)
|
||||
return -1;
|
||||
rv = SpecialSystemDirectories();
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Persistence");
|
||||
if (Persistence("mumble/filedesc.dat") != 0)
|
||||
return -1;
|
||||
rv = Persistence("mumble/filedesc.dat");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Clean:
|
||||
Banner("Delete again (to clean up our mess)");
|
||||
if (Delete(parent) != 0)
|
||||
return -1;
|
||||
Delete(parent);
|
||||
|
||||
return 0;
|
||||
return rv;
|
||||
} // FilesTest::RunAllTests
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "nsFileStream.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
@ -596,13 +595,6 @@ void nsFileURL::operator = (const nsFileSpec& inOther)
|
||||
} // nsFileURL::operator =
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsFileURL& url)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
return (s << url.mURL);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsFilePath implementation
|
||||
//========================================================================================
|
||||
@ -691,15 +683,12 @@ void nsFilePath::operator = (const nsFileSpec& inOther)
|
||||
}
|
||||
#endif // XP_UNIX
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsFilePath::operator = (const char* inString)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
NS_ASSERTION(strstr(inString, kFileURLPrefix) != inString, "URL passed as path");
|
||||
#ifdef XP_MAC
|
||||
mFileSpec = inString;
|
||||
mPath = (const char*)nsFilePath(mFileSpec);
|
||||
#else
|
||||
mPath = inString;
|
||||
#ifdef XP_PC
|
||||
nsFileSpecHelpers::UnixToNative(mPath);
|
||||
@ -709,8 +698,8 @@ void nsFilePath::operator = (const char* inString)
|
||||
#ifdef XP_PC
|
||||
nsFileSpecHelpers::NativeToUnix(mPath);
|
||||
#endif
|
||||
#endif // XP_MAC
|
||||
}
|
||||
#endif // XP_MAC
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -945,23 +934,6 @@ void nsFileSpec::operator = (const char* inString)
|
||||
}
|
||||
#endif //XP_UNIX
|
||||
|
||||
#if (defined(XP_UNIX) || defined(XP_PC))
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsFileSpec& spec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool warnedOnce = PR_FALSE;
|
||||
if (!warnedOnce)
|
||||
{
|
||||
NS_WARNING("This is for debugging only. Do not call this in shipped version!");
|
||||
warnedOnce = PR_TRUE;
|
||||
}
|
||||
#endif // NS_DEBUG
|
||||
return (s << spec.GetCString());
|
||||
}
|
||||
#endif // DEBUG ONLY!
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsFileSpec nsFileSpec::operator + (const char* inRelativePath) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1077,6 +1049,20 @@ nsPersistentFileDescriptor::~nsPersistentFileDescriptor()
|
||||
{
|
||||
} // nsPersistentFileDescriptor::~nsPersistentFileDescriptor
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsPersistentFileDescriptor::GetData(nsSimpleCharString& outData) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
outData = mDescriptorString;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsPersistentFileDescriptor::SetData(const nsSimpleCharString& inData)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
SetData(inData, inData.Length());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsPersistentFileDescriptor::GetData(nsSimpleCharString& outData, PRInt32& outSize) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1092,70 +1078,6 @@ void nsPersistentFileDescriptor::SetData(const nsSimpleCharString& inData, PRInt
|
||||
mDescriptorString.CopyFrom((const char*)inData, inSize);
|
||||
}
|
||||
|
||||
#define MAX_PERSISTENT_DATA_SIZE 1000
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsPersistentFileDescriptor::Read(nsIInputStream* aStream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsInputStream inputStream(aStream);
|
||||
inputStream >> *this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsPersistentFileDescriptor::Write(nsIOutputStream* aStream)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsOutputStream outputStream(aStream);
|
||||
outputStream << *this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStream& operator >> (nsInputStream& s, nsPersistentFileDescriptor& d)
|
||||
// reads the data from a file
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char bigBuffer[MAX_PERSISTENT_DATA_SIZE + 1];
|
||||
// The first 8 bytes of the data should be a hex version of the data size to follow.
|
||||
PRInt32 bytesRead = 8;
|
||||
bytesRead = s.read(bigBuffer, bytesRead);
|
||||
if (bytesRead != 8)
|
||||
return s;
|
||||
bigBuffer[8] = '\0';
|
||||
sscanf(bigBuffer, "%x", (PRUint32*)&bytesRead);
|
||||
if (bytesRead > MAX_PERSISTENT_DATA_SIZE)
|
||||
{
|
||||
// Try to tolerate encoded values with no length header
|
||||
bytesRead = 8 + s.read(bigBuffer + 8, MAX_PERSISTENT_DATA_SIZE - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now we know how many bytes to read, do it.
|
||||
bytesRead = s.read(bigBuffer, bytesRead);
|
||||
}
|
||||
d.SetData(bigBuffer, bytesRead);
|
||||
return s;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStream& operator << (nsOutputStream& s, const nsPersistentFileDescriptor& d)
|
||||
// writes the data to a file
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char littleBuf[9];
|
||||
PRInt32 dataSize;
|
||||
nsSimpleCharString data;
|
||||
d.GetData(data, dataSize);
|
||||
// First write (in hex) the length of the data to follow. Exactly 8 bytes
|
||||
sprintf(littleBuf, "%0.8x", dataSize);
|
||||
s << littleBuf;
|
||||
// Now write the data itself
|
||||
s << (const char*)data;
|
||||
return s;
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// class nsAutoCString
|
||||
//========================================================================================
|
||||
@ -1168,11 +1090,11 @@ nsAutoCString::~nsAutoCString()
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// class nsprPath
|
||||
// class nsNSPRPath
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsprPath::operator const char*() const
|
||||
nsNSPRPath::operator const char*() const
|
||||
// NSPR expects a UNIX path on unix and Macintosh, but a native path on windows. NSPR
|
||||
// cannot be changed, so we have to do the dirty work.
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1186,7 +1108,7 @@ nsprPath::operator const char*() const
|
||||
if (!unixPath)
|
||||
return nsnull;
|
||||
|
||||
((nsprPath*)this)->modifiedNSPRPath
|
||||
((nsNSPRPath*)this)->modifiedNSPRPath
|
||||
= nsCRT::strdup(*unixPath == '/' ? unixPath + 1: unixPath);
|
||||
|
||||
// Replace the bar
|
||||
@ -1205,7 +1127,7 @@ nsprPath::operator const char*() const
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsprPath::~nsprPath()
|
||||
nsNSPRPath::~nsNSPRPath()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
#ifdef XP_PC
|
||||
|
@ -53,7 +53,7 @@
|
||||
//
|
||||
// nsFilePath myPath("/Development/iotest.txt");
|
||||
//
|
||||
// nsOutputFileStream testStream(myPath);
|
||||
// nsOutputFileStream testStream(nsFileSpec(myPath));
|
||||
// testStream << "Hello World" << nsEndl;
|
||||
//
|
||||
// 4. Handy methods for manipulating file specifiers safely, e.g. MakeUnique(),
|
||||
@ -63,35 +63,35 @@
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// Initialize a URL from a string without suffix
|
||||
// Initialize a URL from a string
|
||||
//
|
||||
// nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
||||
//
|
||||
// Initialize a Unix path from a URL
|
||||
// Initialize a Unix-style path from a URL
|
||||
//
|
||||
// nsFilePath filePath(fileURL);
|
||||
//
|
||||
// Initialize a native file spec from a URL
|
||||
// Initialize a file spec from a URL
|
||||
//
|
||||
// nsFileSpec fileSpec(fileURL);
|
||||
//
|
||||
// Make the spec unique (this one has no suffix).
|
||||
// Make the spec unique.
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
// Assign the spec to a URL
|
||||
// Assign the spec to a URL (causing conversion)
|
||||
//
|
||||
// fileURL = fileSpec;
|
||||
//
|
||||
// Assign a unix path using a string with a suffix.
|
||||
// Assign a unix path using a string
|
||||
//
|
||||
// filePath = "/Development/MPW/SysErrs.err";
|
||||
//
|
||||
// Assign to a file spec using a unix path.
|
||||
// Assign to a file spec using a unix path (causing conversion).
|
||||
//
|
||||
// fileSpec = filePath;
|
||||
//
|
||||
// Make this unique (this one has a suffix).
|
||||
// Make this unique.
|
||||
//
|
||||
// fileSpec.MakeUnique();
|
||||
//
|
||||
@ -103,10 +103,6 @@
|
||||
// is solved by holding a "private" native file spec inside the
|
||||
// nsFilePath and nsFileURL classes, which is used when appropriate.
|
||||
//
|
||||
// Not yet done:
|
||||
//
|
||||
// Equality operators... much more.
|
||||
//
|
||||
//========================================================================================
|
||||
|
||||
#ifndef _FILESPEC_H_
|
||||
@ -153,8 +149,9 @@
|
||||
//========================================================================================
|
||||
|
||||
class nsFileSpec; // Preferred. For i/o use nsInputFileStream, nsOutputFileStream
|
||||
class nsFilePath; // This can be passed to NSPR file I/O routines, if you must.
|
||||
class nsFilePath;
|
||||
class nsFileURL;
|
||||
class nsNSPRPath; // This can be passed to NSPR file I/O routines, if you must.
|
||||
class nsPersistentFileDescriptor; // Used for storage across program launches.
|
||||
|
||||
#define kFileURLPrefix "file://"
|
||||
@ -167,6 +164,7 @@ class nsIInputStream;
|
||||
class nsOutputFileStream;
|
||||
class nsInputFileStream;
|
||||
class nsOutputConsoleStream;
|
||||
|
||||
class nsString;
|
||||
|
||||
//========================================================================================
|
||||
@ -269,8 +267,12 @@ protected:
|
||||
void ReleaseData();
|
||||
void ReallocData(PRUint32 inLength);
|
||||
|
||||
// DATA
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
struct Data {
|
||||
int mRefCount;
|
||||
PRUint32 mLength;
|
||||
@ -289,8 +291,8 @@ class NS_BASE nsFileSpec
|
||||
nsFileSpec();
|
||||
|
||||
// These two meathods take *native* file paths.
|
||||
NS_EXPLICIT nsFileSpec(const char* inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const nsString& inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const char* inNativePath, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileSpec(const nsString& inNativePath, PRBool inCreateDirs = PR_FALSE);
|
||||
|
||||
|
||||
NS_EXPLICIT nsFileSpec(const nsFilePath& inPath);
|
||||
@ -300,10 +302,10 @@ class NS_BASE nsFileSpec
|
||||
virtual ~nsFileSpec();
|
||||
|
||||
// These two operands take *native* file paths.
|
||||
void operator = (const char* inPath);
|
||||
void operator = (const nsString& inPath)
|
||||
void operator = (const char* inNativePath);
|
||||
void operator = (const nsString& inNativePath)
|
||||
{
|
||||
const nsAutoCString path(inPath);
|
||||
const nsAutoCString path(inNativePath);
|
||||
*this = path;
|
||||
}
|
||||
|
||||
@ -317,14 +319,19 @@ class NS_BASE nsFileSpec
|
||||
|
||||
operator const char* () const { return GetCString(); }
|
||||
// Same as GetCString (please read the comments).
|
||||
// Do not try to free this!
|
||||
const char* GetNativePathCString() const { return GetCString(); }
|
||||
// Same as GetCString (please read the comments).
|
||||
// Do not try to free this!
|
||||
const char* GetCString() const;
|
||||
// This is the only conversion to const char*
|
||||
// that is provided, and it allows the
|
||||
// Returns a native path, and allows the
|
||||
// path to be "passed" to legacy code. This practice
|
||||
// is VERY EVIL and should only be used to support legacy
|
||||
// code. Using it guarantees bugs on Macintosh.
|
||||
// The path is cached and freed by the nsFileSpec destructor
|
||||
// so do not delete (or free) it.
|
||||
// so do not delete (or free) it. See also nsNSPRPath below,
|
||||
// if you really must pass a string to PR_OpenFile().
|
||||
// Doing so will introduce two automatic bugs.
|
||||
|
||||
#ifdef XP_MAC
|
||||
// For Macintosh people, this is meant to be useful in its own right as a C++ version
|
||||
@ -367,22 +374,15 @@ class NS_BASE nsFileSpec
|
||||
{
|
||||
#ifndef XP_MAC
|
||||
if (mPath.IsEmpty() && NS_SUCCEEDED(mError))
|
||||
((nsFileSpec*)this)->mError = NS_FILE_FAILURE;
|
||||
((nsFileSpec*)this)->mError = NS_ERROR_NOT_INITIALIZED;
|
||||
#endif
|
||||
return mError;
|
||||
}
|
||||
PRBool Failed() const { return (PRBool)NS_FAILED(Error()); }
|
||||
|
||||
|
||||
friend NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream& s,
|
||||
const nsFileSpec& spec); // THIS IS FOR DEBUGGING ONLY.
|
||||
// see PersistentFileDescriptor for the real deal.
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Queries and path algebra. These do not modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
char* GetLeafName() const; // Allocated. Use nsCRT::free().
|
||||
void SetLeafName(const char* inLeafName);
|
||||
@ -422,14 +422,14 @@ class NS_BASE nsFileSpec
|
||||
PRUint32 GetFileSize() const;
|
||||
PRUint32 GetDiskSpaceAvailable() const;
|
||||
|
||||
nsFileSpec operator + (const char* inRelativePath) const;
|
||||
nsFileSpec operator + (const nsString& inRelativePath) const
|
||||
nsFileSpec operator + (const char* inRelativeUnixPath) const;
|
||||
nsFileSpec operator + (const nsString& inRelativeUnixPath) const
|
||||
{
|
||||
const nsAutoCString
|
||||
relativePath(inRelativePath);
|
||||
relativePath(inRelativeUnixPath);
|
||||
return *this + relativePath;
|
||||
}
|
||||
void operator += (const char* inRelativePath);
|
||||
void operator += (const char* inRelativeUnixPath);
|
||||
// Concatenate the relative path to this directory.
|
||||
// Used for constructing the filespec of a descendant.
|
||||
// This must be a directory for this to work. This differs
|
||||
@ -438,9 +438,9 @@ class NS_BASE nsFileSpec
|
||||
// away its leaf information, whereas this one assumes
|
||||
// this is a directory, and the relative path starts
|
||||
// "below" this.
|
||||
void operator += (const nsString& inRelativePath)
|
||||
void operator += (const nsString& inRelativeUnixPath)
|
||||
{
|
||||
const nsAutoCString relativePath(inRelativePath);
|
||||
const nsAutoCString relativePath(inRelativeUnixPath);
|
||||
*this += relativePath;
|
||||
}
|
||||
|
||||
@ -458,9 +458,9 @@ class NS_BASE nsFileSpec
|
||||
// More stringent than Exists()
|
||||
PRBool Exists() const;
|
||||
|
||||
//--------------------------------------------------
|
||||
// Creation and deletion of objects. These can modify the disk.
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Creation and deletion of objects. These can modify the disk.
|
||||
//--------------------------------------------------
|
||||
|
||||
void CreateDirectory(int mode = 0700 /* for unix */);
|
||||
void CreateDir(int mode = 0700) { CreateDirectory(mode); }
|
||||
@ -481,9 +481,9 @@ class NS_BASE nsFileSpec
|
||||
const nsAutoCString argsString(args);
|
||||
return Execute(argsString);
|
||||
}
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
friend class nsFilePath;
|
||||
@ -509,8 +509,8 @@ class NS_BASE nsFileURL
|
||||
{
|
||||
public:
|
||||
nsFileURL(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFileURL(const char* inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsString& inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const char* inURLString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsString& inURLString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFileURL(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFileURL(const nsFileSpec& inPath);
|
||||
virtual ~nsFileURL();
|
||||
@ -520,10 +520,10 @@ class NS_BASE nsFileURL
|
||||
// but should not provide a conversion constructor.
|
||||
|
||||
void operator = (const nsFileURL& inURL);
|
||||
void operator = (const char* inString);
|
||||
void operator = (const nsString& inString)
|
||||
void operator = (const char* inURLString);
|
||||
void operator = (const nsString& inURLString)
|
||||
{
|
||||
const nsAutoCString string(inString);
|
||||
const nsAutoCString string(inURLString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const nsFilePath& inOther);
|
||||
@ -532,16 +532,20 @@ class NS_BASE nsFileURL
|
||||
void operator +=(const char* inRelativeUnixPath);
|
||||
nsFileURL operator +(const char* inRelativeUnixPath) const;
|
||||
operator const char* () const { return (const char*)mURL; } // deprecated.
|
||||
const char* GetURLString() const { return (const char*)mURL; }
|
||||
// Not allocated, so don't free it.
|
||||
const char* GetAsString() const { return (const char*)mURL; }
|
||||
|
||||
friend NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream& s, const nsFileURL& spec);
|
||||
// Not allocated, so don't free it.
|
||||
|
||||
#ifdef XP_MAC
|
||||
// Accessor to allow quick assignment to a mFileSpec
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
friend class nsFilePath; // to allow construction of nsFilePath
|
||||
nsSimpleCharString mURL;
|
||||
@ -562,8 +566,8 @@ class NS_BASE nsFilePath
|
||||
{
|
||||
public:
|
||||
nsFilePath(const nsFilePath& inPath);
|
||||
NS_EXPLICIT nsFilePath(const char* inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsString& inString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const char* inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsString& inUnixPathString, PRBool inCreateDirs = PR_FALSE);
|
||||
NS_EXPLICIT nsFilePath(const nsFileURL& inURL);
|
||||
NS_EXPLICIT nsFilePath(const nsFileSpec& inPath);
|
||||
virtual ~nsFilePath();
|
||||
@ -572,13 +576,13 @@ class NS_BASE nsFilePath
|
||||
operator const char* () const { return mPath; }
|
||||
// This will return a UNIX string. If you
|
||||
// need a string that can be passed into
|
||||
// NSPR, take a look at the nsprPath class.
|
||||
// NSPR, take a look at the nsNSPRPath class.
|
||||
|
||||
void operator = (const nsFilePath& inPath);
|
||||
void operator = (const char* inString);
|
||||
void operator = (const nsString& inString)
|
||||
void operator = (const char* inUnixPathString);
|
||||
void operator = (const nsString& inUnixPathString)
|
||||
{
|
||||
const nsAutoCString string(inString);
|
||||
const nsAutoCString string(inUnixPathString);
|
||||
*this = string;
|
||||
}
|
||||
void operator = (const nsFileURL& inURL);
|
||||
@ -593,6 +597,10 @@ class NS_BASE nsFilePath
|
||||
const nsFileSpec& GetFileSpec() const { return mFileSpec; }
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsSimpleCharString mPath;
|
||||
@ -622,8 +630,11 @@ class NS_BASE nsPersistentFileDescriptor
|
||||
NS_EXPLICIT nsPersistentFileDescriptor(const nsFileSpec& inPath);
|
||||
void operator = (const nsFileSpec& inPath);
|
||||
|
||||
nsresult Read(nsIInputStream* aStream);
|
||||
nsresult Write(nsIOutputStream* aStream);
|
||||
// The following four functions are declared here (as friends). Their implementations
|
||||
// are in mozilla/base/src/nsFileSpecStreaming.cpp.
|
||||
|
||||
friend nsresult Read(nsIInputStream* aStream, nsPersistentFileDescriptor&);
|
||||
friend nsresult Write(nsIOutputStream* aStream, const nsPersistentFileDescriptor&);
|
||||
// writes the data to a file
|
||||
friend NS_BASE nsInputStream& operator >> (nsInputStream&, nsPersistentFileDescriptor&);
|
||||
// reads the data from a file
|
||||
@ -631,11 +642,15 @@ class NS_BASE nsPersistentFileDescriptor
|
||||
// writes the data to a file
|
||||
friend class nsFileSpec;
|
||||
|
||||
private:
|
||||
|
||||
void GetData(nsSimpleCharString& outData) const;
|
||||
void SetData(const nsSimpleCharString& inData);
|
||||
void GetData(nsSimpleCharString& outData, PRInt32& outSize) const;
|
||||
void SetData(const nsSimpleCharString& inData, PRInt32 inSize);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
nsSimpleCharString mDescriptorString;
|
||||
@ -654,7 +669,7 @@ class NS_BASE nsDirectoryIterator
|
||||
//
|
||||
// or:
|
||||
//
|
||||
// for (nsDirectoryIterator i(parentDir, PR_FALSE); i.Exists(); i--)
|
||||
// for (nsDirectoryIterator i(parentDir, -1); i.Exists(); i--)
|
||||
// {
|
||||
// // do something with i.Spec()
|
||||
// }
|
||||
@ -681,6 +696,17 @@ class NS_BASE nsDirectoryIterator
|
||||
nsFileSpec& Spec() { return mCurrent; }
|
||||
|
||||
private:
|
||||
|
||||
#if defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
nsFileSpec mCurrent;
|
||||
PRBool mExists;
|
||||
|
||||
@ -689,35 +715,44 @@ class NS_BASE nsDirectoryIterator
|
||||
#elif defined(XP_PC)
|
||||
PRDir* mDir; // XXX why not use PRDir for Unix too?
|
||||
#elif defined(XP_MAC)
|
||||
OSErr SetToIndex();
|
||||
short mIndex;
|
||||
short mMaxIndex;
|
||||
#endif
|
||||
}; // class nsDirectoryIterator
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsprPath
|
||||
class NS_BASE nsNSPRPath
|
||||
// This class will allow you to pass any one of the nsFile* classes directly into NSPR
|
||||
// without the need to worry about whether you have the right kind of filepath or not.
|
||||
// It will also take care of cleaning up any allocated memory.
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
NS_EXPLICIT nsprPath(const nsFileSpec& other)
|
||||
: mFilePath(other), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsprPath(const nsFileURL& other)
|
||||
: mFilePath(other), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsprPath(const nsFilePath& other)
|
||||
: mFilePath(other), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFileSpec& inSpec)
|
||||
: mFilePath(inSpec), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFileURL& inURL)
|
||||
: mFilePath(inURL), modifiedNSPRPath(nsnull) {}
|
||||
NS_EXPLICIT nsNSPRPath(const nsFilePath& inUnixPath)
|
||||
: mFilePath(inUnixPath), modifiedNSPRPath(nsnull) {}
|
||||
|
||||
virtual ~nsprPath();
|
||||
virtual ~nsNSPRPath();
|
||||
|
||||
operator const char*() const;
|
||||
// actually, can modify modifiedNSPRPath, but
|
||||
// that's really just "mutable".
|
||||
// Returns the path
|
||||
// that NSPR file routines expect on each platform.
|
||||
// Concerning constness, this can modify
|
||||
// modifiedNSPRPath, but it's really just "mutable".
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
private:
|
||||
nsFilePath mFilePath;
|
||||
char* modifiedNSPRPath; // Currently used only on XP_PC
|
||||
}; // class nsprPath
|
||||
|
||||
nsFilePath mFilePath;
|
||||
char* modifiedNSPRPath; // Currently used only on XP_PC
|
||||
}; // class nsNSPRPath
|
||||
|
||||
typedef nsNSPRPath nsprPath; // old name.
|
||||
|
||||
#endif // _FILESPEC_H_
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -177,7 +177,7 @@ PRBool nsFileSpec::Exists() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
return !mPath.IsEmpty() && 0 == stat(nsprPath(*this), &st);
|
||||
return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st);
|
||||
} // nsFileSpec::Exists
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -185,7 +185,7 @@ void nsFileSpec::GetModDate(TimeStamp& outStamp) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
if (!mPath.IsEmpty() && stat(nsprPath(*this), &st) == 0)
|
||||
if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
|
||||
outStamp = st.st_mtime;
|
||||
else
|
||||
outStamp = 0;
|
||||
@ -196,7 +196,7 @@ PRUint32 nsFileSpec::GetFileSize() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
if (!mPath.IsEmpty() && stat(nsprPath(*this), &st) == 0)
|
||||
if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
|
||||
return (PRUint32)st.st_size;
|
||||
return 0;
|
||||
} // nsFileSpec::GetFileSize
|
||||
@ -206,7 +206,7 @@ PRBool nsFileSpec::IsFile() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
return !mPath.IsEmpty() && 0 == stat(nsprPath(*this), &st) && (_S_IFREG & st.st_mode);
|
||||
return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFREG & st.st_mode);
|
||||
} // nsFileSpec::IsFile
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -214,7 +214,7 @@ PRBool nsFileSpec::IsDirectory() const
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
struct stat st;
|
||||
return !mPath.IsEmpty() && 0 == stat(nsprPath(*this), &st) && (_S_IFDIR & st.st_mode);
|
||||
return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFDIR & st.st_mode);
|
||||
} // nsFileSpec::IsDirectory
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -253,7 +253,7 @@ void nsFileSpec::CreateDirectory(int /*mode*/)
|
||||
{
|
||||
// Note that mPath is canonical!
|
||||
if (!mPath.IsEmpty())
|
||||
mkdir(nsprPath(*this));
|
||||
mkdir(nsNSPRPath(*this));
|
||||
} // nsFileSpec::CreateDirectory
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -270,11 +270,11 @@ void nsFileSpec::Delete(PRBool inRecursive) const
|
||||
child.Delete(inRecursive);
|
||||
}
|
||||
}
|
||||
rmdir(nsprPath(*this));
|
||||
rmdir(nsNSPRPath(*this));
|
||||
}
|
||||
else if (!mPath.IsEmpty())
|
||||
{
|
||||
remove(nsprPath(*this));
|
||||
remove(nsNSPRPath(*this));
|
||||
}
|
||||
} // nsFileSpec::Delete
|
||||
|
||||
|
@ -43,6 +43,7 @@ struct FilesTest
|
||||
int CanonicalPath(const char* relativePath);
|
||||
int Persistence(const char* relativePath);
|
||||
int FileSpecEquality(const char *aFile, const char *bFile);
|
||||
int FileSpecAppend(nsFileSpec& parent, const char* relativePath);
|
||||
int Copy(const char* sourceFile, const char* targDir);
|
||||
int Move(const char* sourceFile, const char* targDir);
|
||||
int Rename(const char* sourceFile, const char* newName);
|
||||
@ -51,12 +52,12 @@ struct FilesTest
|
||||
|
||||
int SpecialSystemDirectories();
|
||||
|
||||
int NSPRCompatiblity(const char* sourceFile);
|
||||
int NSPRCompatibility(const char* sourceFile);
|
||||
|
||||
void Banner(const char* bannerString);
|
||||
int Passed();
|
||||
int Failed(const char* explanation = nsnull);
|
||||
void Inspect();
|
||||
int Inspect();
|
||||
|
||||
nsOutputConsoleStream mConsole;
|
||||
};
|
||||
@ -92,10 +93,11 @@ int FilesTest::Failed(const char* explanation)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Inspect()
|
||||
int FilesTest::Inspect()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << nsEndl << "^^^^^^^^^^ PLEASE INSPECT OUTPUT FOR ERRORS" << nsEndl;
|
||||
return 0; // for convenience
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -136,12 +138,12 @@ void FilesTest::WriteStuff(nsOutputStream& s)
|
||||
} // WriteStuff
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::OutputStream(const char* relativePath)
|
||||
int FilesTest::OutputStream(const char* relativeUnixPath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFilePath myTextFilePath(relativeUnixPath, PR_TRUE); // convert to full path.
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
const char* pathAsString = (const char*)mySpec;
|
||||
{
|
||||
mConsole << "WRITING IDENTICAL OUTPUT TO " << pathAsString << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(mySpec);
|
||||
@ -166,7 +168,7 @@ int FilesTest::OutputStream(const char* relativePath)
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
FileSizeAndDate(relativePath);
|
||||
FileSizeAndDate(relativeUnixPath);
|
||||
return Passed();
|
||||
}
|
||||
|
||||
@ -310,8 +312,7 @@ int FilesTest::InputStream(const char* relativePath)
|
||||
testStream2.readline(line, sizeof(line));
|
||||
mConsole << line << nsEndl;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
return Inspect();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -356,8 +357,7 @@ int FilesTest::Parent(
|
||||
<< "\n or as a URL"
|
||||
<< "\n\t" << (const char*)url
|
||||
<< nsEndl;
|
||||
Inspect();
|
||||
return 0;
|
||||
return Inspect();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -429,17 +429,18 @@ int FilesTest::CreateDirectory(nsFileSpec& dirSpec)
|
||||
int FilesTest::CreateDirectoryRecursive(const char* aPath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirSpec(aPath, PR_TRUE);
|
||||
nsFilePath dirPath(aPath, PR_TRUE);
|
||||
mConsole
|
||||
<< "Testing nsFilePath(X, PR_TRUE) using"
|
||||
<< "\n\t" << (const char*)aPath
|
||||
<< nsEndl;
|
||||
|
||||
return Passed();
|
||||
|
||||
nsFileSpec spec(dirPath);
|
||||
if (spec.Valid())
|
||||
return Passed();
|
||||
return Failed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -465,8 +466,7 @@ int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
nsCRT::free(itemName);
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
return Inspect();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -491,13 +491,38 @@ int FilesTest::CanonicalPath(
|
||||
return Passed();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::FileSpecAppend(nsFileSpec& parent, const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath initialPath(parent);
|
||||
const char* initialPathString = (const char*)initialPath;
|
||||
mConsole << "Initial nsFileSpec:\n\t\"" << initialPathString << "\"" << nsEndl;
|
||||
|
||||
nsFileSpec fileSpec(initialPath);
|
||||
|
||||
mConsole << "Appending:\t\"" << relativePath << "\"" << nsEndl;
|
||||
|
||||
fileSpec += relativePath;
|
||||
|
||||
nsFilePath resultPath(fileSpec);
|
||||
const char* resultPathString = (const char*)resultPath;
|
||||
mConsole << "Result:\n\t\"" << resultPathString << "\"" << nsEndl;
|
||||
|
||||
return Inspect();
|
||||
} // FilesTest::FileSpecAppend
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::FileSpecEquality(const char *aFile, const char *bFile)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec aFileSpec(aFile, PR_FALSE);
|
||||
nsFileSpec bFileSpec(bFile, PR_FALSE);
|
||||
nsFileSpec cFileSpec(bFile, PR_FALSE); // this should == bFile
|
||||
nsFilePath aFilePath(aFile, PR_TRUE);
|
||||
nsFilePath bFilePath(bFile, PR_TRUE);
|
||||
|
||||
|
||||
nsFileSpec aFileSpec(aFilePath);
|
||||
nsFileSpec bFileSpec(bFilePath);
|
||||
nsFileSpec cFileSpec(bFilePath); // this should == bFile
|
||||
|
||||
if (aFileSpec != bFileSpec &&
|
||||
bFileSpec == cFileSpec )
|
||||
@ -506,26 +531,26 @@ int FilesTest::FileSpecEquality(const char *aFile, const char *bFile)
|
||||
}
|
||||
|
||||
return Failed();
|
||||
}
|
||||
} // FilesTest::FileSpecEquality
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Copy(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
nsFileSpec dirPath(nsFilePath(dir, PR_TRUE));
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec mySpec(file, PR_TRUE); // relative path.
|
||||
nsFileSpec mySpec(nsFilePath(file, PR_TRUE)); // relative path.
|
||||
{
|
||||
nsIOFileStream testStream(mySpec); // creates the file
|
||||
// Scope ends here, file gets closed
|
||||
}
|
||||
|
||||
nsFileSpec filePath(file);
|
||||
nsFileSpec filePath(nsFilePath(file, PR_TRUE));
|
||||
if (! filePath.Exists())
|
||||
return Failed();
|
||||
|
||||
@ -545,14 +570,14 @@ int FilesTest::Copy(const char* file, const char* dir)
|
||||
int FilesTest::Move(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
nsFileSpec dirPath(nsFilePath(dir, PR_TRUE));
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec srcSpec(file, PR_TRUE); // relative path.
|
||||
nsFileSpec srcSpec(nsFilePath(file, PR_TRUE)); // relative path.
|
||||
{
|
||||
nsIOFileStream testStream(srcSpec); // creates the file
|
||||
// file gets closed here because scope ends here.
|
||||
@ -576,11 +601,12 @@ int FilesTest::Move(const char* file, const char* dir)
|
||||
int FilesTest::Execute(const char* appName, const char* args)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec appPath(appName, PR_FALSE);
|
||||
if (!appPath.Exists())
|
||||
mConsole << "Attempting to execute " << appName << nsEndl;
|
||||
nsFileSpec appSpec(appName, PR_FALSE);
|
||||
if (!appSpec.Exists())
|
||||
return Failed();
|
||||
|
||||
nsresult error = appPath.Execute(args);
|
||||
nsresult error = appSpec.Execute(args);
|
||||
if (NS_FAILED(error))
|
||||
return Failed();
|
||||
|
||||
@ -588,11 +614,13 @@ int FilesTest::Execute(const char* appName, const char* args)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
int FilesTest::NSPRCompatibility(const char* relativeUnixFilePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
nsFileSpec createTheFileSpec(sourceFile, PR_TRUE); // relative path.
|
||||
nsFilePath filePath(relativeUnixFilePath, PR_TRUE); // relative path
|
||||
|
||||
nsFileSpec createTheFileSpec(filePath);
|
||||
{
|
||||
nsIOFileStream testStream(createTheFileSpec); // creates the file
|
||||
// file gets closed here because scope ends here.
|
||||
@ -600,10 +628,10 @@ int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
|
||||
|
||||
|
||||
nsFilePath filePath(sourceFile, PR_TRUE);
|
||||
PRFileDesc* fOut = NULL;
|
||||
|
||||
fOut = PR_Open( nsprPath(filePath), PR_RDONLY, 0 );
|
||||
// From an nsFilePath
|
||||
fOut = PR_Open( nsNSPRPath(filePath), PR_RDONLY, 0 );
|
||||
if ( fOut == NULL )
|
||||
{
|
||||
return Failed();
|
||||
@ -614,9 +642,10 @@ int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
fOut = NULL;
|
||||
}
|
||||
|
||||
// From an nsFileSpec
|
||||
nsFileSpec fileSpec(filePath);
|
||||
|
||||
fOut = PR_Open( nsprPath(fileSpec), PR_RDONLY, 0 );
|
||||
fOut = PR_Open( nsNSPRPath(fileSpec), PR_RDONLY, 0 );
|
||||
if ( fOut == NULL )
|
||||
{
|
||||
return Failed();
|
||||
@ -627,9 +656,10 @@ int FilesTest::NSPRCompatiblity(const char* sourceFile)
|
||||
fOut = NULL;
|
||||
}
|
||||
|
||||
// From an nsFileURL
|
||||
nsFileURL fileURL(fileSpec);
|
||||
|
||||
fOut = PR_Open( nsprPath(fileURL), PR_RDONLY, 0 );
|
||||
fOut = PR_Open( nsNSPRPath(fileURL), PR_RDONLY, 0 );
|
||||
if ( fOut == NULL )
|
||||
{
|
||||
return Failed();
|
||||
@ -887,84 +917,118 @@ int FilesTest::RunAllTests()
|
||||
// For use with DEBUG defined.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// Test of mConsole output
|
||||
|
||||
int rv = 0;
|
||||
|
||||
// Test of mConsole output
|
||||
mConsole << "WRITING TEST OUTPUT TO CONSOLE" << nsEndl << nsEndl;
|
||||
|
||||
// Test of nsFileSpec
|
||||
|
||||
Banner("Interconversion");
|
||||
WriteStuff(mConsole);
|
||||
Inspect();
|
||||
|
||||
rv = Inspect();
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("Canonical Path");
|
||||
if (CanonicalPath("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = CanonicalPath("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("OutputStream");
|
||||
if (OutputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = OutputStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("InputStream");
|
||||
if (InputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = InputStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("IOStream");
|
||||
if (IOStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = IOStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
FileSizeAndDate("mumble/iotest.txt");
|
||||
|
||||
if (InputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
rv = InputStream("mumble/iotest.txt");
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("StringStream");
|
||||
if (StringStream() != 0)
|
||||
return -1;
|
||||
rv = StringStream();
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
Banner("Parent");
|
||||
nsFileSpec parent;
|
||||
if (Parent("mumble/iotest.txt", parent) != 0)
|
||||
return -1;
|
||||
rv = Parent("mumble/iotest.txt", parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("FileSpec Append using Unix relative path");
|
||||
rv = FileSpecAppend(parent, "nested/unix/file.txt");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
Banner("FileSpec Append using Native relative path");
|
||||
#ifdef XP_PC
|
||||
rv = FileSpecAppend(parent, "nested\\windows\\file.txt");
|
||||
#elif defined(XP_MAC)
|
||||
rv = FileSpecAppend(parent, ":nested:mac:file.txt");
|
||||
#else
|
||||
rv = Passed();
|
||||
#endif // XP_MAC
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Delete");
|
||||
if (Delete(parent) != 0)
|
||||
return -1;
|
||||
rv = Delete(parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("CreateDirectory");
|
||||
if (CreateDirectory(parent) != 0)
|
||||
return -1;
|
||||
rv = CreateDirectory(parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("CreateDirectoryRecursive Relative (using nsFileSpec)");
|
||||
if (CreateDirectoryRecursive("mumble/dir1/dir2/dir3/") != 0)
|
||||
return -1;
|
||||
rv = CreateDirectoryRecursive("mumble/dir1/dir2/dir3/");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
#ifdef XP_PC
|
||||
Banner("CreateDirectoryRecursive Absolute (using nsFileSpec)");
|
||||
if (CreateDirectoryRecursive("c:\\temp\\dir1\\dir2\\dir3\\") != 0)
|
||||
return -1;
|
||||
rv = CreateDirectoryRecursive("c:\\temp\\dir1\\dir2\\dir3\\");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
#endif
|
||||
|
||||
Banner("IterateDirectoryChildren");
|
||||
if (IterateDirectoryChildren(parent) != 0)
|
||||
return -1;
|
||||
rv = IterateDirectoryChildren(parent);
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("nsFileSpec equality");
|
||||
if (FileSpecEquality("mumble/a", "mumble/b") != 0)
|
||||
return -1;
|
||||
rv = FileSpecEquality("mumble/a", "mumble/b");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Copy");
|
||||
if (Copy("mumble/copyfile.txt", "mumble/copy") != 0)
|
||||
return -1;
|
||||
rv = Copy("mumble/copyfile.txt", "mumble/copy");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Move");
|
||||
if (Move("mumble/moveFile.txt", "mumble/move") != 0)
|
||||
return -1;
|
||||
rv = Move("mumble/moveFile.txt", "mumble/move");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Execute");
|
||||
#ifdef XP_MAC
|
||||
// This path is hard-coded to test on jrm's machine. Finding an app
|
||||
// on an arbitrary Macintosh would cost more trouble than it's worth.
|
||||
// Change path to suit.
|
||||
if NS_FAILED(Execute("/Projects/Nav45_BRANCH/ns/cmd/macfe/"\
|
||||
"projects/client45/Client45PPC", ""))
|
||||
// Change path to suit. This is currently a native path, as you can see.
|
||||
if NS_FAILED(Execute("Projects:Nav45_BRANCH:ns:cmd:macfe:"\
|
||||
"projects:client45:Client45PPC", ""))
|
||||
#elif XP_PC
|
||||
if NS_FAILED(Execute("c:\\windows\\notepad.exe", ""))
|
||||
#else
|
||||
@ -972,23 +1036,26 @@ int FilesTest::RunAllTests()
|
||||
#endif
|
||||
return -1;
|
||||
|
||||
Banner("NSPR Compatiblity");
|
||||
if (NSPRCompatiblity("mumble/aFile.txt") != 0)
|
||||
return -1;
|
||||
Banner("NSPR Compatibility");
|
||||
rv = NSPRCompatibility("mumble/aFile.txt");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Special System Directories");
|
||||
if (SpecialSystemDirectories() != 0)
|
||||
return -1;
|
||||
rv = SpecialSystemDirectories();
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Banner("Persistence");
|
||||
if (Persistence("mumble/filedesc.dat") != 0)
|
||||
return -1;
|
||||
rv = Persistence("mumble/filedesc.dat");
|
||||
if (rv)
|
||||
goto Clean;
|
||||
|
||||
Clean:
|
||||
Banner("Delete again (to clean up our mess)");
|
||||
if (Delete(parent) != 0)
|
||||
return -1;
|
||||
Delete(parent);
|
||||
|
||||
return 0;
|
||||
return rv;
|
||||
} // FilesTest::RunAllTests
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user