Changeset 589 in vbox for trunk/src/libs/xpcom18a4/xpcom
- Timestamp:
- Feb 4, 2007 12:25:57 PM (18 years ago)
- Location:
- trunk/src/libs/xpcom18a4/xpcom
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/MoreFiles/FSCopyObject.c
r1 r589 44 44 Copyright © 2002 Apple Computer, Inc., All Rights Reserved 45 45 */ 46 47 // Modified 2006-01-23 - added this comment. 46 48 47 49 #include "FSCopyObject.h" -
trunk/src/libs/xpcom18a4/xpcom/MoreFiles/FSCopyObject.h
r1 r589 42 42 */ 43 43 44 // Modified 2006-01-23 - added this comment. 44 45 45 46 #ifndef __FSCOPYOBJECT_H__ -
trunk/src/libs/xpcom18a4/xpcom/MoreFiles/MoreFilesX.c
r1 r589 69 69 <1> 1/25/02 JL MoreFilesX 1.0 70 70 */ 71 72 // Modified 2006-01-23 - added this comment. 71 73 72 74 #if defined(__MACH__) … … 2125 2127 /*****************************************************************************/ 2126 2128 2127 OSErr 2128 FSLockRange( 2129 /* Renamed from FSLockRange to MFX_FSLockRange to avoid a conflict with 2130 * the FSLockRange function present in the system library since Mac OS X 2131 * 10.4. */ 2132 2133 OSErr 2134 MFX_FSLockRange( 2129 2135 SInt16 refNum, 2130 2136 SInt32 rangeLength, … … 2148 2154 /*****************************************************************************/ 2149 2155 2150 OSErr 2151 FSUnlockRange( 2156 /* Renamed from FSUnlockRange to MFX_FSUnlockRange to avoid a conflict with 2157 * the FSUnlockRange function present in the system library since Mac OS X 2158 * 10.4. */ 2159 2160 OSErr 2161 MFX_FSUnlockRange( 2152 2162 SInt16 refNum, 2153 2163 SInt32 rangeLength, … … 2307 2317 /*****************************************************************************/ 2308 2318 2319 // This function exists in Mac OS X 10.5, we cannot re-define it here. 2320 // We don't use this function, so just don't compile it. 2321 #if 0 2309 2322 OSErr 2310 2323 FSVolumeMount( … … 2330 2343 return ( result ); 2331 2344 } 2345 #endif 2332 2346 2333 2347 /*****************************************************************************/ -
trunk/src/libs/xpcom18a4/xpcom/MoreFiles/MoreFilesX.h
r1 r589 84 84 do less work. 85 85 */ 86 87 // Modified 2006-01-23 - added this comment. 86 88 87 89 #ifndef __MOREFILESX__ … … 1333 1335 /*****************************************************************************/ 1334 1336 1335 #pragma mark FSLockRange 1336 1337 OSErr 1338 FSLockRange( 1337 #pragma mark MFX_FSLockRange 1338 /* Renamed from FSLockRange to MFX_FSLockRange to avoid a conflict with 1339 * the FSLockRange function present in the system library since Mac OS X 1340 * 10.4. */ 1341 1342 OSErr 1343 MFX_FSLockRange( 1339 1344 SInt16 refNum, 1340 1345 SInt32 rangeLength, … … 1356 1361 /*****************************************************************************/ 1357 1362 1358 #pragma mark FSUnlockRange 1359 1360 OSErr 1361 FSUnlockRange( 1363 #pragma mark MFX_FSUnlockRange 1364 /* Renamed from FSUnlockRange to MFX_FSUnlockRange to avoid a conflict with 1365 * the FSUnlockRange function present in the system library since Mac OS X 1366 * 10.4. */ 1367 1368 OSErr 1369 MFX_FSUnlockRange( 1362 1370 SInt16 refNum, 1363 1371 SInt32 rangeLength, … … 1483 1491 #pragma mark FSVolumeMount 1484 1492 1493 // This function exists in Mac OS X 10.5, we cannot re-define it here. 1494 // We don't use this function, so just don't compile it. 1495 #if 0 1485 1496 OSErr 1486 1497 FSVolumeMount( 1487 1498 const void *volMountInfo, 1488 1499 FSVolumeRefNum *volRefNum); 1500 #endif 1489 1501 1490 1502 /* -
trunk/src/libs/xpcom18a4/xpcom/io/nsILocalFileMac.idl
r1 r589 22 22 * Contributor(s): 23 23 * Conrad Carlen <[email protected]> 24 * Mark Mentovai <[email protected]> 24 25 * 25 26 * Alternatively, the contents of this file may be used under the terms of … … 51 52 native CFURLRef(CFURLRef); 52 53 53 [ uuid(614c3010-1dd2-11b2-be04-bcd57a64ffc9)]54 [scriptable, uuid(748f3ffe-27d9-4402-9de9-494badbeebf4)] 54 55 interface nsILocalFileMac : nsILocalFile 55 56 { … … 65 66 * 66 67 */ 67 68 [noscript] void initWithCFURL(in CFURLRef aCFURL); 68 69 69 70 /** … … 77 78 * 78 79 */ 79 80 [noscript] void initWithFSRef([const] in FSRefPtr aFSRef); 80 81 81 82 /** … … 88 89 * 89 90 */ 90 91 [noscript] void initWithFSSpec([const] in FSSpecPtr aFileSpec); 91 92 92 93 /** … … 100 101 * 101 102 */ 102 103 [noscript] void initToAppWithCreatorCode(in OSType aAppCreator); 103 104 104 105 /** … … 116 117 * 117 118 * @return 118 * 119 */ 120 121 119 * 120 */ 121 [noscript] CFURLRef getCFURL(); 122 122 123 /** 123 124 * getFSRef … … 133 134 * 134 135 * @return 135 * 136 */ 137 138 136 * 137 */ 138 [noscript] FSRef getFSRef(); 139 139 140 /** 140 141 * getFSSpec … … 148 149 * 149 150 * @return 150 * 151 */ 152 151 * 152 */ 153 [noscript] FSSpec getFSSpec(); 153 154 154 155 /** 155 156 * fileSizeWithResFork 156 * 157 * 157 158 * Returns the combined size of both the data fork and the resource 158 159 * fork (if present) rather than just the size of the data fork … … 160 161 * 161 162 */ 162 163 163 readonly attribute PRInt64 fileSizeWithResFork; 164 164 165 /** 165 166 * Use with SetFileType() to specify the signature of current process 166 167 */ 167 168 168 const unsigned long CURRENT_PROCESS_CREATOR = 0x8000000; 169 169 170 /** 170 171 * fileType, creator … … 173 174 * 174 175 */ 175 attribute OSType fileType;176 attribute OSType fileCreator;177 176 [noscript] attribute OSType fileType; 177 [noscript] attribute OSType fileCreator; 178 178 179 /** 179 180 * setFileTypeAndCreatorFromMIMEType … … 185 186 * 186 187 */ 187 188 188 void setFileTypeAndCreatorFromMIMEType(in string aMIMEType); 189 189 190 /** 190 191 * setFileTypeAndCreatorFromExtension … … 196 197 * 197 198 */ 198 199 199 void setFileTypeAndCreatorFromExtension(in string aExtension); 200 200 201 /** 201 202 * launchWithDoc … … 207 208 * 208 209 */ 209 210 void launchWithDoc(in nsILocalFile aDocToLoad, in boolean aLaunchInBackground); 210 211 211 212 /** … … 220 221 * 221 222 */ 222 223 void openDocWithApp(in nsILocalFile aAppToOpenWith, in boolean aLaunchInBackground); 223 224 224 225 /** … … 228 229 * 229 230 */ 230 boolean isPackage(); 231 boolean isPackage(); 232 233 /** 234 * bundleDisplayName 235 * 236 * returns the display name of the application bundle (usually the human 237 * readable name of the application) 238 */ 239 readonly attribute AString bundleDisplayName; 240 241 /** 242 * bundleIdentifier 243 * 244 * returns the identifier of the bundle 245 */ 246 readonly attribute AUTF8String bundleIdentifier; 231 247 }; 232 248 … … 240 256 241 257 NS_EXPORT nsresult NS_NewLocalFileWithFSSpec(const FSSpec* inSpec, PRBool followSymlinks, nsILocalFileMac* *result); 258 259 // NS_NewLocalFileWithFSRef is available since Mozilla 1.8.1. 260 NS_EXPORT nsresult NS_NewLocalFileWithFSRef(const FSRef* aFSRef, PRBool aFollowSymlinks, nsILocalFileMac** result); 242 261 } 243 262 %} -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileOSX.cpp
r1 r589 23 23 * Conrad Carlen <[email protected]> 24 24 * Jungshik Shin <[email protected]> 25 * Asaf Romano <[email protected]> 26 * Mark Mentovai <[email protected]> 25 27 * 26 28 * Alternatively, the contents of this file may be used under the terms of … … 39 41 40 42 #include "nsLocalFile.h" 43 #include "nsDirectoryServiceDefs.h" 41 44 42 45 #include "nsString.h" 43 46 #include "nsReadableUtils.h" 47 #include "nsIDirectoryEnumerator.h" 44 48 #include "nsISimpleEnumerator.h" 45 49 #include "nsITimelineService.h" … … 49 53 #include "prmem.h" 50 54 #include "nsCRT.h" 55 #include "nsHashKeys.h" 51 56 52 57 #include "MoreFilesX.h" 53 58 #include "FSCopyObject.h" 54 59 #include "nsAutoBuffer.h" 60 #include "nsTraceRefcntImpl.h" 55 61 56 62 // Mac Includes 57 #include <Aliases.h>58 #include <Gestalt.h>59 #include <AppleEvents.h>60 #include <AEDataModel.h>61 #include <Processes.h>62 63 #include <Carbon/Carbon.h> 63 64 64 65 // Unix Includes 66 #include <unistd.h> 65 67 #include <sys/stat.h> 68 #include <stdlib.h> 69 70 #if !defined(MAC_OS_X_VERSION_10_4) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4 71 #define GetAliasSizeFromRecord(aliasRecord) aliasRecord.aliasSize 72 #else 73 #define GetAliasSizeFromRecord(aliasRecord) GetAliasSizeFromPtr(&aliasRecord) 74 #endif 75 76 #define CHECK_mBaseRef() \ 77 PR_BEGIN_MACRO \ 78 if (!mBaseRef) \ 79 return NS_ERROR_NOT_INITIALIZED; \ 80 PR_END_MACRO 66 81 67 82 //***************************************************************************** … … 108 123 mFile.SetFollowLinks(mSavedState); 109 124 } 110 125 111 126 private: 112 127 nsLocalFile& mFile; … … 117 132 #pragma mark [nsDirEnumerator] 118 133 119 class nsDirEnumerator : public nsISimpleEnumerator 134 class nsDirEnumerator : public nsISimpleEnumerator, 135 public nsIDirectoryEnumerator 120 136 { 121 137 public: … … 130 146 } 131 147 132 nsresult Init(nsILocalFileMac* parent) 148 nsresult Init(nsILocalFileMac* parent) 133 149 { 134 150 NS_ENSURE_ARG(parent); 135 151 136 152 OSErr err; 137 153 nsresult rv; 138 154 FSRef parentRef; 139 155 140 156 rv = parent->GetFSRef(&parentRef); 141 157 if (NS_FAILED(rv)) 142 158 return rv; 143 159 144 160 mFSRefsArray = (FSRef *)nsMemory::Alloc(sizeof(FSRef) 145 161 * kRequestCountPerIteration); 146 162 if (!mFSRefsArray) 147 163 return NS_ERROR_OUT_OF_MEMORY; 148 164 149 165 err = ::FSOpenIterator(&parentRef, kFSIterateFlat, &mIterator); 150 166 if (err != noErr) 151 167 return MacErrorMapper(err); 152 168 153 169 return NS_OK; 154 170 } 155 171 156 NS_IMETHOD HasMoreElements(PRBool *result) 172 NS_IMETHOD HasMoreElements(PRBool *result) 157 173 { 158 174 if (mNext == nsnull) { … … 168 184 nsnull, 169 185 nsnull); 170 186 171 187 if (err == noErr || err == errFSNoMoreItems) { 172 188 mArrayCnt = actualCnt; … … 183 199 mArrayIndex++; 184 200 mNext = newFile; 185 } 201 } 186 202 } 187 203 *result = mNext != nsnull; 204 if (!*result) 205 Close(); 188 206 return NS_OK; 189 207 } 190 208 191 NS_IMETHOD GetNext(nsISupports **result) 209 NS_IMETHOD GetNext(nsISupports **result) 192 210 { 193 211 NS_ENSURE_ARG_POINTER(result); … … 206 224 } 207 225 226 NS_IMETHOD GetNextFile(nsIFile **result) 227 { 228 *result = nsnull; 229 PRBool hasMore = PR_FALSE; 230 nsresult rv = HasMoreElements(&hasMore); 231 if (NS_FAILED(rv) || !hasMore) 232 return rv; 233 *result = mNext; 234 NS_IF_ADDREF(*result); 235 mNext = nsnull; 236 return NS_OK; 237 } 238 239 NS_IMETHOD Close() 240 { 241 if (mIterator) { 242 ::FSCloseIterator(mIterator); 243 mIterator = nsnull; 244 } 245 if (mFSRefsArray) { 246 nsMemory::Free(mFSRefsArray); 247 mFSRefsArray = nsnull; 248 } 249 return NS_OK; 250 } 251 208 252 private: 209 ~nsDirEnumerator() 253 ~nsDirEnumerator() 210 254 { 211 if (mIterator) 212 ::FSCloseIterator(mIterator); 213 if (mFSRefsArray) 214 nsMemory::Free(mFSRefsArray); 255 Close(); 215 256 } 216 257 … … 221 262 kRequestCountPerIteration = ((4096 * 4) / sizeof(FSRef)) 222 263 }; 223 264 224 265 nsCOMPtr<nsILocalFileMac> mNext; 225 266 226 267 FSIterator mIterator; 227 268 FSRef *mFSRefsArray; … … 229 270 }; 230 271 231 NS_IMPL_ISUPPORTS 1(nsDirEnumerator, nsISimpleEnumerator)272 NS_IMPL_ISUPPORTS2(nsDirEnumerator, nsISimpleEnumerator, nsIDirectoryEnumerator) 232 273 233 274 #pragma mark - … … 242 283 dataHandle = nil; 243 284 } 244 285 245 286 ~StAEDesc() 246 287 { … … 305 346 #pragma mark [nsISupports] 306 347 307 NS_IMPL_THREADSAFE_ISUPPORTS 3(nsLocalFile,348 NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile, 308 349 nsILocalFileMac, 309 350 nsILocalFile, 310 nsIFile) 311 351 nsIFile, 352 nsIHashable) 353 312 354 NS_METHOD nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) 313 355 { … … 318 360 if (inst == NULL) 319 361 return NS_ERROR_OUT_OF_MEMORY; 320 362 321 363 nsresult rv = inst->QueryInterface(aIID, aInstancePtr); 322 364 if (NS_FAILED(rv)) … … 338 380 NS_IMETHODIMP nsLocalFile::Append(const nsAString& aNode) 339 381 { 340 return AppendNative(NS_ConvertU CS2toUTF8(aNode));382 return AppendNative(NS_ConvertUTF16toUTF8(aNode)); 341 383 } 342 384 … … 344 386 NS_IMETHODIMP nsLocalFile::AppendNative(const nsACString& aNode) 345 387 { 346 if (!mBaseRef)347 return NS_ERROR_NOT_INITIALIZED;388 // Check we are correctly initialized. 389 CHECK_mBaseRef(); 348 390 349 391 nsACString::const_iterator start, end; … … 372 414 NS_IMETHODIMP nsLocalFile::Normalize() 373 415 { 374 return NS_OK; 416 // Check we are correctly initialized. 417 CHECK_mBaseRef(); 418 419 // CFURL doesn't doesn't seem to resolve paths containing relative 420 // components, so we'll nick the stdlib code from nsLocalFileUnix 421 UInt8 path[PATH_MAX] = ""; 422 Boolean success; 423 success = ::CFURLGetFileSystemRepresentation(mBaseRef, true, path, PATH_MAX); 424 if (!success) 425 return NS_ERROR_FAILURE; 426 427 char resolved_path[PATH_MAX] = ""; 428 char *resolved_path_ptr = nsnull; 429 resolved_path_ptr = realpath((char*)path, resolved_path); 430 431 // if there is an error, the return is null. 432 if (!resolved_path_ptr) 433 return NSRESULT_FOR_ERRNO(); 434 435 // Need to know whether we're a directory to create a new CFURLRef 436 PRBool isDirectory; 437 nsresult rv = IsDirectory(&isDirectory); 438 NS_ENSURE_SUCCESS(rv, rv); 439 440 rv = NS_ERROR_FAILURE; 441 CFStringRef pathStrRef = 442 ::CFStringCreateWithCString(kCFAllocatorDefault, 443 resolved_path, 444 kCFStringEncodingUTF8); 445 if (pathStrRef) { 446 CFURLRef newURLRef = 447 ::CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pathStrRef, 448 kCFURLPOSIXPathStyle, isDirectory); 449 if (newURLRef) { 450 SetBaseRef(newURLRef); 451 ::CFRelease(newURLRef); 452 rv = NS_OK; 453 } 454 ::CFRelease(pathStrRef); 455 } 456 457 return rv; 375 458 } 376 459 … … 380 463 if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE) 381 464 return NS_ERROR_FILE_UNKNOWN_TYPE; 382 if (!mBaseRef) 383 return NS_ERROR_NOT_INITIALIZED; 384 465 466 // Check we are correctly initialized. 467 CHECK_mBaseRef(); 468 385 469 nsStringArray nonExtantNodes; 386 470 CFURLRef pathURLRef = mBaseRef; … … 389 473 nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer; 390 474 Boolean success; 391 475 392 476 // Work backwards through the path to find the last node which 393 477 // exists. Place the nodes which don't exist in an array and we'll … … 405 489 ::CFRelease(leafStrRef); 406 490 leafStrRef = nsnull; 407 491 408 492 // Get the parent of the leaf for the next go round 409 493 CFURLRef parent = ::CFURLCreateCopyDeletingLastPathComponent(NULL, pathURLRef); … … 423 507 if (nodesToCreate == 0) 424 508 return NS_ERROR_FILE_ALREADY_EXISTS; 425 426 OSErr err; 509 510 OSErr err; 427 511 nsAutoString nextNodeName; 428 512 for (PRInt32 i = nodesToCreate - 1; i > 0; i--) { … … 451 535 nsnull, nsnull, nsnull, nsnull); 452 536 } 453 537 454 538 return MacErrorMapper(err); 455 539 } … … 468 552 NS_IMETHODIMP nsLocalFile::SetLeafName(const nsAString& aLeafName) 469 553 { 470 return SetNativeLeafName(NS_ConvertU CS2toUTF8(aLeafName));554 return SetNativeLeafName(NS_ConvertUTF16toUTF8(aLeafName)); 471 555 } 472 556 … … 474 558 NS_IMETHODIMP nsLocalFile::GetNativeLeafName(nsACString& aNativeLeafName) 475 559 { 476 if (!mBaseRef) 477 return NS_ERROR_NOT_INITIALIZED; 560 // Check we are correctly initialized. 561 CHECK_mBaseRef(); 562 478 563 nsresult rv = NS_ERROR_FAILURE; 479 564 CFStringRef leafStrRef = ::CFURLCopyLastPathComponent(mBaseRef); … … 482 567 ::CFRelease(leafStrRef); 483 568 } 484 return rv; 569 return rv; 485 570 } 486 571 487 572 NS_IMETHODIMP nsLocalFile::SetNativeLeafName(const nsACString& aNativeLeafName) 488 573 { 489 if (!mBaseRef) 490 return NS_ERROR_NOT_INITIALIZED; 574 // Check we are correctly initialized. 575 CHECK_mBaseRef(); 576 491 577 nsresult rv = NS_ERROR_FAILURE; 492 578 CFURLRef parentURLRef = ::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, mBaseRef); … … 514 600 NS_IMETHODIMP nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString& newName) 515 601 { 516 return MoveCopy(newParentDir, newName, PR_TRUE, PR_FALSE);602 return CopyInternal(newParentDir, newName, PR_FALSE); 517 603 } 518 604 … … 520 606 NS_IMETHODIMP nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString& newName) 521 607 { 522 return MoveCopy(newParentDir, NS_ConvertUTF8toUCS2(newName), PR_TRUE, PR_FALSE);608 return CopyInternal(newParentDir, NS_ConvertUTF8toUTF16(newName), PR_FALSE); 523 609 } 524 610 … … 526 612 NS_IMETHODIMP nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString& newName) 527 613 { 528 return MoveCopy(newParentDir, newName, PR_TRUE, PR_TRUE);614 return CopyInternal(newParentDir, newName, PR_TRUE); 529 615 } 530 616 … … 532 618 NS_IMETHODIMP nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString& newName) 533 619 { 534 return MoveCopy(newParentDir, NS_ConvertUTF8toUCS2(newName), PR_TRUE, PR_TRUE);620 return CopyInternal(newParentDir, NS_ConvertUTF8toUTF16(newName), PR_TRUE); 535 621 } 536 622 … … 538 624 NS_IMETHODIMP nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString& newName) 539 625 { 540 return MoveCopy(newParentDir, newName, FALSE, FALSE);626 return MoveToNative(newParentDir, NS_ConvertUTF16toUTF8(newName)); 541 627 } 542 628 … … 544 630 NS_IMETHODIMP nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString& newName) 545 631 { 546 return MoveCopy(newParentDir, NS_ConvertUTF8toUCS2(newName), FALSE, FALSE); 632 // Check we are correctly initialized. 633 CHECK_mBaseRef(); 634 635 StFollowLinksState followLinks(*this, PR_FALSE); 636 637 PRBool isDirectory; 638 nsresult rv = IsDirectory(&isDirectory); 639 if (NS_FAILED(rv)) 640 return rv; 641 642 // Get the source path. 643 nsCAutoString srcPath; 644 rv = GetNativePath(srcPath); 645 if (NS_FAILED(rv)) 646 return rv; 647 648 // Build the destination path. 649 nsCOMPtr<nsIFile> parentDir = newParentDir; 650 if (!parentDir) { 651 if (newName.IsEmpty()) 652 return NS_ERROR_INVALID_ARG; 653 rv = GetParent(getter_AddRefs(parentDir)); 654 if (NS_FAILED(rv)) 655 return rv; 656 } 657 else { 658 PRBool exists; 659 rv = parentDir->Exists(&exists); 660 if (NS_FAILED(rv)) 661 return rv; 662 if (!exists) { 663 rv = parentDir->Create(nsIFile::DIRECTORY_TYPE, 0777); 664 if (NS_FAILED(rv)) 665 return rv; 666 } 667 } 668 669 nsCAutoString destPath; 670 rv = parentDir->GetNativePath(destPath); 671 if (NS_FAILED(rv)) 672 return rv; 673 674 if (!newName.IsEmpty()) 675 destPath.Append(NS_LITERAL_CSTRING("/") + newName); 676 else { 677 nsCAutoString leafName; 678 rv = GetNativeLeafName(leafName); 679 if (NS_FAILED(rv)) 680 return rv; 681 destPath.Append(NS_LITERAL_CSTRING("/") + leafName); 682 } 683 684 // Perform the move. 685 if (rename(srcPath.get(), destPath.get()) != 0) { 686 if (errno == EXDEV) { 687 // Can't move across volume (device) boundaries. Copy and remove. 688 rv = CopyToNative(parentDir, newName); 689 if (NS_SUCCEEDED(rv)) { 690 // Permit removal failure. 691 Remove(PR_TRUE); 692 } 693 } 694 else 695 rv = NSRESULT_FOR_ERRNO(); 696 697 if (NS_FAILED(rv)) 698 return rv; 699 } 700 701 // Update |this| to refer to the moved file. 702 CFURLRef newBaseRef = 703 ::CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)destPath.get(), 704 destPath.Length(), isDirectory); 705 if (!newBaseRef) 706 return NS_ERROR_FAILURE; 707 SetBaseRef(newBaseRef); 708 ::CFRelease(newBaseRef); 709 710 return rv; 547 711 } 548 712 … … 550 714 NS_IMETHODIMP nsLocalFile::Remove(PRBool recursive) 551 715 { 552 StFollowLinksState followLinks(*this, PR_FALSE); // XXX If we're an alias, never remove target 553 716 // Check we are correctly initialized. 717 CHECK_mBaseRef(); 718 719 // XXX If we're an alias, never remove target 720 StFollowLinksState followLinks(*this, PR_FALSE); 721 722 PRBool isDirectory; 723 nsresult rv = IsDirectory(&isDirectory); 724 if (NS_FAILED(rv)) 725 return rv; 726 727 if (recursive && isDirectory) { 728 FSRef fsRef; 729 rv = GetFSRefInternal(fsRef); 730 if (NS_FAILED(rv)) 731 return rv; 732 733 // Call MoreFilesX to do a recursive removal. 734 OSStatus err = ::FSDeleteContainer(&fsRef); 735 rv = MacErrorMapper(err); 736 } 737 else { 738 nsCAutoString path; 739 rv = GetNativePath(path); 740 if (NS_FAILED(rv)) 741 return rv; 742 743 const char* pathPtr = path.get(); 744 int status; 745 if (isDirectory) 746 status = rmdir(pathPtr); 747 else 748 status = unlink(pathPtr); 749 750 if (status != 0) 751 rv = NSRESULT_FOR_ERRNO(); 752 } 753 754 mCachedFSRefValid = PR_FALSE; 755 return rv; 756 } 757 758 /* attribute unsigned long permissions; */ 759 NS_IMETHODIMP nsLocalFile::GetPermissions(PRUint32 *aPermissions) 760 { 761 NS_ENSURE_ARG_POINTER(aPermissions); 762 554 763 FSRef fsRef; 555 764 nsresult rv = GetFSRefInternal(fsRef); 556 765 if (NS_FAILED(rv)) 557 766 return rv; 558 559 PRBool isDir; 560 rv = IsDirectory(&isDir); 561 if (NS_FAILED(rv)) 562 return rv; 563 564 OSErr err; 565 if (recursive && isDir) 566 err = ::FSDeleteContainer(&fsRef); 567 else 568 err = ::FSDeleteObject(&fsRef); 569 570 mCachedFSRefValid = PR_FALSE; 571 return MacErrorMapper(err); 572 } 573 574 /* attribute unsigned long permissions; */ 575 NS_IMETHODIMP nsLocalFile::GetPermissions(PRUint32 *aPermissions) 576 { 577 NS_ENSURE_ARG_POINTER(aPermissions); 578 579 FSRef fsRef; 580 nsresult rv = GetFSRefInternal(fsRef); 581 if (NS_FAILED(rv)) 582 return rv; 583 767 584 768 FSCatalogInfo catalogInfo; 585 769 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo, … … 598 782 if (NS_FAILED(rv)) 599 783 return rv; 600 784 601 785 FSCatalogInfo catalogInfo; 602 786 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo, … … 626 810 NS_IMETHODIMP nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModifiedTime) 627 811 { 812 // Check we are correctly initialized. 813 CHECK_mBaseRef(); 814 628 815 NS_ENSURE_ARG_POINTER(aLastModifiedTime); 629 816 630 817 FSRef fsRef; 631 818 nsresult rv = GetFSRefInternal(fsRef); 632 819 if (NS_FAILED(rv)) 633 820 return rv; 634 821 635 822 FSCatalogInfo catalogInfo; 636 823 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoContentMod, &catalogInfo, … … 638 825 if (err != noErr) 639 826 return MacErrorMapper(err); 640 *aLastModifiedTime = HFSPlustoNSPRTime(catalogInfo.contentModDate); 827 *aLastModifiedTime = HFSPlustoNSPRTime(catalogInfo.contentModDate); 641 828 return NS_OK; 642 829 } … … 644 831 NS_IMETHODIMP nsLocalFile::SetLastModifiedTime(PRInt64 aLastModifiedTime) 645 832 { 833 // Check we are correctly initialized. 834 CHECK_mBaseRef(); 835 646 836 OSErr err; 647 837 nsresult rv; … … 661 851 if (err != noErr) 662 852 return MacErrorMapper(err); 663 853 664 854 /* Notify the parent if this is a file */ 665 855 notifyParent = (0 == (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)); … … 695 885 NS_ENSURE_ARG_POINTER(aFileSize); 696 886 *aFileSize = 0; 697 887 698 888 FSRef fsRef; 699 889 nsresult rv = GetFSRefInternal(fsRef); 700 890 if (NS_FAILED(rv)) 701 891 return rv; 702 892 703 893 FSCatalogInfo catalogInfo; 704 894 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags + kFSCatInfoDataSizes, &catalogInfo, … … 706 896 if (err != noErr) 707 897 return MacErrorMapper(err); 708 898 709 899 // FSGetCatalogInfo can return a bogus size for directories sometimes, so only 710 900 // rely on the answer for files … … 716 906 NS_IMETHODIMP nsLocalFile::SetFileSize(PRInt64 aFileSize) 717 907 { 908 // Check we are correctly initialized. 909 CHECK_mBaseRef(); 910 718 911 FSRef fsRef; 719 912 nsresult rv = GetFSRefInternal(fsRef); 720 913 if (NS_FAILED(rv)) 721 914 return rv; 722 723 SInt16 refNum; 915 916 SInt16 refNum; 724 917 OSErr err = ::FSOpenFork(&fsRef, 0, nsnull, fsWrPerm, &refNum); 725 918 if (err != noErr) 726 919 return MacErrorMapper(err); 727 920 err = ::FSSetForkSize(refNum, fsFromStart, aFileSize); 728 ::FSCloseFork(refNum); 729 921 ::FSCloseFork(refNum); 922 730 923 return MacErrorMapper(err); 731 924 } … … 734 927 NS_IMETHODIMP nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSizeOfLink) 735 928 { 929 // Check we are correctly initialized. 930 CHECK_mBaseRef(); 931 736 932 NS_ENSURE_ARG_POINTER(aFileSizeOfLink); 737 933 738 934 StFollowLinksState followLinks(*this, PR_FALSE); 739 935 return GetFileSize(aFileSizeOfLink); … … 768 964 NS_IMETHODIMP nsLocalFile::GetNativePath(nsACString& aNativePath) 769 965 { 770 if (!mBaseRef) 771 return NS_ERROR_NOT_INITIALIZED; 966 // Check we are correctly initialized. 967 CHECK_mBaseRef(); 968 772 969 nsresult rv = NS_ERROR_FAILURE; 773 970 CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(mBaseRef, kCFURLPOSIXPathStyle); … … 782 979 NS_IMETHODIMP nsLocalFile::Exists(PRBool *_retval) 783 980 { 981 // Check we are correctly initialized. 982 CHECK_mBaseRef(); 983 784 984 NS_ENSURE_ARG_POINTER(_retval); 785 985 *_retval = PR_FALSE; 786 986 787 987 FSRef fsRef; 788 988 if (NS_SUCCEEDED(GetFSRefInternal(fsRef, PR_TRUE))) { 789 989 *_retval = PR_TRUE; 790 990 } 791 991 792 992 return NS_OK; 793 993 } … … 796 996 NS_IMETHODIMP nsLocalFile::IsWritable(PRBool *_retval) 797 997 { 998 // Check we are correctly initialized. 999 CHECK_mBaseRef(); 1000 798 1001 NS_ENSURE_ARG_POINTER(_retval); 799 1002 *_retval = PR_FALSE; 800 1003 801 1004 FSRef fsRef; 802 1005 nsresult rv = GetFSRefInternal(fsRef); 803 1006 if (NS_FAILED(rv)) 804 1007 return rv; 805 if (::FSCheckLock(&fsRef) == noErr) { 1008 if (::FSCheckLock(&fsRef) == noErr) { 806 1009 PRUint32 permissions; 807 1010 rv = GetPermissions(&permissions); … … 816 1019 NS_IMETHODIMP nsLocalFile::IsReadable(PRBool *_retval) 817 1020 { 1021 // Check we are correctly initialized. 1022 CHECK_mBaseRef(); 1023 818 1024 NS_ENSURE_ARG_POINTER(_retval); 819 1025 *_retval = PR_FALSE; 820 1026 821 1027 PRUint32 permissions; 822 1028 nsresult rv = GetPermissions(&permissions); … … 830 1036 NS_IMETHODIMP nsLocalFile::IsExecutable(PRBool *_retval) 831 1037 { 1038 // Check we are correctly initialized. 1039 CHECK_mBaseRef(); 1040 832 1041 NS_ENSURE_ARG_POINTER(_retval); 833 1042 *_retval = PR_FALSE; 834 1043 835 1044 FSRef fsRef; 836 1045 nsresult rv = GetFSRefInternal(fsRef); 837 1046 if (NS_FAILED(rv)) 838 1047 return rv; 839 1048 840 1049 LSRequestedInfo theInfoRequest = kLSRequestAllInfo; 841 1050 LSItemInfoRecord theInfo; … … 852 1061 NS_ENSURE_ARG_POINTER(_retval); 853 1062 *_retval = PR_FALSE; 854 1063 855 1064 FSRef fsRef; 856 1065 nsresult rv = GetFSRefInternal(fsRef); 857 1066 if (NS_FAILED(rv)) 858 1067 return rv; 859 1068 860 1069 FSCatalogInfo catalogInfo; 861 HFSUniStr255 leafName; 862 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfo NodeFlags, &catalogInfo,1070 HFSUniStr255 leafName; 1071 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catalogInfo, 863 1072 &leafName, nsnull, nsnull); 864 1073 if (err != noErr) 865 1074 return MacErrorMapper(err); 866 1075 867 1076 FileInfo *fInfoPtr = (FileInfo *)(catalogInfo.finderInfo); // Finder flags are in the same place whether we use FileInfo or FolderInfo 868 1077 if ((fInfoPtr->finderFlags & kIsInvisible) != 0) { … … 882 1091 NS_ENSURE_ARG_POINTER(_retval); 883 1092 *_retval = PR_FALSE; 884 1093 885 1094 FSRef fsRef; 886 1095 nsresult rv = GetFSRefInternal(fsRef, PR_FALSE); 887 1096 if (NS_FAILED(rv)) 888 1097 return rv; 889 1098 890 1099 FSCatalogInfo catalogInfo; 891 1100 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo, … … 902 1111 NS_ENSURE_ARG_POINTER(_retval); 903 1112 *_retval = PR_FALSE; 904 1113 905 1114 FSRef fsRef; 906 1115 nsresult rv = GetFSRefInternal(fsRef, PR_FALSE); 907 1116 if (NS_FAILED(rv)) 908 1117 return rv; 909 1118 910 1119 FSCatalogInfo catalogInfo; 911 1120 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo, … … 920 1129 NS_IMETHODIMP nsLocalFile::IsSymlink(PRBool *_retval) 921 1130 { 1131 // Check we are correctly initialized. 1132 CHECK_mBaseRef(); 1133 922 1134 NS_ENSURE_ARG(_retval); 923 1135 *_retval = PR_FALSE; 924 if (!mBaseRef) 925 return NS_ERROR_NOT_INITIALIZED; 926 1136 1137 // Check we are correctly initialized. 1138 CHECK_mBaseRef(); 1139 927 1140 FSRef fsRef; 928 1141 if (::CFURLGetFSRef(mBaseRef, &fsRef)) { … … 950 1163 951 1164 NS_ADDREF(*_retval); 952 1165 953 1166 return NS_OK; 954 1167 } … … 957 1170 NS_IMETHODIMP nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) 958 1171 { 1172 return EqualsInternal(inFile, PR_TRUE, _retval); 1173 } 1174 1175 nsresult 1176 nsLocalFile::EqualsInternal(nsISupports* inFile, PRBool aUpdateCache, 1177 PRBool *_retval) 1178 { 959 1179 NS_ENSURE_ARG_POINTER(_retval); 960 1180 *_retval = PR_FALSE; 961 1181 962 1182 nsCOMPtr<nsILocalFileMac> inMacFile(do_QueryInterface(inFile)); 963 1183 if (!inFile) 964 1184 return NS_OK; 965 1185 1186 nsLocalFile* inLF = 1187 NS_STATIC_CAST(nsLocalFile*, (nsILocalFileMac*) inMacFile); 1188 966 1189 // If both exist, compare FSRefs 967 1190 FSRef thisFSRef, inFSRef; 968 nsresult rv1 = GetFSRef (&thisFSRef);969 nsresult rv2 = in MacFile->GetFSRef(&inFSRef);1191 nsresult rv1 = GetFSRefInternal(thisFSRef, aUpdateCache); 1192 nsresult rv2 = inLF->GetFSRefInternal(inFSRef, aUpdateCache); 970 1193 if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) { 971 1194 *_retval = (thisFSRef == inFSRef); 972 1195 return NS_OK; 973 1196 } 974 // If one exists and the other doesn't, not equal 1197 // If one exists and the other doesn't, not equal 975 1198 if (rv1 != rv2) 976 1199 return NS_OK; 977 1200 978 1201 // Arg, we have to get their paths and compare 979 1202 nsCAutoString thisPath, inPath; … … 983 1206 return NS_ERROR_FAILURE; 984 1207 *_retval = thisPath.Equals(inPath); 985 1208 986 1209 return NS_OK; 987 1210 } … … 990 1213 NS_IMETHODIMP nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) 991 1214 { 1215 // Check we are correctly initialized. 1216 CHECK_mBaseRef(); 1217 992 1218 NS_ENSURE_ARG_POINTER(_retval); 993 1219 *_retval = PR_FALSE; … … 1009 1235 if (inPath[thisPathLen] == kPathSepChar) 1010 1236 *_retval = PR_TRUE; 1011 } 1237 } 1012 1238 return NS_OK; 1013 1239 } … … 1018 1244 NS_ENSURE_ARG_POINTER(aParent); 1019 1245 *aParent = nsnull; 1020 if (!mBaseRef) 1021 return NS_ERROR_NOT_INITIALIZED; 1022 1246 1247 // Check we are correctly initialized. 1248 CHECK_mBaseRef(); 1249 1023 1250 nsLocalFile *newFile = nsnull; 1024 1251 … … 1039 1266 } 1040 1267 ::CFRelease(parentURLRef); 1041 } 1268 } 1042 1269 return rv; 1043 1270 } … … 1052 1279 PRBool isDir; 1053 1280 rv = IsDirectory(&isDir); 1054 if (NS_FAILED(rv)) 1281 if (NS_FAILED(rv)) 1055 1282 return rv; 1056 1283 if (!isDir) … … 1067 1294 } 1068 1295 *aDirectoryEntries = dirEnum; 1069 1296 1070 1297 return NS_OK; 1071 1298 } … … 1081 1308 NS_IMETHODIMP nsLocalFile::InitWithPath(const nsAString& filePath) 1082 1309 { 1083 return InitWithNativePath(NS_ConvertU CS2toUTF8(filePath));1310 return InitWithNativePath(NS_ConvertUTF16toUTF8(filePath)); 1084 1311 } 1085 1312 … … 1087 1314 NS_IMETHODIMP nsLocalFile::InitWithNativePath(const nsACString& filePath) 1088 1315 { 1089 if (filePath.IsEmpty() || filePath.First() != '/') 1316 nsCAutoString fixedPath; 1317 if (Substring(filePath, 0, 2).EqualsLiteral("~/")) { 1318 nsCOMPtr<nsIFile> homeDir; 1319 nsCAutoString homePath; 1320 nsresult rv = NS_GetSpecialDirectory(NS_OS_HOME_DIR, 1321 getter_AddRefs(homeDir)); 1322 NS_ENSURE_SUCCESS(rv, rv); 1323 rv = homeDir->GetNativePath(homePath); 1324 NS_ENSURE_SUCCESS(rv, rv); 1325 1326 fixedPath = homePath + Substring(filePath, 1, filePath.Length() - 1); 1327 } 1328 else if (filePath.IsEmpty() || filePath.First() != '/') 1090 1329 return NS_ERROR_FILE_UNRECOGNIZED_PATH; 1091 // On 10.2, huge paths crash CFURLGetFSRef()1092 if (filePath.Length() > PATH_MAX)1093 return NS_ERROR_FILE_NAME_TOO_LONG; 1094 // A nd, apath with consecutive '/'s which are not between1095 // nodes alsocrashes CFURLGetFSRef(). Consecutive '/'s which1330 else 1331 fixedPath.Assign(filePath); 1332 1333 // A path with consecutive '/'s which are not between 1334 // nodes crashes CFURLGetFSRef(). Consecutive '/'s which 1096 1335 // are between actual nodes are OK. So, convert consecutive 1097 1336 // '/'s to a single one. 1098 nsCAutoString fixedPath;1099 fixedPath.Assign(filePath);1100 1337 fixedPath.ReplaceSubstring("//", "/"); 1338 1339 // On 10.2, huge paths also crash CFURLGetFSRef() 1340 if (fixedPath.Length() > PATH_MAX) 1341 return NS_ERROR_FILE_NAME_TOO_LONG; 1101 1342 1102 1343 CFStringRef pathAsCFString; … … 1113 1354 SetBaseRef(pathAsCFURL); 1114 1355 ::CFRelease(pathAsCFURL); 1356 ::CFRelease(pathAsCFString); 1115 1357 return NS_OK; 1116 1358 } … … 1120 1362 { 1121 1363 NS_ENSURE_ARG(aFile); 1122 1364 1123 1365 nsCOMPtr<nsILocalFileMac> aFileMac(do_QueryInterface(aFile)); 1124 1366 if (!aFileMac) … … 1137 1379 { 1138 1380 NS_ENSURE_ARG_POINTER(aFollowLinks); 1139 1381 1140 1382 *aFollowLinks = mFollowLinks; 1141 1383 return NS_OK; … … 1160 1402 if (NS_FAILED(rv)) 1161 1403 return rv; 1162 1404 1163 1405 *_retval = PR_Open(path.get(), flags, mode); 1164 1406 if (! *_retval) … … 1177 1419 if (NS_FAILED(rv)) 1178 1420 return rv; 1179 1421 1180 1422 *_retval = fopen(path.get(), mode); 1181 1423 if (! *_retval) … … 1188 1430 NS_IMETHODIMP nsLocalFile::Load(PRLibrary **_retval) 1189 1431 { 1432 // Check we are correctly initialized. 1433 CHECK_mBaseRef(); 1434 1190 1435 NS_ENSURE_ARG_POINTER(_retval); 1191 1436 … … 1197 1442 return rv; 1198 1443 1444 #ifdef NS_BUILD_REFCNT_LOGGING 1445 nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE); 1446 #endif 1447 1199 1448 *_retval = PR_LoadLibrary(path.get()); 1449 1450 #ifdef NS_BUILD_REFCNT_LOGGING 1451 nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE); 1452 #endif 1200 1453 1201 1454 NS_TIMELINE_STOP_TIMER("PR_LoadLibrary"); … … 1204 1457 if (!*_retval) 1205 1458 return NS_ERROR_FAILURE; 1206 1459 1207 1460 return NS_OK; 1208 1461 } … … 1211 1464 NS_IMETHODIMP nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable) 1212 1465 { 1466 // Check we are correctly initialized. 1467 CHECK_mBaseRef(); 1468 1213 1469 NS_ENSURE_ARG_POINTER(aDiskSpaceAvailable); 1214 1470 1215 1471 FSRef fsRef; 1216 1472 nsresult rv = GetFSRefInternal(fsRef); 1217 1473 if (NS_FAILED(rv)) 1218 1474 return rv; 1219 1475 1220 1476 OSErr err; 1221 1477 FSCatalogInfo catalogInfo; … … 1224 1480 if (err != noErr) 1225 1481 return MacErrorMapper(err); 1226 1227 FSVolumeInfo volumeInfo; 1482 1483 FSVolumeInfo volumeInfo; 1228 1484 err = ::FSGetVolumeInfo(catalogInfo.volume, 0, nsnull, kFSVolInfoSizes, 1229 1485 &volumeInfo, nsnull, nsnull); 1230 1486 if (err != noErr) 1231 1487 return MacErrorMapper(err); 1232 1488 1233 1489 *aDiskSpaceAvailable = volumeInfo.freeBytes; 1234 1490 return NS_OK; … … 1238 1494 NS_IMETHODIMP nsLocalFile::AppendRelativePath(const nsAString& relativeFilePath) 1239 1495 { 1240 return AppendRelativeNativePath(NS_ConvertU CS2toUTF8(relativeFilePath));1496 return AppendRelativeNativePath(NS_ConvertUTF16toUTF8(relativeFilePath)); 1241 1497 } 1242 1498 1243 1499 /* [noscript] void appendRelativeNativePath (in ACString relativeFilePath); */ 1244 1500 NS_IMETHODIMP nsLocalFile::AppendRelativeNativePath(const nsACString& relativeFilePath) 1245 { 1501 { 1246 1502 if (relativeFilePath.IsEmpty()) 1247 1503 return NS_OK; 1248 // No leading '/' 1504 // No leading '/' 1249 1505 if (relativeFilePath.First() == '/') 1250 1506 return NS_ERROR_FILE_UNRECOGNIZED_PATH; … … 1255 1511 relativeFilePath.EndReading(pathEnd); 1256 1512 nsACString::const_iterator nodeEnd(nodeBegin); 1257 1513 1258 1514 while (nodeEnd != pathEnd) { 1259 1515 FindCharInReadable(kPathSepChar, nodeEnd, pathEnd); … … 1275 1531 if (NS_FAILED(rv)) 1276 1532 return rv; 1277 1533 1278 1534 AliasHandle aliasH; 1279 1535 OSErr err = ::FSNewAlias(nsnull, &fsRef, &aliasH); 1280 1536 if (err != noErr) 1281 1537 return MacErrorMapper(err); 1282 1538 1283 1539 PRUint32 bytes = ::GetHandleSize((Handle) aliasH); 1284 1540 ::HLock((Handle) aliasH); … … 1287 1543 ::DisposeHandle((Handle) aliasH); 1288 1544 NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY); 1289 1545 1290 1546 aPersistentDescriptor = buf; 1291 1547 PR_Free(buf); … … 1299 1555 return NS_ERROR_INVALID_ARG; 1300 1556 1557 // Support pathnames as user-supplied descriptors if they begin with '/' 1558 // or '~'. These characters do not collide with the base64 set used for 1559 // encoding alias records. 1560 char first = aPersistentDescriptor.First(); 1561 if (first == '/' || first == '~') 1562 return InitWithNativePath(aPersistentDescriptor); 1563 1301 1564 nsresult rv = NS_OK; 1302 1303 PRUint32 dataSize = aPersistentDescriptor.Length(); 1565 1566 PRUint32 dataSize = aPersistentDescriptor.Length(); 1304 1567 char* decodedData = PL_Base64Decode(PromiseFlatCString(aPersistentDescriptor).get(), dataSize, nsnull); 1305 1568 if (!decodedData) { … … 1307 1570 return NS_ERROR_FAILURE; 1308 1571 } 1309 1572 1310 1573 // Cast to an alias record and resolve. 1311 PRInt32 aliasSize = (dataSize * 3) / 4;1312 AliasRecord aliasHeader = *(AliasPtr)decodedData;1313 if (alias Header.aliasSize > aliasSize) {// be paranoid about having too few data1574 AliasRecord aliasHeader = *(AliasPtr)decodedData; 1575 PRInt32 aliasSize = GetAliasSizeFromRecord(aliasHeader); 1576 if (aliasSize > (dataSize * 3) / 4) { // be paranoid about having too few data 1314 1577 PR_Free(decodedData); 1315 1578 return NS_ERROR_FAILURE; 1316 1579 } 1317 1318 aliasSize = aliasHeader.aliasSize; 1319 1580 1320 1581 // Move the now-decoded data into the Handle. 1321 1582 // The size of the decoded data is 3/4 the size of the encoded data. See plbase64.h … … 1330 1591 FSRef resolvedFSRef; 1331 1592 OSErr err = ::FSResolveAlias(nsnull, (AliasHandle)newHandle, &resolvedFSRef, &changed); 1332 1593 1333 1594 rv = MacErrorMapper(err); 1334 1595 DisposeHandle(newHandle); 1335 1596 if (NS_FAILED(rv)) 1336 1597 return rv; 1337 1598 1338 1599 return InitWithFSRef(&resolvedFSRef); 1339 1600 } … … 1348 1609 OSErr err; 1349 1610 ProcessSerialNumber process; 1350 1611 1351 1612 nsresult rv = GetFSRefInternal(fsRefToReveal); 1352 1613 if (NS_FAILED(rv)) 1353 1614 return rv; 1354 1615 1355 1616 err = ::FindRunningAppBySignature ('MACS', process); 1356 if (err == noErr) { 1617 if (err == noErr) { 1357 1618 err = ::AECreateDesc(typeProcessSerialNumber, (Ptr)&process, sizeof(process), &myAddressDesc); 1358 1619 if (err == noErr) { 1359 1620 // Create the FinderEvent 1360 1621 err = ::AECreateAppleEvent(kAEMiscStandards, kAEMakeObjectsVisible, &myAddressDesc, 1361 kAutoGenerateReturnID, kAnyTransactionID, &aeEvent); 1622 kAutoGenerateReturnID, kAnyTransactionID, &aeEvent); 1362 1623 if (err == noErr) { 1363 1624 // Create the file list … … 1381 1642 } 1382 1643 } 1383 1644 1384 1645 return NS_OK; 1385 1646 } … … 1408 1669 { 1409 1670 NS_ENSURE_ARG(aCFURL); 1410 1671 1411 1672 SetBaseRef(aCFURL); 1412 1673 return NS_OK; … … 1418 1679 NS_ENSURE_ARG(aFSRef); 1419 1680 nsresult rv = NS_ERROR_FAILURE; 1420 1681 1421 1682 CFURLRef newURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, aFSRef); 1422 1683 if (newURLRef) { … … 1432 1693 { 1433 1694 NS_ENSURE_ARG(aFileSpec); 1434 1695 1435 1696 FSRef fsRef; 1436 1697 OSErr err = ::FSpMakeFSRef(aFileSpec, &fsRef); … … 1440 1701 CInfoPBRec pBlock; 1441 1702 FSSpec parentDirSpec; 1442 1703 1443 1704 memset(&pBlock, 0, sizeof(CInfoPBRec)); 1444 1705 parentDirSpec.name[0] = 0; … … 1450 1711 if (err != noErr) 1451 1712 return MacErrorMapper(err); 1452 1713 1453 1714 parentDirSpec.vRefNum = aFileSpec->vRefNum; 1454 1715 parentDirSpec.parID = pBlock.dirInfo.ioDrParID; … … 1463 1724 if (NS_FAILED(rv)) 1464 1725 return rv; 1465 return Append(nsDependentString(unicodeName.unicode, unicodeName.length)); 1726 return Append(nsDependentString(unicodeName.unicode, unicodeName.length)); 1466 1727 } 1467 1728 return MacErrorMapper(err); … … 1500 1761 { 1501 1762 NS_ENSURE_ARG_POINTER(_retval); 1502 if (!mBaseRef) 1503 return NS_ERROR_NOT_INITIALIZED; 1504 1763 1764 // Check we are correctly initialized. 1765 CHECK_mBaseRef(); 1766 1505 1767 OSErr err; 1506 1768 FSRef fsRef; … … 1510 1772 err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNone, 1511 1773 nsnull, nsnull, _retval, nsnull); 1512 return MacErrorMapper(err); 1774 return MacErrorMapper(err); 1513 1775 } 1514 1776 else if (rv == NS_ERROR_FILE_NOT_FOUND) { … … 1532 1794 catalogInfo.nodeID == fsRtDirID, 1533 1795 hfsName)) == noErr) 1534 err = ::FSMakeFSSpec(catalogInfo.volume, catalogInfo.nodeID, hfsName, _retval); 1796 err = ::FSMakeFSSpec(catalogInfo.volume, catalogInfo.nodeID, hfsName, _retval); 1535 1797 } 1536 1798 } … … 1546 1808 { 1547 1809 NS_ENSURE_ARG_POINTER(aFileSizeWithResFork); 1548 1810 1549 1811 FSRef fsRef; 1550 1812 nsresult rv = GetFSRefInternal(fsRef); 1551 1813 if (NS_FAILED(rv)) 1552 1814 return rv; 1553 1815 1554 1816 FSCatalogInfo catalogInfo; 1555 1817 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoDataSizes + kFSCatInfoRsrcSizes, … … 1557 1819 if (err != noErr) 1558 1820 return MacErrorMapper(err); 1559 1821 1560 1822 *aFileSizeWithResFork = catalogInfo.dataLogicalSize + catalogInfo.rsrcLogicalSize; 1561 1823 return NS_OK; … … 1566 1828 { 1567 1829 NS_ENSURE_ARG_POINTER(aFileType); 1568 1830 1569 1831 FSRef fsRef; 1570 1832 nsresult rv = GetFSRefInternal(fsRef); 1571 1833 if (NS_FAILED(rv)) 1572 1834 return rv; 1573 1574 FinderInfo fInfo; 1835 1836 FinderInfo fInfo; 1575 1837 OSErr err = ::FSGetFinderInfo(&fsRef, &fInfo, nsnull, nsnull); 1576 1838 if (err != noErr) … … 1586 1848 if (NS_FAILED(rv)) 1587 1849 return rv; 1588 1850 1589 1851 OSErr err = ::FSChangeCreatorType(&fsRef, 0, aFileType); 1590 1852 return MacErrorMapper(err); … … 1595 1857 { 1596 1858 NS_ENSURE_ARG_POINTER(aFileCreator); 1597 1859 1598 1860 FSRef fsRef; 1599 1861 nsresult rv = GetFSRefInternal(fsRef); 1600 1862 if (NS_FAILED(rv)) 1601 1863 return rv; 1602 1603 FinderInfo fInfo; 1864 1865 FinderInfo fInfo; 1604 1866 OSErr err = ::FSGetFinderInfo(&fsRef, &fInfo, nsnull, nsnull); 1605 1867 if (err != noErr) … … 1615 1877 if (NS_FAILED(rv)) 1616 1878 return rv; 1617 1879 1618 1880 OSErr err = ::FSChangeCreatorType(&fsRef, aFileCreator, 0); 1619 1881 return MacErrorMapper(err); … … 1657 1919 return rv; 1658 1920 } 1659 1921 1660 1922 LSLaunchFlags theLaunchFlags = kLSLaunchDefaults; 1661 1923 LSLaunchFSRefSpec thelaunchSpec; … … 1701 1963 if (!isExecutable) 1702 1964 return NS_ERROR_FILE_EXECUTION_FAILED; 1703 1965 1704 1966 rv = appFileMac->GetFSRef(&appFSRef); 1705 1967 if (NS_FAILED(rv)) … … 1716 1978 return MacErrorMapper(err); 1717 1979 } 1718 1980 1719 1981 LSLaunchFlags theLaunchFlags = kLSLaunchDefaults; 1720 1982 LSLaunchFSRefSpec thelaunchSpec; … … 1741 2003 NS_ENSURE_ARG(_retval); 1742 2004 *_retval = PR_FALSE; 1743 2005 1744 2006 FSRef fsRef; 1745 2007 nsresult rv = GetFSRefInternal(fsRef); … … 1773 2035 } 1774 2036 2037 NS_IMETHODIMP 2038 nsLocalFile::GetBundleDisplayName(nsAString& outBundleName) 2039 { 2040 PRBool isPackage = PR_FALSE; 2041 nsresult rv = IsPackage(&isPackage); 2042 if (NS_FAILED(rv) || !isPackage) 2043 return NS_ERROR_FAILURE; 2044 2045 nsAutoString name; 2046 rv = GetLeafName(name); 2047 if (NS_FAILED(rv)) 2048 return rv; 2049 2050 PRInt32 length = name.Length(); 2051 if (Substring(name, length - 4, length).EqualsLiteral(".app")) { 2052 // 4 characters in ".app" 2053 outBundleName = Substring(name, 0, length - 4); 2054 } 2055 else 2056 outBundleName = name; 2057 2058 return NS_OK; 2059 } 2060 2061 NS_IMETHODIMP 2062 nsLocalFile::GetBundleIdentifier(nsACString& outBundleIdentifier) 2063 { 2064 nsresult rv = NS_ERROR_FAILURE; 2065 2066 CFURLRef urlRef; 2067 if (NS_SUCCEEDED(GetCFURL(&urlRef))) { 2068 CFBundleRef bundle = ::CFBundleCreate(NULL, urlRef); 2069 if (bundle) { 2070 CFStringRef bundleIdentifier = ::CFBundleGetIdentifier(bundle); 2071 if (bundleIdentifier) 2072 rv = CFStringReftoUTF8(bundleIdentifier, outBundleIdentifier); 2073 2074 ::CFRelease(bundle); 2075 } 2076 ::CFRelease(urlRef); 2077 } 2078 2079 return rv; 2080 } 2081 1775 2082 1776 2083 //***************************************************************************** … … 1783 2090 { 1784 2091 NS_ENSURE_ARG(aCFURLRef); 1785 2092 1786 2093 ::CFRetain(aCFURLRef); 1787 2094 if (mBaseRef) … … 1789 2096 mBaseRef = aCFURLRef; 1790 2097 1791 mFollowLinksDirty = PR_TRUE; 2098 mFollowLinksDirty = PR_TRUE; 1792 2099 UpdateTargetRef(); 1793 2100 mCachedFSRefValid = PR_FALSE; … … 1797 2104 nsresult nsLocalFile::UpdateTargetRef() 1798 2105 { 1799 if (!mBaseRef)1800 return NS_ERROR_NOT_INITIALIZED;1801 2106 // Check we are correctly initialized. 2107 CHECK_mBaseRef(); 2108 1802 2109 if (mFollowLinksDirty) { 1803 2110 if (mTargetRef) { … … 1812 2119 if (::CFURLGetFSRef(mBaseRef, &fsRef)) { 1813 2120 Boolean targetIsFolder, wasAliased; 1814 if (FSResolveAliasFile(&fsRef, true /*resolveAliasChains*/, 2121 if (FSResolveAliasFile(&fsRef, true /*resolveAliasChains*/, 1815 2122 &targetIsFolder, &wasAliased) == noErr && wasAliased) { 1816 2123 ::CFRelease(mTargetRef); … … 1848 2155 { 1849 2156 nsresult rv = NS_ERROR_FAILURE; 1850 2157 1851 2158 CFURLRef whichURLRef = mFollowLinks ? mTargetRef : mBaseRef; 1852 2159 NS_ENSURE_TRUE(whichURLRef, NS_ERROR_NULL_POINTER); 1853 2160 1854 2161 CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(whichURLRef, kCFURLPOSIXPathStyle); 1855 2162 if (pathStrRef) { … … 1860 2167 } 1861 2168 1862 nsresult nsLocalFile::MoveCopy(nsIFile* aParentDir, const nsAString& newName, PRBool isCopy, PRBool followLinks) 1863 { 2169 nsresult nsLocalFile::CopyInternal(nsIFile* aParentDir, 2170 const nsAString& newName, 2171 PRBool followLinks) 2172 { 2173 // Check we are correctly initialized. 2174 CHECK_mBaseRef(); 2175 1864 2176 StFollowLinksState srcFollowState(*this, followLinks); 1865 2177 … … 1867 2179 OSErr err; 1868 2180 FSRef srcFSRef, newFSRef; 1869 2181 1870 2182 rv = GetFSRefInternal(srcFSRef); 1871 2183 if (NS_FAILED(rv)) 1872 2184 return rv; 1873 2185 1874 2186 nsCOMPtr<nsIFile> newParentDir = aParentDir; 1875 CFURLRef newBaseURLRef;1876 2187 1877 2188 if (!newParentDir) { … … 1880 2191 rv = GetParent(getter_AddRefs(newParentDir)); 1881 2192 if (NS_FAILED(rv)) 1882 return rv; 1883 } 1884 2193 return rv; 2194 } 2195 1885 2196 // If newParentDir does not exist, create it 1886 2197 PRBool exists; … … 1889 2200 return rv; 1890 2201 if (!exists) { 1891 rv = newParentDir->Create(nsIFile::DIRECTORY_TYPE, 0 666);2202 rv = newParentDir->Create(nsIFile::DIRECTORY_TYPE, 0777); 1892 2203 if (NS_FAILED(rv)) 1893 2204 return rv; 1894 2205 } 1895 2206 1896 2207 FSRef destFSRef; 1897 2208 nsCOMPtr<nsILocalFileMac> newParentDirMac(do_QueryInterface(newParentDir)); … … 1901 2212 if (NS_FAILED(rv)) 1902 2213 return rv; 1903 1904 if (isCopy) { 1905 err = ::FSCopyObject(&srcFSRef, &destFSRef, 1906 newName.Length(), newName.Length() ? PromiseFlatString(newName).get() : nsnull, 1907 0, kFSCatInfoNone, false, false, nsnull, nsnull, &newFSRef); 1908 // don't update ourselves on a copy 1909 } 1910 else { 1911 // According to the API: "If 'this' is a file, and the destination file already 1912 // exists, moveTo will replace the old file." 1913 FSCatalogInfo catalogInfo; 1914 HFSUniStr255 leafName; 1915 err = ::FSGetCatalogInfo(&srcFSRef, kFSCatInfoNodeFlags, &catalogInfo, 1916 newName.IsEmpty() ? &leafName : nsnull, nsnull, nsnull); 1917 if (err == noErr) { 1918 if (!(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)) { 1919 FSRef oldFileRef; 1920 if (newName.IsEmpty()) 1921 err = ::FSMakeFSRefUnicode(&destFSRef, leafName.length, leafName.unicode, 1922 kTextEncodingUnknown, &oldFileRef); 1923 else 1924 err = ::FSMakeFSRefUnicode(&destFSRef, newName.Length(), PromiseFlatString(newName).get(), 1925 kTextEncodingUnknown, &oldFileRef); 1926 if (err == noErr) 1927 ::FSDeleteObject(&oldFileRef); 1928 } 1929 } 1930 // First, try the quick way which works only within the same volume 1931 err = ::FSMoveRenameObjectUnicode(&srcFSRef, &destFSRef, 1932 newName.Length(), newName.Length() ? PromiseFlatString(newName).get() : nsnull, 1933 kTextEncodingUnknown, &newFSRef); 1934 1935 if (err == diffVolErr) { 1936 // If on different volumes, resort to copy & delete 1937 err = ::FSCopyObject(&srcFSRef, &destFSRef, 1938 newName.Length(), newName.Length() ? PromiseFlatString(newName).get() : nsnull, 1939 0, kFSCatInfoNone, false, false, nsnull, nsnull, &newFSRef); 1940 ::FSDeleteObjects(&srcFSRef); 1941 } 1942 if (err == noErr) { 1943 newBaseURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, &newFSRef); 1944 if (!newBaseURLRef) 1945 return NS_ERROR_FAILURE; 1946 SetBaseRef(newBaseURLRef); 1947 ::CFRelease(newBaseURLRef); 1948 } 1949 } 2214 2215 err = 2216 ::FSCopyObject(&srcFSRef, &destFSRef, newName.Length(), 2217 newName.Length() ? PromiseFlatString(newName).get() : NULL, 2218 0, kFSCatInfoNone, false, false, NULL, NULL, &newFSRef); 2219 1950 2220 return MacErrorMapper(err); 1951 2221 } 1952 2222 1953 const PRInt64 kMil isecsPerSec = 1000LL;2223 const PRInt64 kMillisecsPerSec = 1000LL; 1954 2224 const PRInt64 kUTCDateTimeFractionDivisor = 65535LL; 1955 2225 … … 1957 2227 { 1958 2228 // Start with seconds since Jan. 1, 1904 GMT 1959 PRInt64 result = ((PRInt64)utcTime.highSeconds << 32) + (PRInt64)utcTime.lowSeconds; 2229 PRInt64 result = ((PRInt64)utcTime.highSeconds << 32) + (PRInt64)utcTime.lowSeconds; 1960 2230 // Subtract to convert to NSPR epoch of 1970 1961 2231 result -= kJanuaryFirst1970Seconds; 1962 // Convert to mil isecs1963 result *= kMil isecsPerSec;1964 // Convert the fraction to mil isecs and add it1965 result += ((PRInt64)utcTime.fraction * kMil isecsPerSec) / kUTCDateTimeFractionDivisor;2232 // Convert to millisecs 2233 result *= kMillisecsPerSec; 2234 // Convert the fraction to millisecs and add it 2235 result += ((PRInt64)utcTime.fraction * kMillisecsPerSec) / kUTCDateTimeFractionDivisor; 1966 2236 1967 2237 return result; … … 1970 2240 void nsLocalFile::NSPRtoHFSPlusTime(PRInt64 nsprTime, UTCDateTime& utcTime) 1971 2241 { 1972 PRInt64 fraction = nsprTime % kMil isecsPerSec;1973 PRInt64 seconds = (nsprTime / kMil isecsPerSec) + kJanuaryFirst1970Seconds;2242 PRInt64 fraction = nsprTime % kMillisecsPerSec; 2243 PRInt64 seconds = (nsprTime / kMillisecsPerSec) + kJanuaryFirst1970Seconds; 1974 2244 utcTime.highSeconds = (UInt16)((PRUint64)seconds >> 32); 1975 2245 utcTime.lowSeconds = (UInt32)seconds; 1976 utcTime.fraction = (UInt16)((fraction * kUTCDateTimeFractionDivisor) / kMil isecsPerSec);2246 utcTime.fraction = (UInt16)((fraction * kUTCDateTimeFractionDivisor) / kMillisecsPerSec); 1977 2247 } 1978 2248 … … 1984 2254 kCFStringEncodingUTF8, 0, PR_FALSE, nsnull, 0, &usedBufLen); 1985 2255 if (charsConverted == inStrLen) { 2256 #if 0 /* bird: too new? */ 2257 aOutStr.SetLength(usedBufLen); 2258 if (aOutStr.Length() != usedBufLen) 2259 return NS_ERROR_OUT_OF_MEMORY; 2260 UInt8 *buffer = (UInt8*) aOutStr.BeginWriting(); 2261 2262 ::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen), 2263 kCFStringEncodingUTF8, 0, false, buffer, usedBufLen, &usedBufLen); 2264 rv = NS_OK; 2265 #else 1986 2266 nsAutoBuffer<UInt8, FILENAME_BUFFER_SIZE> buffer; 1987 2267 if (buffer.EnsureElemCapacity(usedBufLen + 1)) { … … 1992 2272 rv = NS_OK; 1993 2273 } 2274 #endif 1994 2275 } 1995 2276 return rv; 2277 } 2278 2279 // nsIHashable 2280 2281 NS_IMETHODIMP 2282 nsLocalFile::Equals(nsIHashable* aOther, PRBool *aResult) 2283 { 2284 return EqualsInternal(aOther, PR_FALSE, aResult); 2285 } 2286 2287 NS_IMETHODIMP 2288 nsLocalFile::GetHashCode(PRUint32 *aResult) 2289 { 2290 CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(mBaseRef, kCFURLPOSIXPathStyle); 2291 nsCAutoString path; 2292 CFStringReftoUTF8(pathStrRef, path); 2293 *aResult = HashString(path); 2294 return NS_OK; 1996 2295 } 1997 2296 … … 2032 2331 nsresult NS_NewNativeLocalFile(const nsACString& path, PRBool followLinks, nsILocalFile **result) 2033 2332 { 2034 return NS_NewLocalFile(NS_ConvertUTF8toU CS2(path), followLinks, result);2333 return NS_NewLocalFile(NS_ConvertUTF8toUTF16(path), followLinks, result); 2035 2334 } 2036 2335 … … 2053 2352 } 2054 2353 2354 nsresult NS_NewLocalFileWithFSRef(const FSRef* aFSRef, PRBool aFollowLinks, nsILocalFileMac** result) 2355 { 2356 nsLocalFile* file = new nsLocalFile(); 2357 if (file == nsnull) 2358 return NS_ERROR_OUT_OF_MEMORY; 2359 NS_ADDREF(file); 2360 2361 file->SetFollowLinks(aFollowLinks); 2362 2363 nsresult rv = file->InitWithFSRef(aFSRef); 2364 if (NS_FAILED(rv)) { 2365 NS_RELEASE(file); 2366 return rv; 2367 } 2368 *result = file; 2369 return NS_OK; 2370 } 2371 2055 2372 //***************************************************************************** 2056 2373 // Static Functions … … 2060 2377 { 2061 2378 nsresult outErr; 2062 2379 2063 2380 switch (inErr) 2064 2381 { … … 2074 2391 outErr = NS_ERROR_FILE_ALREADY_EXISTS; 2075 2392 break; 2076 2393 2077 2394 case dskFulErr: 2078 2395 outErr = NS_ERROR_FILE_DISK_FULL; 2079 2396 break; 2080 2397 2081 2398 case fLckdErr: 2082 2399 outErr = NS_ERROR_FILE_IS_LOCKED; 2083 2400 break; 2084 2401 2085 2402 // Can't find good map for some 2086 2403 case bdNamErr: … … 2088 2405 break; 2089 2406 2090 default: 2407 default: 2091 2408 outErr = NS_ERROR_FAILURE; 2092 2409 break; … … 2099 2416 ProcessInfoRec info; 2100 2417 OSErr err = noErr; 2101 2418 2102 2419 outPsn.highLongOfPSN = 0; 2103 2420 outPsn.lowLongOfPSN = kNoProcess; 2104 2421 2105 2422 while (PR_TRUE) 2106 2423 { … … 2116 2433 if (err != noErr) 2117 2434 return err; 2118 2435 2119 2436 if (info.processSignature == aAppSig) 2120 2437 return noErr; … … 2147 2464 if (!sUnicodeNormalizer) { // OS X 10.2 or earlier 2148 2465 CopyUTF8toUTF16(aSrc, aResult); 2149 return; 2466 return; 2150 2467 } 2151 2468 … … 2159 2476 if (!inStr) { 2160 2477 CopyUTF8toUTF16(aSrc, aResult); 2161 return; 2162 } 2163 2164 ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8); 2478 return; 2479 } 2480 2481 ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8); 2165 2482 2166 2483 sUnicodeNormalizer(inStr, kCFStringNormalizationFormC); … … 2169 2486 const UniChar* chars = CFStringGetCharactersPtr(inStr); 2170 2487 2171 if (chars) 2488 if (chars) 2172 2489 aResult.Assign(chars, length); 2173 2490 else { -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileOSX.h
r1 r589 42 42 #include "nsILocalFileMac.h" 43 43 #include "nsString.h" 44 #include "nsIHashable.h" 44 45 45 46 class nsDirEnumerator; … … 56 57 //***************************************************************************** 57 58 58 class NS_COM nsLocalFile : public nsILocalFileMac 59 class NS_COM nsLocalFile : public nsILocalFileMac, 60 public nsIHashable 59 61 { 60 62 friend class nsDirEnumerator; … … 71 73 NS_DECL_NSILOCALFILE 72 74 NS_DECL_NSILOCALFILEMAC 75 NS_DECL_NSIHASHABLE 73 76 74 77 public: … … 88 91 nsresult GetFSRefInternal(FSRef& aFSSpec, PRBool bForceUpdateCache = PR_TRUE); 89 92 nsresult GetPathInternal(nsACString& path); // Returns path WRT mFollowLinks 93 nsresult EqualsInternal(nsISupports* inFile, 94 PRBool aUpdateCache, PRBool *_retval); 90 95 91 nsresult MoveCopy(nsIFile* newParentDir, const nsAString &newName, PRBool isCopy, PRBool followLinks); 96 nsresult CopyInternal(nsIFile* newParentDir, 97 const nsAString& newName, 98 PRBool followLinks); 92 99 93 100 static PRInt64 HFSPlustoNSPRTime(const UTCDateTime& utcTime); -
trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_unixish_x86.cpp
r1 r589 21 21 * 22 22 * Contributor(s): 23 * Mark Mentovai <[email protected]> 23 24 * 24 25 * Alternatively, the contents of this file may be used under the terms of … … 79 80 #ifdef __GNUC__ /* Gnu compiler. */ 80 81 PRUint32 result; 81 / /Each param takes at most 2, 4-byte words82 //It doesn't matter if we push too many words, and calculating the exact83 // ammount takes time.82 /* Each param takes at most 2, 4-byte words 83 It doesn't matter if we push too many words, and calculating the exact 84 amount takes time. */ 84 85 PRUint32 n = paramCount << 3; 85 86 void (*fn_copy) (unsigned int, nsXPTCVariant *, PRUint32 *) = invoke_copy_to_stack; 86 int temp1, temp2, temp3; 87 87 int temp1, temp2; 88 89 /* These are only significant when KEEP_STACK_16_BYTE_ALIGNED is 90 defined. Otherwise, they're just placeholders to keep the parameter 91 indices the same for aligned and unaligned users in the inline asm 92 block. */ 93 unsigned int saved_esp; 94 88 95 __asm__ __volatile__( 96 #ifdef KEEP_STACK_16_BYTE_ALIGNED 97 "movl %%esp, %3\n\t" 98 #endif 89 99 "subl %8, %%esp\n\t" /* make room for params */ 100 #ifdef KEEP_STACK_16_BYTE_ALIGNED 101 /* For the second CALL, there will be one parameter before the ones 102 copied by invoke_copy_to_stack. Make sure that the stack will be 103 aligned for that CALL. */ 104 "subl $4, %%esp\n\t" 105 "andl $0xfffffff0, %%esp\n\t" 106 /* For the first CALL, there are three parameters. Leave padding to 107 ensure alignment. */ 108 "subl $4, %%esp\n\t" 109 /* The third parameter to invoke_copy_to_stack is the destination pointer. 110 It needs to point into the parameter area prepared for the second CALL, 111 leaving room for the |that| parameter. This reuses |n|, which was 112 the stack space to reserve, but that's OK because it's no longer needed 113 if the stack is being kept aligned. */ 114 "leal 8(%%esp), %8\n\t" 115 "pushl %8\n\t" 116 #else 90 117 "pushl %%esp\n\t" 118 #endif 91 119 "pushl %7\n\t" 92 120 "pushl %6\n\t" 93 "call *%0\n\t" /* copy params */ 121 "call *%9\n\t" /* copy params */ 122 #ifdef KEEP_STACK_16_BYTE_ALIGNED 123 /* The stack is still aligned from the first CALL. Keep it aligned for 124 the next one by popping past the parameters from the first CALL and 125 leaving space for the first (|that|) parameter for the second CALL. */ 126 "addl $0x14, %%esp\n\t" 127 #else 94 128 "addl $0xc, %%esp\n\t" 129 #endif 95 130 "movl %4, %%ecx\n\t" 96 131 #ifdef CFRONT_STYLE_THIS_ADJUST … … 115 150 #endif 116 151 "call *(%%edx)\n\t" /* safe to not cleanup esp */ 152 #ifdef KEEP_STACK_16_BYTE_ALIGNED 153 "movl %3, %%esp\n\t" 154 #else 117 155 "addl $4, %%esp\n\t" 118 156 "addl %8, %%esp" 157 #endif 119 158 : "=a" (result), /* %0 */ 120 159 "=c" (temp1), /* %1 */ 121 160 "=d" (temp2), /* %2 */ 122 "=g" (temp3) /* %3 */ 161 #ifdef KEEP_STACK_16_BYTE_ALIGNED 162 "=&g" (saved_esp) /* %3 */ 163 #else 164 /* Don't waste a register, this isn't used if alignment is unimportant */ 165 "=m" (saved_esp) /* %3 */ 166 #endif 123 167 : "g" (that), /* %4 */ 124 168 "g" (methodIndex), /* %5 */ 125 169 "1" (paramCount), /* %6 */ 126 170 "2" (params), /* %7 */ 171 #ifdef KEEP_STACK_16_BYTE_ALIGNED 172 /* Must be in a register, it's the target of an LEA instruction */ 173 "r" (n), /* %8 */ 174 #else 127 175 "g" (n), /* %8 */ 128 "0" (fn_copy) /* %3 */ 176 #endif 177 "0" (fn_copy) /* %9 */ 129 178 : "memory" 130 179 ); 131 180 132 181 return result; 133 182 … … 136 185 #endif /* __GNUC__ */ 137 186 138 } 187 } -
trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_x86.cpp
r1 r589 40 40 #include "xptcprivate.h" 41 41 #include "xptc_platforms_unixish_x86.h" 42 /*#include "xptiprivate.h"*/ 42 43 43 44 static nsresult … … 104 105 105 106 #ifdef __GNUC__ /* Gnu Compiler. */ 107 108 #ifdef KEEP_STACK_16_BYTE_ALIGNED 109 /* Make sure the stack is 16-byte aligned. Do that by aligning to 16 bytes and 110 * then subtracting 4 so the three subsequent pushes result in a 16-byte aligned 111 * stack. */ 112 #define ALIGN_STACK_DECL \ 113 unsigned int saved_esp; 114 115 #define ALIGN_STACK_SAVE \ 116 "movl %%esp, %3\n\t" 117 118 #define ALIGN_STACK_ALIGN \ 119 "addl $0x4, %%esp\n\t" \ 120 "andl $0xfffffff0, %%esp\n\t" \ 121 "subl $0x4, %%esp\n\t" 122 123 #define STACK_RESTORE \ 124 "movl %3, %%esp\n" 125 126 #define ALIGN_STACK_REGS_IN \ 127 , "=r"(saved_esp) /* 3 */ 128 129 #define ALIGN_STACK_REGS_OUT \ 130 , "3"(saved_esp) 131 132 #else 133 #define ALIGN_STACK_DECL 134 #define ALIGN_STACK_SAVE 135 #define ALIGN_STACK_ALIGN 136 #define STACK_RESTORE \ 137 "addl $12, %%esp\n" 138 #define ALIGN_STACK_REGS_IN 139 #define ALIGN_STACK_REGS_OUT 140 #endif 141 106 142 #define STUB_ENTRY(n) \ 107 143 nsresult nsXPTCStubBase::Stub##n() \ … … 110 146 int temp0, temp1; \ 111 147 register nsresult result; \ 148 ALIGN_STACK_DECL \ 112 149 __asm__ __volatile__( \ 150 ALIGN_STACK_SAVE \ 151 ALIGN_STACK_ALIGN \ 113 152 "leal 0x0c(%%ebp), %%ecx\n\t" /* args */ \ 114 153 "pushl %%ecx\n\t" \ … … 117 156 "pushl %%ecx\n\t" \ 118 157 "call *%%edx\n\t" /* PrepareAndDispatch */ \ 119 "addl $12, %%esp"\158 STACK_RESTORE /* "addl $12, %%esp" or restore saved */ \ 120 159 : "=a" (result), /* %0 */ \ 121 160 "=&c" (temp0), /* %1 */ \ 122 161 "=d" (temp1) /* %2 */ \ 162 ALIGN_STACK_REGS_IN \ 123 163 : "2" (method) /* %2 */ \ 124 : "memory" ); \ 164 ALIGN_STACK_REGS_OUT \ 165 : "memory" \ 166 ); \ 125 167 return result; \ 126 168 } -
trunk/src/libs/xpcom18a4/xpcom/tests/nsIFileTest.cpp
r1 r589 1 1 #include "nsILocalFile.h" 2 #if 0 /* too new */ 3 #include "nsStringGlue.h" 4 #else 2 5 #include "nsString.h" 6 #endif 3 7 4 8 #include <stdio.h> … … 8 12 #include "nsIServiceManager.h" 9 13 #include "nsIMemory.h" 10 #include "nsXPIDLString.h" 14 15 #include "nsComponentManagerUtils.h" 16 #include "nsCOMPtr.h" 11 17 12 18 void Passed(); … … 63 69 rv = file->GetNativePath(pathName); 64 70 VerifyResult(rv); 65 71 66 72 printf("filepath: %s\n", pathName.get()); 67 73 } … … 70 76 { 71 77 nsILocalFile* file = nsnull; 72 nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, 73 nsnull, 74 NS_GET_IID(nsILocalFile), 75 (void**)&file); 76 77 if (NS_FAILED(rv) || (!file)) 78 nsresult rv = CallCreateInstance(NS_LOCAL_FILE_CONTRACTID, &file); 79 80 81 if (NS_FAILED(rv) || (!file)) 78 82 { 79 83 printf("create nsILocalFile failed\n"); … … 88 92 rv = file->InitWithNativePath(nsDependentCString(creationPath)); 89 93 VerifyResult(rv); 90 94 91 95 printf("Getting Filename\n"); 92 96 rv = file->GetNativeLeafName(leafName); … … 105 109 GetPaths(file); 106 110 107 111 108 112 printf("Check For Existence\n"); 109 113 … … 121 125 PRInt32 whatToCreate, PRInt32 perm) 122 126 { 123 nsCOMPtr<nsILocalFile> file; 124 nsresult rv = 125 nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, 126 nsnull, 127 NS_GET_IID(nsILocalFile), 128 (void **)getter_AddRefs(file)); 129 130 if (NS_FAILED(rv) || (!file)) 127 nsresult rv; 128 nsCOMPtr<nsILocalFile> file = 129 do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); 130 131 if (NS_FAILED(rv) || (!file)) 131 132 { 132 133 printf("create nsILocalFile failed\n"); … … 139 140 rv = file->InitWithNativePath(nsDependentCString(creationPath)); 140 141 VerifyResult(rv); 141 142 142 143 printf("Appending %s\n", appendPath); 143 144 rv = file->AppendRelativeNativePath(nsDependentCString(appendPath)); 144 145 VerifyResult(rv); 145 146 146 147 printf("Check For Existence\n"); 147 148 … … 155 156 156 157 157 rv = file->Create(whatToCreate, perm); 158 rv = file->Create(whatToCreate, perm); 158 159 VerifyResult(rv); 159 160 … … 161 162 VerifyResult(rv); 162 163 163 164 164 165 if (!exists) 165 166 { … … 167 168 return; 168 169 } 169 170 } 170 171 } 171 172 172 173 void CreateUniqueTest(const char* creationPath, const char* appendPath, 173 174 PRInt32 whatToCreate, PRInt32 perm) 174 175 { 175 nsCOMPtr<nsILocalFile> file; 176 nsresult rv = 177 nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, 178 nsnull, 179 NS_GET_IID(nsILocalFile), 180 (void **)getter_AddRefs(file)); 181 182 if (NS_FAILED(rv) || (!file)) 176 nsresult rv; 177 nsCOMPtr<nsILocalFile> file = 178 do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); 179 180 if (NS_FAILED(rv) || (!file)) 183 181 { 184 182 printf("create nsILocalFile failed\n"); … … 191 189 rv = file->InitWithNativePath(nsDependentCString(creationPath)); 192 190 VerifyResult(rv); 193 191 194 192 printf("Appending %s\n", appendPath); 195 193 rv = file->AppendNative(nsDependentCString(appendPath)); 196 194 VerifyResult(rv); 197 195 198 196 printf("Check For Existence\n"); 199 197 … … 207 205 208 206 209 rv = file->CreateUnique(whatToCreate, perm); 207 rv = file->CreateUnique(whatToCreate, perm); 210 208 VerifyResult(rv); 211 209 … … 213 211 VerifyResult(rv); 214 212 215 213 216 214 if (!exists) 217 215 { … … 219 217 return; 220 218 } 221 222 } 219 220 } 223 221 224 222 … … 226 224 CopyTest(const char *testFile, const char *targetDir) 227 225 { 228 nsCOMPtr<nsILocalFile> file;229 nsCOMPtr<nsILocalFile> dir;230 231 226 printf("start copy test\n"); 232 227 233 nsresult rv = 234 nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL, 235 NS_GET_IID(nsILocalFile), 236 (void**)getter_AddRefs(file)); 237 238 if (NS_FAILED(rv) || (!file)) 228 nsresult rv; 229 nsCOMPtr<nsILocalFile> file = 230 do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); 231 232 if (NS_FAILED(rv) || (!file)) 239 233 { 240 234 printf("create nsILocalFile failed\n"); … … 244 238 rv = file->InitWithNativePath(nsDependentCString(testFile)); 245 239 VerifyResult(rv); 246 247 rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL, 248 NS_GET_IID(nsILocalFile), 249 (void**)getter_AddRefs(dir)); 250 251 if (NS_FAILED(rv) || (!dir)) 240 241 nsCOMPtr<nsILocalFile> dir = 242 do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); 243 244 if (NS_FAILED(rv) || (!dir)) 252 245 { 253 246 printf("create nsILocalFile failed\n"); … … 263 256 printf("end copy test\n"); 264 257 } 265 258 266 259 void 267 260 DeletionTest(const char* creationPath, const char* appendPath, PRBool recursive) 268 261 { 269 nsCOMPtr<nsILocalFile> file; 270 nsresult rv = 271 nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL, 272 NS_GET_IID(nsILocalFile), 273 (void**)getter_AddRefs(file)); 274 275 if (NS_FAILED(rv) || (!file)) 262 nsresult rv; 263 nsCOMPtr<nsILocalFile> file = 264 do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); 265 266 if (NS_FAILED(rv) || (!file)) 276 267 { 277 268 printf("create nsILocalFile failed\n"); … … 284 275 rv = file->InitWithNativePath(nsDependentCString(creationPath)); 285 276 VerifyResult(rv); 286 277 287 278 printf("Appending %s\n", appendPath); 288 279 rv = file->AppendNative(nsDependentCString(appendPath)); 289 280 VerifyResult(rv); 290 281 291 282 printf("Check For Existance\n"); 292 283 … … 299 290 printf("no.\n"); 300 291 301 rv = file->Remove(recursive); 292 rv = file->Remove(recursive); 302 293 VerifyResult(rv); 303 294 304 295 rv = file->Exists(&exists); 305 296 VerifyResult(rv); 306 297 307 298 if (exists) 308 299 { … … 310 301 return; 311 302 } 312 313 } 314 315 void 303 304 } 305 306 void 316 307 MoveTest(const char *testFile, const char *targetDir) 317 308 { … … 322 313 nsresult rv; 323 314 nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); 324 325 if (!file) 315 316 if (!file) 326 317 { 327 318 printf("create nsILocalFile failed\n"); … … 331 322 rv = file->InitWithNativePath(nsDependentCString(testFile)); 332 323 VerifyResult(rv); 333 324 334 325 nsCOMPtr<nsILocalFile> dir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); 335 336 if (!dir) 326 327 if (!dir) 337 328 { 338 329 printf("create nsILocalFile failed\n"); … … 352 343 } 353 344 354 345 // move up the number of directories in moveUpCount, then append "foo/bar" 346 void 347 NormalizeTest(const char *testPath, int moveUpCount, 348 const char *expected) 349 { 350 Banner("Normalize Test"); 351 352 nsresult rv; 353 nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); 354 355 if (!file) 356 { 357 printf("create nsILocalFile failed\n"); 358 return; 359 } 360 361 rv = file->InitWithNativePath(nsDependentCString(testPath)); 362 VerifyResult(rv); 363 364 nsCOMPtr<nsIFile> parent; 365 nsAutoString path; 366 for (int i=0; i < moveUpCount; i++) 367 { 368 rv = file->GetParent(getter_AddRefs(parent)); 369 VerifyResult(rv); 370 rv = parent->GetPath(path); 371 VerifyResult(rv); 372 rv = file->InitWithPath(path); 373 VerifyResult(rv); 374 } 375 376 if (!parent) { 377 printf("Getting parent failed!\n"); 378 return; 379 } 380 381 rv = parent->Append(NS_LITERAL_STRING("foo")); 382 VerifyResult(rv); 383 rv = parent->Append(NS_LITERAL_STRING("bar")); 384 VerifyResult(rv); 385 386 rv = parent->Normalize(); 387 VerifyResult(rv); 388 389 nsCAutoString newPath; 390 rv = parent->GetNativePath(newPath); 391 VerifyResult(rv); 392 393 nsCOMPtr<nsILocalFile> 394 expectedFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); 395 396 if (!expectedFile) 397 { 398 printf("create nsILocalFile failed\n"); 399 return; 400 } 401 rv = expectedFile->InitWithNativePath(nsDependentCString(expected)); 402 VerifyResult(rv); 403 404 rv = expectedFile->Normalize(); 405 VerifyResult(rv); 406 407 nsCAutoString expectedPath; 408 rv = expectedFile->GetNativePath(expectedPath); 409 VerifyResult(rv); 410 411 if (!newPath.Equals(expectedPath)) { 412 printf("ERROR: Normalize() test Failed!\n"); 413 printf(" Got: %s\n", newPath.get()); 414 printf("Expected: %s\n", expectedPath); 415 } 416 417 printf("end normalize test.\n"); 418 } 355 419 356 420 int main(void) … … 361 425 NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); 362 426 registrar->AutoRegister(nsnull); 363 427 364 428 #if defined(XP_WIN) || defined(XP_OS2) 365 InitTest("c:\\temp\\", "sub1/sub2/"); 366 InitTest("d:\\temp\\", "sub1\\sub2\\"); 429 InitTest("c:\\temp\\", "sub1/sub2/"); // expect failure 430 InitTest("d:\\temp\\", "sub1\\sub2\\"); // expect failure 367 431 368 432 CreationTest("c:\\temp\\", "file.txt", nsIFile::NORMAL_FILE_TYPE, 0644); … … 385 449 #else 386 450 #ifdef XP_UNIX 387 InitTest("/tmp/", "sub1/sub2/"); 388 451 InitTest("/tmp/", "sub1/sub2/"); // expect failure 452 389 453 CreationTest("/tmp", "file.txt", nsIFile::NORMAL_FILE_TYPE, 0644); 390 454 DeletionTest("/tmp/", "file.txt", PR_FALSE); 391 455 392 456 CreationTest("/tmp", "mumble/a/b/c/d/e/f/g/h/i/j/k/", nsIFile::DIRECTORY_TYPE, 0644); 393 457 DeletionTest("/tmp", "mumble", PR_TRUE); 394 CopyTest("/tmp/test.txt", "/tmp/foo"); 458 459 CreationTest("/tmp", "file", nsIFile::NORMAL_FILE_TYPE, 0644); 460 CopyTest("/tmp/file", "/tmp/newDir"); 461 MoveTest("/tmp/file", "/tmp/newDir/anotherNewDir"); 462 DeletionTest("/tmp", "newDir", PR_TRUE); 463 464 CreationTest("/tmp", "qux/quux", nsIFile::NORMAL_FILE_TYPE, 0644); 465 CreationTest("/tmp", "foo/bar", nsIFile::NORMAL_FILE_TYPE, 0644); 466 NormalizeTest("/tmp/qux/quux/..", 1, "/tmp/foo/bar"); 467 DeletionTest("/tmp", "qux", PR_TRUE); 468 DeletionTest("/tmp", "foo", PR_TRUE); 395 469 396 470 #endif /* XP_UNIX */
Note:
See TracChangeset
for help on using the changeset viewer.