From e7da0178b3e0ca594f8bf66e61f0d05360cffb06 Mon Sep 17 00:00:00 2001 From: "davidm%netscape.com" Date: Mon, 3 Apr 2000 01:54:22 +0000 Subject: [PATCH] 27857 nsIFile - MAC not completely implemented --- xpcom/io/nsLocalFileMac.cpp | 89 +++++++++++++++++++++--------------- xpcom/io/nsLocalFileMac.h | 2 +- xpcom/macbuild/xpcomPPC.mcp | Bin 131818 -> 131818 bytes 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/xpcom/io/nsLocalFileMac.cpp b/xpcom/io/nsLocalFileMac.cpp index 25cacc0ad4d..4475f54c214 100644 --- a/xpcom/io/nsLocalFileMac.cpp +++ b/xpcom/io/nsLocalFileMac.cpp @@ -39,7 +39,7 @@ #include "FullPath.h" #include "FileCopy.h" #include "MoreFilesExtras.h" - +#include "DirectoryCopy.h" #include #include #include @@ -50,6 +50,7 @@ #include #include +#include "macDirectoryCopy.h" // Stupid @#$% header looks like its got extern mojo but it doesn't really extern "C" @@ -1299,11 +1300,54 @@ nsLocalFile::GetPath(char **_retval) return NS_OK; } +nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const char* newName, PRBool isCopy ) +{ + nsresult rv = ResolveAndStat( PR_TRUE ); + if ( NS_FAILED( rv ) ) + return rv; + nsCOMPtr destDir( do_QueryInterface( newParentDir )); + + PRBool isDirectory; + rv = newParentDir->IsDirectory( &isDirectory ); + if ( NS_FAILED( rv ) ) + return rv; + FSSpec srcSpec; + FSSpec destSpec; + srcSpec = mResolvedSpec; + rv = destDir->GetResolvedFSSpec( &destSpec ); + if ( NS_FAILED( rv ) ) + return rv; + + OSErr macErr; + Str255 newPascalName; + if ( newName ) + myPLstrncpy( newPascalName, newName, 255); + if ( isCopy ) + { + if ( mResolvedWasFolder ) + macErr = MacFSpDirectoryCopyRename( &srcSpec, &destSpec, newPascalName, NULL, 0, true, NULL ); + else + macErr = ::FSpFileCopy( &srcSpec, &destSpec, newPascalName, NULL, 0, true ); + } + else + { + macErr= ::FSpMoveRenameCompat(&srcSpec, &destSpec, newPascalName); + if ( macErr == diffVolErr) + { + // On a different Volume so go for Copy and then delete + rv = CopyTo( newParentDir, newName ); + if ( NS_FAILED ( rv ) ) + return rv; + return Delete( PR_TRUE ); + } + } + return MacErrorMapper( macErr ); +} NS_IMETHODIMP nsLocalFile::CopyTo(nsIFile *newParentDir, const char *newName) { - return NS_ERROR_NOT_IMPLEMENTED; + return MoveCopy( newParentDir, newName, PR_TRUE ); } NS_IMETHODIMP @@ -1315,7 +1359,7 @@ nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const char *newName) NS_IMETHODIMP nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName) { - return NS_ERROR_NOT_IMPLEMENTED; + return MoveCopy( newParentDir, newName, PR_FALSE ); } NS_IMETHODIMP @@ -1362,47 +1406,18 @@ nsLocalFile::Delete(PRBool recursive) MakeDirty(); PRBool isDir; - nsresult rv = IsDirectory(&isDir); if (NS_FAILED(rv)) return rv; const char *filePath = mResolvedPath.GetBuffer(); - - if (isDir) - { - if (recursive) - { - nsDirEnumerator* dirEnum = new nsDirEnumerator(); - if (dirEnum) - return NS_ERROR_OUT_OF_MEMORY; - - rv = dirEnum->Init(this); - - nsCOMPtr dirIterator = do_QueryInterface(dirEnum); - - PRBool more; - dirIterator->HasMoreElements(&more); - while (more) - { - nsCOMPtr item; - nsCOMPtr file; - dirIterator->GetNext(getter_AddRefs(item)); - file = do_QueryInterface(item); - - file->Delete(recursive); - - dirIterator->HasMoreElements(&more); - } - } - //rmdir(filePath); // todo: save return value? - } + OSErr macerror; + if (isDir && recursive) + macerror = ::DeleteDirectory( mResolvedSpec.vRefNum, mResolvedSpec.parID, mResolvedSpec.name ); else - { - //remove(filePath); // todo: save return value? - } + macerror = ::HDelete( mResolvedSpec.vRefNum, mResolvedSpec.parID, mResolvedSpec.name ); - return NS_OK; + return MacErrorMapper( macerror ); } NS_IMETHODIMP diff --git a/xpcom/io/nsLocalFileMac.h b/xpcom/io/nsLocalFileMac.h index bd6a9f29e28..7168c7c3084 100644 --- a/xpcom/io/nsLocalFileMac.h +++ b/xpcom/io/nsLocalFileMac.h @@ -91,7 +91,7 @@ protected: nsresult TestFinderFlag(PRUint16 flagMask, PRBool *outFlagSet, PRBool testTargetSpec = PR_TRUE); OSErr GetTargetSpecCatInfo(CInfoPBRec& outInfo); - + nsresult MoveCopy( nsIFile* newParentDir, const char* newName, PRBool isCopy ); private: // It's important we keep track of how we were initialized diff --git a/xpcom/macbuild/xpcomPPC.mcp b/xpcom/macbuild/xpcomPPC.mcp index bb84064f1e648e85325fd8243ff83fa6c5290ccd..d6a7d9cdfdb5d36ae34e1e1809c1b74268faa113 100644 GIT binary patch delta 478 zcmaFW%JHg|V}mxMX(9syLnR}SU}Rui0VI2XcmV^0q&5SC3`n$xL0?NDASm9)-`(BQ z&s{-FpSPBGa{}WzM&2ZlRwf|9#K5>_vo-T&&dHm6>n8gd^K72M>nYB}*uD9_${Uu= z=QSG`Wgx~gFawqI05O=}%IkjV|NjqCo71($nKn1+I&-q~x*z@j|K_31AFY2gPCjlS z1{65Pz>vTS6!^)w`L5MXA;!dsj+-~1aTZ{luF%dXKKT`g(dNVc)7e=-u9)a}ezR_b zxe}YC1jy}^KU#m?9AB*|!^pq6bNUJvM>kI&SCBfO3m6=v*R642_?$o>T(hRc5A)-a3AfuA5rIJ7cwIOJU{!mkkjS{3o65-N$!!;HT z1%ZmM5~D$A2&6xQ5CnxZI$mgN*NYtnW2dPLSK$%FHF^&))EENiD6x4#cJ3;kQ9T}s zE;D`%mN?nR;gdB4^c!KR^sRX*BMY$DyT(0i`ZAaAn78fet)S&p6ui z0Q%>gkeVt&y1+q#iLx48j-8CF8VB@YCG)_U9-t;8lxNa5G#sZLdL)gS~X>2ORt#uI+>|