Adding followSymlink flag to nsILocalFile.
Adjusting callers.
windows shortcut optimizations.
r=blizzard@mozilla.org.
a=brendan@mozilla.org
This commit is contained in:
dougt%netscape.com 2000-07-12 23:31:31 +00:00
Родитель d6bafb8d3b
Коммит c422448137
40 изменённых файлов: 295 добавлений и 157 удалений

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

@ -1188,6 +1188,7 @@ nsDocShell::GotoIndex(PRInt32 aIndex)
return NS_OK;
}
NS_IMETHODIMP nsDocShell::LoadURI(const PRUnichar* aURI)
{
nsCOMPtr<nsIURI> uri;

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

@ -75,7 +75,7 @@ nsresult NS_InitEmbedding(const char *aPath)
nsILocalFile *localFile = nsnull;
if (aPath && strlen(aPath) > 0)
{
NS_NewLocalFile(aPath, &localFile);
NS_NewLocalFile(aPath, PR_FALSE, &localFile);
}
nsresult rv = NS_InitEmbedding(localFile);
@ -170,7 +170,6 @@ nsresult NS_InitEmbedding(nsILocalFile *aPath)
}
nsresult NS_TermEmbedding()
{
// Reentrant calls to this method do nothing except decrement a counter

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

@ -53,16 +53,13 @@ NS_IMETHODIMP nsXPCToolsCompiler::GetBinDir(nsILocalFile * *aBinDir)
{
*aBinDir = nsnull;
nsCOMPtr<nsILocalFile> dir = do_CreateInstance(NS_LOCAL_FILE_PROGID);
if(!dir)
return NS_ERROR_FAILURE;
nsresult rv = dir->InitWithPath(
nsSpecialSystemDirectory(
nsSpecialSystemDirectory::OS_CurrentProcessDirectory));
nsCOMPtr<nsIFile> file;
nsresult rv = NS_GetSpecialDirectory("xpcom.currentProcessDirectory", getter_AddRefs(file));
if(NS_FAILED(rv))
return rv;
NS_ADDREF(*aBinDir = dir);
nsCOMPtr<nsIFile> lfile = do_QueryInterface(file);
NS_ADDREF(*aBinDir = lfile);
return NS_OK;
}

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

@ -1312,7 +1312,7 @@ nsresult nsFormFrame::ProcessAsMultipart(nsIFormProcessor* aFormProcessor,nsIFil
// on the Mac as it expects a Unix style path. Instead we'll use our
// spiffy new nsILocalFile
nsILocalFile* tempFile = nsnull;
rv = NS_NewLocalFile(value, &tempFile);
rv = NS_NewLocalFile(value, PR_TRUE, &tempFile);
NS_ASSERTION(tempFile, "Couldn't create nsIFileSpec to get file size!");
if (NS_FAILED(rv) || !tempFile)
break; // NS_ERROR_OUT_OF_MEMORY

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

@ -1004,7 +1004,7 @@ nsStdURL::GetFile(nsIFile * *aFile)
path.Cut(0, 1);
#endif
nsCOMPtr<nsILocalFile> localFile;
rv = NS_NewLocalFile(path, getter_AddRefs(localFile));
rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(localFile));
mFile = localFile;
*aFile = mFile;

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

@ -463,7 +463,7 @@ nsDiskCacheRecord::RetrieveInfo(void* aInfo, PRUint32 aInfoLength)
// create mFile if Init() isn't called
if(!mFile.get() ) {
nsCOMPtr< nsILocalFile> file;
NS_NewLocalFile( file_url ,getter_AddRefs(file));
NS_NewLocalFile( file_url, PR_FALSE ,getter_AddRefs(file));
mFile = file;
if(!mFile.get())

2
netwerk/cache/filecache/nsNetDiskCache.cpp поставляемый
Просмотреть файл

@ -96,7 +96,7 @@ static int PR_CALLBACK folderChanged(const char *pref, void *closure)
if ( NS_FAILED ( rv ) )
return rv;
rv = NS_NewLocalFile( path, getter_AddRefs(cacheFolder));
rv = NS_NewLocalFile( path, PR_FALSE, getter_AddRefs(cacheFolder));
nsMemory::Free( path );
return ( (nsNetDiskCache*)closure )->SetDiskCacheFolder( cacheFolder );

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

@ -76,6 +76,10 @@ nsFileChannel::Init(PRInt32 ioFlags,
rv = fileURL->GetFile(getter_AddRefs(mFile));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mFile);
if (localFile)
localFile->SetFollowLinks(PR_TRUE);
return rv;
}

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

@ -315,7 +315,7 @@ nsHTTPHandler::NewPostDataStream(PRBool isFile,
nsresult rv;
if (isFile) {
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(data, getter_AddRefs(file));
rv = NS_NewLocalFile(data, PR_FALSE, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> in;

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

@ -211,7 +211,7 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
rv = reader->OnStartRequest(nsnull, nsnull);
if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer?
rv = NS_NewLocalFile(path, getter_AddRefs(file));
rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(file));
if (NS_FAILED(rv)) goto done;
rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStr), file);
@ -326,7 +326,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts)
PRDirEntry* entry;
while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH)) != nsnull) {
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(dirName, getter_AddRefs(file));
rv = NS_NewLocalFile(dirName, PR_FALSE, getter_AddRefs(file));
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewLocalFile failed");
rv = file->Append(entry->name);

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

@ -449,11 +449,11 @@ main(int argc, char* argv[])
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILocalFile> inDirFile;
rv = NS_NewLocalFile(inDir, getter_AddRefs(inDirFile));
rv = NS_NewLocalFile(inDir, PR_FALSE, getter_AddRefs(inDirFile));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILocalFile> outDirFile;
rv = NS_NewLocalFile(outDir, getter_AddRefs(outDirFile));
rv = NS_NewLocalFile(outDir, PR_FALSE, getter_AddRefs(outDirFile));
if (NS_FAILED(rv)) return rv;
CreateFun create = FileChannelWorker::Create;

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

@ -87,7 +87,7 @@ public:
nsresult Init(const char* origFile) {
nsresult rv;
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(origFile, getter_AddRefs(file));
rv = NS_NewLocalFile(origFile, PR_FALSE, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
char* name;
rv = file->GetLeafName(&name);
@ -129,7 +129,7 @@ TestAsyncRead(const char* fileName, PRUint32 offset, PRInt32 length)
nsIChannel* fileTrans;
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(fileName, getter_AddRefs(file));
rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
rv = fts->CreateTransport(file, PR_RDONLY, 0, &fileTrans);
if (NS_FAILED(rv)) return rv;
@ -176,7 +176,7 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length)
outFile.Append(".out");
nsIChannel* fileTrans;
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(outFile, getter_AddRefs(file));
rv = NS_NewLocalFile(outFile, PR_FALSE, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
rv = fts->CreateTransport(file,
PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
@ -191,7 +191,7 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length)
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILocalFile> f;
rv = NS_NewLocalFile(fileName, getter_AddRefs(f));
rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(f));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIInputStream> inStr;
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), f);

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

@ -112,7 +112,7 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length)
if (NS_FAILED(rv)) return rv ;
nsCOMPtr<nsILocalFile> fs;
rv = NS_NewLocalFile(filename, getter_AddRefs(fs));
rv = NS_NewLocalFile(filename, PR_FALSE, getter_AddRefs(fs));
if (NS_FAILED(rv)) return rv ;
nsCOMPtr<nsIChannel> transport;

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

@ -156,6 +156,7 @@ static void event_processor_callback(gpointer data,
nsIEventQueue *eventQueue = (nsIEventQueue*)data;
if (eventQueue)
eventQueue->ProcessPendingEvents();
}
#define PREF_NCOLS "browser.ncols"

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

@ -468,7 +468,7 @@ printf("looking for data in type %s, mac flavor %ld\n", NS_STATIC_CAST(const cha
HFSFlavor* fileData = NS_REINTERPRET_CAST(HFSFlavor*, dataBuff);
NS_ASSERTION ( sizeof(HFSFlavor) == dataSize, "Ooops, we realy don't have a HFSFlavor" );
nsCOMPtr<nsILocalFileMac> file;
if ( NS_SUCCEEDED(NS_NewLocalFileWithFSSpec(&fileData->fileSpec, getter_AddRefs(file))) )
if ( NS_SUCCEEDED(NS_NewLocalFileWithFSSpec(&fileData->fileSpec, PR_TRUE, getter_AddRefs(file))) )
genericDataWrapper = do_QueryInterface(file);
}
else {

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

@ -624,7 +624,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
// we have a file path in |data|. Create an nsLocalFile object.
char* filepath = NS_REINTERPRET_CAST(char*, data);
nsCOMPtr<nsILocalFile> file;
if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, getter_AddRefs(file))) )
if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) )
genericDataWrapper = do_QueryInterface(file);
}
else {

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

@ -134,6 +134,6 @@ void XXXNeverCalled()
nsString foo;
nsLinebreakConverter::ConvertStringLineBreaks(foo,
nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent);
NS_NewLocalFile(NULL, NULL);
NS_NewLocalFile(NULL, PR_FALSE, NULL);
NS_NewByteArrayInputStream (NULL, NULL, 0);
}

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

@ -1443,3 +1443,4 @@ NS_FileSpecToIFile(nsFileSpec* fileSpec, nsILocalFile* *result)

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

@ -58,6 +58,23 @@ interface nsILocalFile : nsIFile
void initWithPath([const] in string filePath);
void initWithUnicodePath([const] in wstring filePath);
/**
* followLinks
*
* This attribute will determine if the nsLocalFile will auto
* resolve symbolic links. By default, this value will be false
* on all non unix systems. On unix, this attribute is effectively
* a noop.
*
* Be aware that changing this attribute from true to false after
* the nsILocalFile has been initialized may lead to errors. This
* could happen if there were resolved symlink in the initialized
* path. For example if you had /a/b/c where |b| was a symlink,
* and you change this attribute to false, the next usage would
* mostlikely fail.
*/
attribute PRBool followLinks;
[noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);
[noscript] FILE openANSIFileDesc(in string mode);
@ -84,9 +101,9 @@ interface nsILocalFile : nsIFile
#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
extern "C" NS_EXPORT nsresult
NS_NewLocalFile(const char* path, nsILocalFile* *result);
NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result);
extern "C" NS_EXPORT nsresult
NS_NewUnicodeLocalFile(const PRUnichar* path, nsILocalFile* *result);
NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result);
%}

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

@ -100,6 +100,6 @@ public:
extern "C" NS_EXPORT nsresult
NS_NewLocalFileWithFSSpec(FSSpec* inSpec, nsILocalFileMac* *result);
NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followSymlinks, nsILocalFileMac* *result);
#endif

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

@ -29,8 +29,7 @@
#include "nsIUnicodeDecoder.h"
#endif /* XPCOM_STANDALONE */
/* nsFileSpec stuff. put here untill it got obsoleted */
#include "nsFileSpec.h"
#include "nsFileSpec.h" // evil ftang hack
#ifdef XP_PC
#ifdef XP_OS2
@ -111,12 +110,12 @@ private:
} \
return res; \
}
#define SET_UCS_2ARGS_1( func , arg1, arg2) \
#define SET_UCS_2ARGS_1( func , path, followLinks, result) \
{ \
char* tmp; \
nsresult res; \
if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((arg1), &tmp))){ \
res = (func)(tmp, arg2); \
if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((path), &tmp))){ \
res = (func)(tmp, followLinks, result); \
nsMemory::Free(tmp); \
} \
return res; \
@ -305,10 +304,78 @@ nsLocalFile::GetUnicodeTarget(PRUnichar **_retval)
GET_UCS(GetTarget, _retval);
}
nsresult
NS_NewUnicodeLocalFile(const PRUnichar* path, nsILocalFile* *result)
NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result)
{
SET_UCS_2ARGS_1( NS_NewLocalFile , path, result)
SET_UCS_2ARGS_1( NS_NewLocalFile, path, followLinks, result)
}
// should work on Macintosh, Unix, and Win32.
#define kMaxFilenameLength 31
NS_IMETHODIMP
nsLocalFile::CreateUnique(const char* suggestedName, PRUint32 type, PRUint32 attributes)
{
nsresult rv = Create(type, attributes);
if (NS_SUCCEEDED(rv)) return NS_OK;
if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv;
char* leafName;
rv = GetLeafName(&leafName);
if (NS_FAILED(rv)) return rv;
char* lastDot = strrchr(leafName, '.');
char suffix[kMaxFilenameLength + 1] = "";
if (lastDot)
{
strncpy(suffix, lastDot, kMaxFilenameLength); // include '.'
suffix[kMaxFilenameLength] = 0; // make sure it's null terminated
*lastDot = '\0'; // strip suffix and dot.
}
// 27 should work on Macintosh, Unix, and Win32.
const int maxRootLength = 27 - nsCRT::strlen(suffix) - 1;
if ((int)nsCRT::strlen(leafName) > (int)maxRootLength)
leafName[maxRootLength] = '\0';
for (short indx = 1; indx < 10000; indx++)
{
// start with "Picture-1.jpg" after "Picture.jpg" exists
char newName[kMaxFilenameLength + 1];
sprintf(newName, "%s-%d%s", leafName, indx, suffix);
SetLeafName(newName);
rv = Create(type, attributes);
if (NS_SUCCEEDED(rv) || rv != NS_ERROR_FILE_ALREADY_EXISTS)
{
nsMemory::Free(leafName);
return rv;
}
}
nsMemory::Free(leafName);
// The disk is full, sort of
return NS_ERROR_FILE_TOO_BIG;
}
// E_V_I_L Below! E_V_I_L Below! E_V_I_L Below! E_V_I_L Below!
// FTANG need to move this crap out of here. Mixing nsFileSpec here is
// E_V_I_L
// ==================================================================
// nsFileSpec stuff . put here untill nsFileSpec get obsoleted
@ -366,58 +433,3 @@ nsresult nsFileSpec::Execute(const nsString& args) const
{
SET_UCS( Execute , args.GetUnicode());
}
// should work on Macintosh, Unix, and Win32.
#define kMaxFilenameLength 31
NS_IMETHODIMP
nsLocalFile::CreateUnique(const char* suggestedName, PRUint32 type, PRUint32 attributes)
{
nsresult rv = Create(type, attributes);
if (NS_SUCCEEDED(rv)) return NS_OK;
if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv;
char* leafName;
rv = GetLeafName(&leafName);
if (NS_FAILED(rv)) return rv;
char* lastDot = strrchr(leafName, '.');
char suffix[kMaxFilenameLength + 1] = "";
if (lastDot)
{
strncpy(suffix, lastDot, kMaxFilenameLength); // include '.'
suffix[kMaxFilenameLength] = 0; // make sure it's null terminated
*lastDot = '\0'; // strip suffix and dot.
}
// 27 should work on Macintosh, Unix, and Win32.
const int maxRootLength = 27 - nsCRT::strlen(suffix) - 1;
if ((int)nsCRT::strlen(leafName) > (int)maxRootLength)
leafName[maxRootLength] = '\0';
for (short indx = 1; indx < 10000; indx++)
{
// start with "Picture-1.jpg" after "Picture.jpg" exists
char newName[kMaxFilenameLength + 1];
sprintf(newName, "%s-%d%s", leafName, indx, suffix);
SetLeafName(newName);
rv = Create(type, attributes);
if (NS_SUCCEEDED(rv) || rv != NS_ERROR_FILE_ALREADY_EXISTS)
{
nsMemory::Free(leafName);
return rv;
}
}
nsMemory::Free(leafName);
// The disk is full, sort of
return NS_ERROR_FILE_TOO_BIG;
}

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

@ -707,7 +707,7 @@ class nsDirEnumerator : public nsISimpleEnumerator
// Make a new nsILocalFile for the new element
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile("dummy:path", getter_AddRefs(file));
rv = NS_NewLocalFile("dummy:path", PR_TRUE, getter_AddRefs(file));
if (NS_FAILED(rv))
return rv;
@ -768,6 +768,7 @@ nsLocalFile::nsLocalFile()
: mInitType(eNotInitialized)
, mLastResolveFlag(PR_FALSE)
, mHaveFileInfo(PR_FALSE)
, mFollowSymlinks(PR_FALSE)
, mType('????')
, mCreator('MOSS')
{
@ -820,6 +821,21 @@ nsLocalFile::MakeDirty()
}
/* attribute PRBool followLinks; */
NS_IMETHODIMP
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
{
*aFollowLinks = mFollowSymlinks;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
{
MakeDirty();
mFollowSymlinks = aFollowLinks;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::ResolveAndStat(PRBool resolveTerminal)
{
@ -1698,7 +1714,7 @@ nsLocalFile::GetParent(nsIFile * *aParent)
parentPath.Truncate(offset);
nsCOMPtr<nsILocalFile> localFile;
rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile));
rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv) && localFile)
{
rv = localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent);
@ -1739,7 +1755,7 @@ nsLocalFile::GetParent(nsIFile * *aParent)
parentFolderSpec.parID = pBlock.dirInfo.ioDrParID;
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile("dummy:path", getter_AddRefs(file));
rv = NS_NewLocalFile("dummy:path", mFollowSymlinks, getter_AddRefs(file));
if (NS_FAILED(rv))
goto bail;
@ -2047,7 +2063,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
return NS_OK;
}
#pragma mark -
// a stack-based, exception safe class for an AEDesc
@ -2625,13 +2640,15 @@ nsLocalFile::OpenDocWithApp(nsILocalFile* aAppToOpenWith, PRBool aLaunchInBackgr
// Handy dandy utility create routine for something or the other
nsresult
NS_NewLocalFile(const char* path, nsILocalFile* *result)
NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result)
{
nsLocalFile* file = new nsLocalFile();
if (file == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
file->SetFollowLinks(followLinks);
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
@ -2642,13 +2659,15 @@ NS_NewLocalFile(const char* path, nsILocalFile* *result)
}
nsresult
NS_NewLocalFileWithFSSpec(FSSpec* inSpec, nsILocalFileMac* *result)
NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followLinks, nsILocalFileMac* *result)
{
nsLocalFile* file = new nsLocalFile();
if (file == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
file->SetFollowLinks(followLinks);
nsresult rv = file->InitWithFSSpec(inSpec);
if (NS_FAILED(rv)) {
NS_RELEASE(file);

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

@ -101,6 +101,8 @@ private:
PRPackedBool mStatDirty;
PRPackedBool mLastResolveFlag;
PRPackedBool mFollowSymlinks;
// Is the mResolvedSpec member valid? Only after we resolve the mSpec or mWorkingPath
// PRPackedBool mHaveValidSpec;

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

@ -263,6 +263,7 @@ nsLocalFile::nsLocalFile()
mPersistFile = nsnull;
mShellLink = nsnull;
#endif
mFollowSymlinks = PR_FALSE;
mLastResolution = PR_FALSE;
MakeDirty();
}
@ -566,6 +567,8 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal)
return(NS_ERROR_FILE_NOT_FOUND);
}
#else
if (!mFollowSymlinks)
return NS_ERROR_FILE_NOT_FOUND; // if we are not resolving, we just give up here.
nsresult result;
@ -610,7 +613,7 @@ nsLocalFile::Clone(nsIFile **file)
nsCOMPtr<nsILocalFile> localFile;
rv = NS_NewLocalFile(aFilePath, getter_AddRefs(localFile));
rv = NS_NewLocalFile(aFilePath, mFollowSymlinks, getter_AddRefs(localFile));
nsMemory::Free(aFilePath);
if (NS_SUCCEEDED(rv) && localFile)
@ -1683,7 +1686,7 @@ nsLocalFile::GetParent(nsIFile * *aParent)
parentPath.Truncate(offset);
nsCOMPtr<nsILocalFile> localFile;
nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile));
nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile));
if(NS_SUCCEEDED(rv) && localFile)
{
@ -2027,6 +2030,21 @@ nsLocalFile::GetTarget(char **_retval)
}
/* attribute PRBool followLinks; */
NS_IMETHODIMP
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
{
*aFollowLinks = mFollowSymlinks;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
{
MakeDirty();
mFollowSymlinks = aFollowLinks;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
{
@ -2056,15 +2074,29 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
return NS_OK;
}
/* attribute PRBool followLinks; */
NS_IMETHODIMP
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
{
*aFollowLinks = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
{
return NS_OK;
}
nsresult
NS_NewLocalFile(const char* path, nsILocalFile* *result)
NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result)
{
nsLocalFile* file = new nsLocalFile();
if (file == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
file->SetFollowLinks(followLinks);
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);

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

@ -109,8 +109,9 @@ public:
private:
// this is the flag which indicates if I can used cached information about the file
PRBool mDirty;
PRBool mLastResolution;
PRPackedBool mDirty;
PRPackedBool mLastResolution;
PRPackedBool mFollowSymlinks;
// this string will alway be in native format!
nsCString mWorkingPath;

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

@ -1065,7 +1065,7 @@ nsLocalFile::GetParent(nsIFile **aParent)
parentPath.Truncate(offset);
nsCOMPtr<nsILocalFile> localFile;
nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile));
nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile));
if(NS_SUCCEEDED(rv) && localFile)
{
@ -1286,6 +1286,20 @@ nsLocalFile::Spawn(const char **args, PRUint32 count)
return NS_ERROR_FILE_EXECUTION_FAILED;
}
/* attribute PRBool followLinks; */
NS_IMETHODIMP
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
{
*aFollowLinks = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
{
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries)
{
@ -1315,7 +1329,7 @@ nsLocalFile::Load(PRLibrary **_retval)
}
nsresult
NS_NewLocalFile(const char* path, nsILocalFile* *result)
NS_NewLocalFile(const char* path, PRBool followSymlinks, nsILocalFile* *result)
{
nsLocalFile* file = new nsLocalFile();
if (file == nsnull)

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

@ -243,6 +243,7 @@ nsLocalFile::nsLocalFile()
mPersistFile = nsnull;
mShellLink = nsnull;
mLastResolution = PR_FALSE;
mFollowSymlinks = PR_FALSE;
MakeDirty();
}
@ -307,6 +308,10 @@ nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char**
{
nsresult rv = NS_OK;
if (strstr(workingPath, ".lnk") == nsnull)
return NS_ERROR_FILE_INVALID_PATH;
if (mPersistFile == nsnull || mShellLink == nsnull)
{
CoInitialize(NULL); // FIX: we should probably move somewhere higher up during startup
@ -507,6 +512,7 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal)
return NS_OK;
}
mLastResolution = resolveTerminal;
mResolvedPath.Assign(mWorkingPath); //until we know better.
// First we will see if the workingPath exists. If it does, then we
// can simply use that as the resolved path. This simplification can
@ -528,11 +534,27 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal)
PRStatus status = PR_GetFileInfo64(nsprPath, &mFileInfo64);
if ( status == PR_SUCCESS )
{
mResolvedPath.Assign(workingFilePath);
if (!resolveTerminal)
{
mDirty = PR_FALSE;
return NS_OK;
}
// check to see that this is shortcut.
int pathLen = strlen(workingFilePath);
const char* leaf = workingFilePath + pathLen - 4;
if ( (strcmp(leaf, ".lnk") != 0))
{
mDirty = PR_FALSE;
return NS_OK;
}
}
if (!mFollowSymlinks)
return NS_ERROR_FILE_NOT_FOUND; // if we are not resolving, we just give up here.
nsresult result;
// okay, something is wrong with the working path. We will try to resolve it.
@ -541,22 +563,12 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal)
result = ResolvePath(workingFilePath, resolveTerminal, &resolvePath);
if (NS_FAILED(result))
return result;
return NS_ERROR_FILE_NOT_FOUND;
mResolvedPath.Assign(resolvePath);
nsMemory::Free(resolvePath);
// if we are not resolving the terminal node, we have to "fake" windows
// out and append the ".lnk" file extension before getting any information
// about the shortcut. If resoveTerminal was TRUE, than it the shortcut was
// resolved by the call to ResolvePath above.
char linkStr[MAX_PATH];
strcpy(linkStr, mResolvedPath.GetBuffer());
strcat(linkStr, ".lnk");
status = PR_GetFileInfo64(linkStr, &mFileInfo64);
status = PR_GetFileInfo64(mResolvedPath, &mFileInfo64);
if ( status == PR_SUCCESS )
mDirty = PR_FALSE;
@ -575,7 +587,7 @@ nsLocalFile::Clone(nsIFile **file)
nsCOMPtr<nsILocalFile> localFile;
rv = NS_NewLocalFile(aFilePath, getter_AddRefs(localFile));
rv = NS_NewLocalFile(aFilePath, mFollowSymlinks, getter_AddRefs(localFile));
nsMemory::Free(aFilePath);
if (NS_SUCCEEDED(rv) && localFile)
@ -625,6 +637,7 @@ nsLocalFile::InitWithPath(const char *filePath)
mWorkingPath.Assign(nativeFilePath);
nsMemory::Free( nativeFilePath );
return NS_OK;
}
@ -1505,7 +1518,7 @@ nsLocalFile::GetParent(nsIFile * *aParent)
parentPath.Truncate(offset);
nsCOMPtr<nsILocalFile> localFile;
nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile));
nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile));
if(NS_SUCCEEDED(rv) && localFile)
{
@ -1777,6 +1790,22 @@ nsLocalFile::GetTarget(char **_retval)
}
/* attribute PRBool followLinks; */
NS_IMETHODIMP
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
{
*aFollowLinks = mFollowSymlinks;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
{
MakeDirty();
mFollowSymlinks = aFollowLinks;
return NS_OK;
}
NS_IMETHODIMP
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
{
@ -1808,18 +1837,21 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
nsresult
NS_NewLocalFile(const char* path, nsILocalFile* *result)
NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result)
{
nsLocalFile* file = new nsLocalFile();
if (file == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
file->SetFollowLinks(followLinks);
nsresult rv = file->InitWithPath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
*result = file;
return NS_OK;
}

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

@ -68,8 +68,10 @@ public:
private:
// this is the flag which indicates if I can used cached information about the file
PRBool mDirty;
PRBool mLastResolution;
PRPackedBool mDirty;
PRPackedBool mLastResolution;
PRPackedBool mFollowSymlinks;
// this string will alway be in native format!
nsCString mWorkingPath;

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

@ -44,6 +44,7 @@ PROG16 = .\$(OBJDIR)\TestPipes.exe
PROG17 = .\$(OBJDIR)\TestShutdown.exe
PROG18 = .\$(OBJDIR)\TestStackCrawl.exe
PROG19 = .\$(OBJDIR)\TestVoidBTree.exe
PROG20 = .\$(OBJDIR)\nsIFileEnumerator.exe
RESFILE = timer.res
@ -64,6 +65,7 @@ PROGRAMS = $(PROG1) \
$(PROG17) \
$(PROG18) \
$(PROG19) \
$(PROG20) \
$(NULL)
LCFLAGS=-DUSE_NSREG -GX
@ -106,4 +108,6 @@ $(PROG16): $(OBJDIR) TestPipes.cpp
$(PROG17): $(OBJDIR) TestShutdown.cpp
$(PROG18): $(OBJDIR) TestStackCrawl.cpp
$(PROG19): $(OBJDIR) TestVoidBTree.cpp
$(PROG20): $(OBJDIR) nsIFileEnumerator.cpp

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

@ -221,7 +221,7 @@ nsStreamTransfer::SelectFile( nsIDOMWindow *parent, nsIFileSpec **aResult, const
nsXPIDLCString nativeStartDir;
startDir->GetNativePath( getter_Copies( nativeStartDir ) );
nsCOMPtr<nsILocalFile> startLocalFile;
if ( NS_SUCCEEDED( NS_NewLocalFile( nativeStartDir, getter_AddRefs( startLocalFile ) ) ) ) {
if ( NS_SUCCEEDED( NS_NewLocalFile( nativeStartDir, PR_FALSE, getter_AddRefs( startLocalFile ) ) ) ) {
#ifdef DEBUG_law
printf( "\nSetting display directory to %s\n\n", (const char*)nativeStartDir );
#endif
@ -310,7 +310,7 @@ nsCString nsStreamTransfer::SuggestNameFor( nsIChannel *aChannel, char const *su
// this suggested name comes from a http response header and could
// try to overwrite c:\config.sys or something.
nsCOMPtr<nsILocalFile> localFile;
if ( NS_SUCCEEDED( NS_NewLocalFile( result, getter_AddRefs( localFile ) ) ) ) {
if ( NS_SUCCEEDED( NS_NewLocalFile( result, PR_FALSE, getter_AddRefs( localFile ) ) ) ) {
// We want base part of name only.
nsXPIDLCString baseName;
if ( NS_SUCCEEDED( localFile->GetLeafName( getter_Copies( baseName ) ) ) ) {

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

@ -167,7 +167,7 @@ nsStreamXferOp::Start( void ) {
nsFileSpec target; // XXX eliminate
mOutputSpec->GetFileSpec( &target );
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(target, getter_AddRefs(file));
rv = NS_NewLocalFile(target, PR_FALSE, getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
rv = fts->CreateTransport(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
0664, getter_AddRefs( mOutputChannel));

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

@ -414,7 +414,7 @@ void DeleteScheduledFiles( HREG reg )
// no need to check return value of
// SetPersistentDescriptorString, it's always NS_OK
//spec->SetPersistentDescriptorString(valbuf); //nsIFileXXX: Do we still need this instead of InitWithPath?
NS_NewLocalFile((char*)valbuf, getter_AddRefs(spec));
NS_NewLocalFile((char*)valbuf, PR_TRUE, getter_AddRefs(spec));
spec->Clone(getter_AddRefs(doomedFile));
if (NS_SUCCEEDED(rv))
{
@ -478,10 +478,10 @@ void ReplaceScheduledFiles( HREG reg )
if ( err1 == REGERR_OK && err2 == REGERR_OK )
{
rv1 = NS_NewLocalFile((char*)srcFile, getter_AddRefs(src));
rv1 = NS_NewLocalFile((char*)srcFile, PR_TRUE, getter_AddRefs(src));
rv1 = src->Clone(getter_AddRefs(srcSpec));
rv2 = NS_NewLocalFile((char*)doomedFile, getter_AddRefs(dest));
rv2 = NS_NewLocalFile((char*)doomedFile, PR_TRUE, getter_AddRefs(dest));
rv2 = dest->Clone(getter_AddRefs(doomedSpec));
if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2))

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

@ -726,7 +726,7 @@ nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn)
}
nsAutoCString temp(aFolder);
nsCOMPtr<nsILocalFile> folder;
NS_NewLocalFile(temp, getter_AddRefs(folder));
NS_NewLocalFile(temp, PR_TRUE, getter_AddRefs(folder));
result = folder->GetDiskSpaceAvailable(aReturn);
return NS_OK;
@ -2477,7 +2477,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName,
extractHereSpec->Delete(PR_FALSE);
//nsCOMPtr<nsILocalFile> file;
//rv = NS_NewLocalFile(*extractHereSpec, getter_AddRefs(file));
//rv = NS_NewLocalFile(*extractHereSpec, PR_TRUE, getter_AddRefs(file));
//if (NS_SUCCEEDED(rv))
rv = mJarFileData->Extract(nsAutoCString(aJarfile), extractHereSpec);
if (NS_FAILED(rv))

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

@ -236,7 +236,7 @@ PRInt32 nsInstallDelete::ProcessInstallDelete()
// delete mFinalFile;
nsCOMPtr<nsILocalFile> tempLocalFile;
NS_NewLocalFile(tempRegistryString, getter_AddRefs(tempLocalFile));
NS_NewLocalFile(tempRegistryString, PR_TRUE, getter_AddRefs(tempLocalFile));
mFinalFile = tempLocalFile;
if (mFinalFile == nsnull)

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

@ -168,7 +168,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe
// XXX the filespec creation will fail due to unix slashes on Mac
nsAutoCString tempRelPath(aRelativePath);
nsCOMPtr<nsILocalFile> temp;
NS_NewLocalFile(tempRelPath, getter_AddRefs(temp));
NS_NewLocalFile(tempRelPath, PR_TRUE, getter_AddRefs(temp));
mFileSpec = temp; // creates the directories to the relative path.
return;
}
@ -269,7 +269,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe
{
nsAutoCString tempRelPath(aRelativePath);
nsCOMPtr<nsILocalFile> temp;
NS_NewLocalFile(tempRelPath, getter_AddRefs(temp));
NS_NewLocalFile(tempRelPath, PR_TRUE, getter_AddRefs(temp));
mFileSpec = temp;
// file:// is a special case where it returns and does not

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

@ -93,7 +93,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
nsString folderSpec; folderSpec.AssignWithConversion(tempTargetFile);
nsCOMPtr<nsILocalFile> tmp;
NS_NewLocalFile((char*)tempTargetFile, getter_AddRefs(tmp));
NS_NewLocalFile((char*)tempTargetFile, PR_TRUE, getter_AddRefs(tmp));
mPatchFile = nsnull;
mTargetFile = nsnull;

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

@ -195,7 +195,7 @@ REGERR su_UninstallProcessItem(char *component_path)
err = VR_GetPath(component_path, sizeof(filepath), filepath);
if ( err == REGERR_OK )
{
NS_NewLocalFile((char*)filepath, getter_AddRefs(nsLFPath));
NS_NewLocalFile((char*)filepath, PR_TRUE, getter_AddRefs(nsLFPath));
nsFPath = nsLFPath;
err = VR_GetRefCount(component_path, &refcount);
if ( err == REGERR_OK )

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

@ -1028,15 +1028,15 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval
ConvertJSValToStr(b0, cx, argv[0]);
NS_NewLocalFile(nsAutoCString(b0), getter_AddRefs(nsfsB0));
NS_NewLocalFile(nsAutoCString(b0), PR_TRUE, getter_AddRefs(nsfsB0));
ConvertJSValToStr(b1, cx, argv[1]);
NS_NewLocalFile(nsAutoCString(b1), getter_AddRefs(nsfsB1));
NS_NewLocalFile(nsAutoCString(b1), PR_TRUE, getter_AddRefs(nsfsB1));
ConvertJSValToStr(b2, cx, argv[2]);
ConvertJSValToStr(b3, cx, argv[3]);
NS_NewLocalFile(nsAutoCString(b3), getter_AddRefs(nsfsB3));
NS_NewLocalFile(nsAutoCString(b3), PR_TRUE, getter_AddRefs(nsfsB3));
ConvertJSValToStr(b4, cx, argv[4]);
ConvertJSValToStr(b5, cx, argv[5]);
NS_NewLocalFile(nsAutoCString(b5), getter_AddRefs(nsfsB5));
NS_NewLocalFile(nsAutoCString(b5), PR_TRUE, getter_AddRefs(nsfsB5));
if(JSVAL_IS_NULL(argv[6]))
{

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

@ -173,7 +173,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB
nsIFile* jFile;
nsresult rv =jarFile->Clone(&jFile);
//NS_NewLocalFile(jarFile, getter_AddRefs(jFile));
//NS_NewLocalFile(jarFile, PR_TRUE, getter_AddRefs(jFile));
if (NS_SUCCEEDED(rv))
rv = hZip->Init(jFile);
@ -191,7 +191,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB
// Extract the install.js file.
nsCOMPtr<nsILocalFile> iFile;
rv = NS_NewLocalFile(installJSFileSpec, getter_AddRefs(iFile));
rv = NS_NewLocalFile(installJSFileSpec, PR_TRUE, getter_AddRefs(iFile));
if (NS_SUCCEEDED(rv))
rv = hZip->Extract("install.js", iFile);
if ( NS_SUCCEEDED(rv) )

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

@ -126,14 +126,14 @@ PR_PUBLIC_API(nsresult) XPI_Init(
getcwd(componentPath, MAX_PATH);
nsCOMPtr<nsILocalFile> file;
NS_NewLocalFile(componentPath, getter_AddRefs(file));
NS_NewLocalFile(componentPath, PR_TRUE, getter_AddRefs(file));
rv = NS_InitXPCOM(&gServiceMgr, file);
#elif defined(XP_UNIX)
nsCOMPtr<nsILocalFile> file;
NS_NewLocalFile(aProgramDir, getter_AddRefs(file));
NS_NewLocalFile(aProgramDir, PR_TRUE, getter_AddRefs(file));
rv = NS_InitXPCOM(&gServiceMgr, file);
@ -146,7 +146,7 @@ PR_PUBLIC_API(nsresult) XPI_Init(
sprintf(compDirPath, "%s/components", cwd);
nsCOMPtr<nsILocalFile> compDir;
NS_NewLocalFile(compDirPath, getter_AddRefs(compDir));
NS_NewLocalFile(compDirPath, PR_TRUE, getter_AddRefs(compDir));
#else
@ -193,10 +193,10 @@ PR_PUBLIC_API(nsresult) XPI_Init(
#if XP_MAC
nsCOMPtr<nsILocalFileMac> iMacDirSpec;
NS_NewLocalFileWithFSSpec((FSSpec *)&aProgramDir, getter_AddRefs(iMacDirSpec));
NS_NewLocalFileWithFSSpec((FSSpec *)&aProgramDir, PR_TRUE, getter_AddRefs(iMacDirSpec));
iDirSpec = do_QueryInterface(iMacDirSpec);
#else
NS_NewLocalFile(aProgramDir, getter_AddRefs(iDirSpec));
NS_NewLocalFile(aProgramDir, PR_TRUE, getter_AddRefs(iDirSpec));
#endif
if (hook && iDirSpec)
@ -267,10 +267,10 @@ PR_PUBLIC_API(PRInt32) XPI_Install(
#if XP_MAC
nsCOMPtr<nsILocalFileMac> iMacFile;
NS_NewLocalFileWithFSSpec((FSSpec *)&aFile, getter_AddRefs(iMacFile));
NS_NewLocalFileWithFSSpec((FSSpec *)&aFile, PR_TRUE, getter_AddRefs(iMacFile));
iFile = do_QueryInterface(iMacFile);
#else
NS_NewLocalFile(aFile, getter_AddRefs(iFile));
NS_NewLocalFile(aFile, PR_TRUE, getter_AddRefs(iFile));
#endif
if (iFile && gXPI)