This commit is contained in:
mkaply%us.ibm.com 2005-04-25 13:06:43 +00:00
Родитель 2d5ba6cf4e
Коммит 775f5da9a5
1 изменённых файлов: 39 добавлений и 41 удалений

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

@ -135,6 +135,9 @@ myLL_L2II(PRInt64 result, PRInt32 *hi, PRInt32 *lo )
LL_L2I(*lo, a64); LL_L2I(*lo, a64);
} }
//-----------------------------------------------------------------------------
// nsDirEnumerator
//-----------------------------------------------------------------------------
class nsDirEnumerator : public nsISimpleEnumerator, class nsDirEnumerator : public nsISimpleEnumerator,
public nsIDirectoryEnumerator public nsIDirectoryEnumerator
@ -166,7 +169,7 @@ class nsDirEnumerator : public nsISimpleEnumerator,
if (mDir == nsnull) // not a directory? if (mDir == nsnull) // not a directory?
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
mParent = parent; mParent = parent;
return NS_OK; return NS_OK;
} }
@ -247,12 +250,15 @@ class nsDirEnumerator : public nsISimpleEnumerator,
{ {
PRStatus status = PR_CloseDir(mDir); PRStatus status = PR_CloseDir(mDir);
NS_ASSERTION(status == PR_SUCCESS, "close failed"); NS_ASSERTION(status == PR_SUCCESS, "close failed");
if (status != PR_SUCCESS)
return NS_ERROR_FAILURE;
mDir = nsnull; mDir = nsnull;
} }
return NS_OK; return NS_OK;
} }
private: // dtor can be non-virtual since there are no subclasses, but must be
// public to use the class on the stack.
~nsDirEnumerator() ~nsDirEnumerator()
{ {
Close(); Close();
@ -961,36 +967,34 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsACString &newName, PRBool mov
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
nsDirEnumerator* dirEnum = new nsDirEnumerator(); nsDirEnumerator dirEnum;
if (!dirEnum)
return NS_ERROR_OUT_OF_MEMORY;
rv = dirEnum->Init(this); rv = dirEnum.Init(this);
if (NS_FAILED(rv)) {
nsCOMPtr<nsISimpleEnumerator> iterator = do_QueryInterface(dirEnum); NS_WARNING("dirEnum initalization failed");
return rv;
}
PRBool more; PRBool more;
iterator->HasMoreElements(&more); while (NS_SUCCEEDED(dirEnum.HasMoreElements(&more)) && more)
while (more)
{ {
nsCOMPtr<nsISupports> item; nsCOMPtr<nsISupports> item;
nsCOMPtr<nsIFile> file; nsCOMPtr<nsIFile> file;
iterator->GetNext(getter_AddRefs(item)); dirEnum.GetNext(getter_AddRefs(item));
file = do_QueryInterface(item); file = do_QueryInterface(item);
PRBool isDir, isLink; if (file)
file->IsDirectory(&isDir);
if (move)
{ {
rv = file->MoveToNative(target, EmptyCString()); if (move)
{
rv = file->MoveToNative(target, EmptyCString());
NS_ENSURE_SUCCESS(rv,rv);
}
else
{
rv = file->CopyToNative(target, EmptyCString());
NS_ENSURE_SUCCESS(rv,rv);
}
} }
else
{
rv = file->CopyToNative(target, EmptyCString());
}
iterator->HasMoreElements(&more);
} }
// we've finished moving all the children of this directory // we've finished moving all the children of this directory
// in the new directory. so now delete the directory // in the new directory. so now delete the directory
@ -1000,7 +1004,7 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsACString &newName, PRBool mov
// to the new location. nothing should be left in the folder. // to the new location. nothing should be left in the folder.
if (move) if (move)
{ {
rv = Remove(PR_FALSE); rv = Remove(PR_FALSE /* recursive */);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
} }
} }
@ -1088,26 +1092,20 @@ nsLocalFile::Remove(PRBool recursive)
{ {
if (recursive) if (recursive)
{ {
nsDirEnumerator* dirEnum = new nsDirEnumerator(); nsDirEnumerator dirEnum;
if (dirEnum == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = dirEnum->Init(this); rv = dirEnum.Init(this);
if (NS_FAILED(rv))
nsCOMPtr<nsISimpleEnumerator> iterator = do_QueryInterface(dirEnum); return rv;
PRBool more; PRBool more;
iterator->HasMoreElements(&more); while (NS_SUCCEEDED(dirEnum.HasMoreElements(&more)) && more)
while (more)
{ {
nsCOMPtr<nsISupports> item; nsCOMPtr<nsISupports> item;
nsCOMPtr<nsIFile> file; dirEnum.GetNext(getter_AddRefs(item));
iterator->GetNext(getter_AddRefs(item)); nsCOMPtr<nsIFile> file = do_QueryInterface(item);
file = do_QueryInterface(item); if (file)
file->Remove(recursive);
file->Remove(recursive);
iterator->HasMoreElements(&more);
} }
} }
rv = rmdir(filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK; rv = rmdir(filePath) == -1 ? NSRESULT_FOR_ERRNO() : NS_OK;