VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileOSX.cpp@ 1184

Last change on this file since 1184 was 589, checked in by vboxsync, 18 years ago

Make it build and run on Mac OS X.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.6 KB
Line 
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2001, 2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Conrad Carlen <[email protected]>
24 * Jungshik Shin <[email protected]>
25 * Asaf Romano <[email protected]>
26 * Mark Mentovai <[email protected]>
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
39 *
40 * ***** END LICENSE BLOCK ***** */
41
42#include "nsLocalFile.h"
43#include "nsDirectoryServiceDefs.h"
44
45#include "nsString.h"
46#include "nsReadableUtils.h"
47#include "nsIDirectoryEnumerator.h"
48#include "nsISimpleEnumerator.h"
49#include "nsITimelineService.h"
50#include "nsVoidArray.h"
51
52#include "plbase64.h"
53#include "prmem.h"
54#include "nsCRT.h"
55#include "nsHashKeys.h"
56
57#include "MoreFilesX.h"
58#include "FSCopyObject.h"
59#include "nsAutoBuffer.h"
60#include "nsTraceRefcntImpl.h"
61
62// Mac Includes
63#include <Carbon/Carbon.h>
64
65// Unix Includes
66#include <unistd.h>
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
81
82//*****************************************************************************
83// Static Function Prototypes
84//*****************************************************************************
85
86static nsresult MacErrorMapper(OSErr inErr);
87static OSErr FindRunningAppBySignature(OSType aAppSig, ProcessSerialNumber& outPsn);
88static void CopyUTF8toUTF16NFC(const nsACString& aSrc, nsAString& aResult);
89
90//*****************************************************************************
91// Local Helper Classes
92//*****************************************************************************
93
94#pragma mark -
95#pragma mark [FSRef operator==]
96
97bool operator==(const FSRef& lhs, const FSRef& rhs)
98{
99 return (::FSCompareFSRefs(&lhs, &rhs) == noErr);
100}
101
102#pragma mark -
103#pragma mark [StFollowLinksState]
104
105class StFollowLinksState
106{
107 public:
108 StFollowLinksState(nsLocalFile& aFile) :
109 mFile(aFile)
110 {
111 mFile.GetFollowLinks(&mSavedState);
112 }
113
114 StFollowLinksState(nsLocalFile& aFile, PRBool followLinksState) :
115 mFile(aFile)
116 {
117 mFile.GetFollowLinks(&mSavedState);
118 mFile.SetFollowLinks(followLinksState);
119 }
120
121 ~StFollowLinksState()
122 {
123 mFile.SetFollowLinks(mSavedState);
124 }
125
126 private:
127 nsLocalFile& mFile;
128 PRBool mSavedState;
129};
130
131#pragma mark -
132#pragma mark [nsDirEnumerator]
133
134class nsDirEnumerator : public nsISimpleEnumerator,
135 public nsIDirectoryEnumerator
136{
137 public:
138
139 NS_DECL_ISUPPORTS
140
141 nsDirEnumerator() :
142 mIterator(nsnull),
143 mFSRefsArray(nsnull),
144 mArrayCnt(0), mArrayIndex(0)
145 {
146 }
147
148 nsresult Init(nsILocalFileMac* parent)
149 {
150 NS_ENSURE_ARG(parent);
151
152 OSErr err;
153 nsresult rv;
154 FSRef parentRef;
155
156 rv = parent->GetFSRef(&parentRef);
157 if (NS_FAILED(rv))
158 return rv;
159
160 mFSRefsArray = (FSRef *)nsMemory::Alloc(sizeof(FSRef)
161 * kRequestCountPerIteration);
162 if (!mFSRefsArray)
163 return NS_ERROR_OUT_OF_MEMORY;
164
165 err = ::FSOpenIterator(&parentRef, kFSIterateFlat, &mIterator);
166 if (err != noErr)
167 return MacErrorMapper(err);
168
169 return NS_OK;
170 }
171
172 NS_IMETHOD HasMoreElements(PRBool *result)
173 {
174 if (mNext == nsnull) {
175 if (mArrayIndex >= mArrayCnt) {
176 ItemCount actualCnt;
177 OSErr err = ::FSGetCatalogInfoBulk(mIterator,
178 kRequestCountPerIteration,
179 &actualCnt,
180 nsnull,
181 kFSCatInfoNone,
182 nsnull,
183 mFSRefsArray,
184 nsnull,
185 nsnull);
186
187 if (err == noErr || err == errFSNoMoreItems) {
188 mArrayCnt = actualCnt;
189 mArrayIndex = 0;
190 }
191 }
192 if (mArrayIndex < mArrayCnt) {
193 nsLocalFile *newFile = new nsLocalFile;
194 if (!newFile)
195 return NS_ERROR_OUT_OF_MEMORY;
196 FSRef fsRef = mFSRefsArray[mArrayIndex];
197 if (NS_FAILED(newFile->InitWithFSRef(&fsRef)))
198 return NS_ERROR_FAILURE;
199 mArrayIndex++;
200 mNext = newFile;
201 }
202 }
203 *result = mNext != nsnull;
204 if (!*result)
205 Close();
206 return NS_OK;
207 }
208
209 NS_IMETHOD GetNext(nsISupports **result)
210 {
211 NS_ENSURE_ARG_POINTER(result);
212 *result = nsnull;
213
214 nsresult rv;
215 PRBool hasMore;
216 rv = HasMoreElements(&hasMore);
217 if (NS_FAILED(rv)) return rv;
218
219 *result = mNext; // might return nsnull
220 NS_IF_ADDREF(*result);
221
222 mNext = nsnull;
223 return NS_OK;
224 }
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
252 private:
253 ~nsDirEnumerator()
254 {
255 Close();
256 }
257
258 protected:
259 // According to Apple doc, request the number of objects
260 // per call that will fit in 4 VM pages.
261 enum {
262 kRequestCountPerIteration = ((4096 * 4) / sizeof(FSRef))
263 };
264
265 nsCOMPtr<nsILocalFileMac> mNext;
266
267 FSIterator mIterator;
268 FSRef *mFSRefsArray;
269 PRInt32 mArrayCnt, mArrayIndex;
270};
271
272NS_IMPL_ISUPPORTS2(nsDirEnumerator, nsISimpleEnumerator, nsIDirectoryEnumerator)
273
274#pragma mark -
275#pragma mark [StAEDesc]
276
277class StAEDesc: public AEDesc
278{
279public:
280 StAEDesc()
281 {
282 descriptorType = typeNull;
283 dataHandle = nil;
284 }
285
286 ~StAEDesc()
287 {
288 ::AEDisposeDesc(this);
289 }
290};
291
292#define FILENAME_BUFFER_SIZE 512
293
294//*****************************************************************************
295// nsLocalFile
296//*****************************************************************************
297
298const char nsLocalFile::kPathSepChar = '/';
299const PRUnichar nsLocalFile::kPathSepUnichar = '/';
300
301// The HFS+ epoch is Jan. 1, 1904 GMT - differs from HFS in which times were local
302// The NSPR epoch is Jan. 1, 1970 GMT
303// 2082844800 is the difference in seconds between those dates
304const PRInt64 nsLocalFile::kJanuaryFirst1970Seconds = 2082844800LL;
305
306#pragma mark -
307#pragma mark [CTORs/DTOR]
308
309nsLocalFile::nsLocalFile() :
310 mBaseRef(nsnull),
311 mTargetRef(nsnull),
312 mCachedFSRefValid(PR_FALSE),
313 mFollowLinks(PR_TRUE),
314 mFollowLinksDirty(PR_TRUE)
315{
316}
317
318nsLocalFile::nsLocalFile(const nsLocalFile& src) :
319 mBaseRef(src.mBaseRef),
320 mTargetRef(src.mTargetRef),
321 mCachedFSRef(src.mCachedFSRef),
322 mCachedFSRefValid(src.mCachedFSRefValid),
323 mFollowLinks(src.mFollowLinks),
324 mFollowLinksDirty(src.mFollowLinksDirty)
325{
326 // A CFURLRef is immutable so no need to copy, just retain.
327 if (mBaseRef)
328 ::CFRetain(mBaseRef);
329 if (mTargetRef)
330 ::CFRetain(mTargetRef);
331}
332
333nsLocalFile::~nsLocalFile()
334{
335 if (mBaseRef)
336 ::CFRelease(mBaseRef);
337 if (mTargetRef)
338 ::CFRelease(mTargetRef);
339}
340
341
342//*****************************************************************************
343// nsLocalFile::nsISupports
344//*****************************************************************************
345#pragma mark -
346#pragma mark [nsISupports]
347
348NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile,
349 nsILocalFileMac,
350 nsILocalFile,
351 nsIFile,
352 nsIHashable)
353
354NS_METHOD nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
355{
356 NS_ENSURE_ARG_POINTER(aInstancePtr);
357 NS_ENSURE_NO_AGGREGATION(outer);
358
359 nsLocalFile* inst = new nsLocalFile();
360 if (inst == NULL)
361 return NS_ERROR_OUT_OF_MEMORY;
362
363 nsresult rv = inst->QueryInterface(aIID, aInstancePtr);
364 if (NS_FAILED(rv))
365 {
366 delete inst;
367 return rv;
368 }
369 return NS_OK;
370}
371
372
373//*****************************************************************************
374// nsLocalFile::nsIFile
375//*****************************************************************************
376#pragma mark -
377#pragma mark [nsIFile]
378
379/* void append (in AString node); */
380NS_IMETHODIMP nsLocalFile::Append(const nsAString& aNode)
381{
382 return AppendNative(NS_ConvertUTF16toUTF8(aNode));
383}
384
385/* [noscript] void appendNative (in ACString node); */
386NS_IMETHODIMP nsLocalFile::AppendNative(const nsACString& aNode)
387{
388 // Check we are correctly initialized.
389 CHECK_mBaseRef();
390
391 nsACString::const_iterator start, end;
392 aNode.BeginReading(start);
393 aNode.EndReading(end);
394 if (FindCharInReadable(kPathSepChar, start, end))
395 return NS_ERROR_FILE_UNRECOGNIZED_PATH;
396
397 CFStringRef nodeStrRef = ::CFStringCreateWithCString(kCFAllocatorDefault,
398 PromiseFlatCString(aNode).get(),
399 kCFStringEncodingUTF8);
400 if (nodeStrRef) {
401 CFURLRef newRef = ::CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
402 mBaseRef, nodeStrRef, PR_FALSE);
403 ::CFRelease(nodeStrRef);
404 if (newRef) {
405 SetBaseRef(newRef);
406 ::CFRelease(newRef);
407 return NS_OK;
408 }
409 }
410 return NS_ERROR_FAILURE;
411}
412
413/* void normalize (); */
414NS_IMETHODIMP nsLocalFile::Normalize()
415{
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;
458}
459
460/* void create (in unsigned long type, in unsigned long permissions); */
461NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 permissions)
462{
463 if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE)
464 return NS_ERROR_FILE_UNKNOWN_TYPE;
465
466 // Check we are correctly initialized.
467 CHECK_mBaseRef();
468
469 nsStringArray nonExtantNodes;
470 CFURLRef pathURLRef = mBaseRef;
471 FSRef pathFSRef;
472 CFStringRef leafStrRef = nsnull;
473 nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer;
474 Boolean success;
475
476 // Work backwards through the path to find the last node which
477 // exists. Place the nodes which don't exist in an array and we'll
478 // create those below.
479 while ((success = ::CFURLGetFSRef(pathURLRef, &pathFSRef)) == false) {
480 leafStrRef = ::CFURLCopyLastPathComponent(pathURLRef);
481 if (!leafStrRef)
482 break;
483 CFIndex leafLen = ::CFStringGetLength(leafStrRef);
484 if (!buffer.EnsureElemCapacity(leafLen + 1))
485 break;
486 ::CFStringGetCharacters(leafStrRef, CFRangeMake(0, leafLen), buffer.get());
487 buffer.get()[leafLen] = '\0';
488 nonExtantNodes.AppendString(nsString(nsDependentString(buffer.get())));
489 ::CFRelease(leafStrRef);
490 leafStrRef = nsnull;
491
492 // Get the parent of the leaf for the next go round
493 CFURLRef parent = ::CFURLCreateCopyDeletingLastPathComponent(NULL, pathURLRef);
494 if (!parent)
495 break;
496 if (pathURLRef != mBaseRef)
497 ::CFRelease(pathURLRef);
498 pathURLRef = parent;
499 }
500 if (pathURLRef != mBaseRef)
501 ::CFRelease(pathURLRef);
502 if (leafStrRef != nsnull)
503 ::CFRelease(leafStrRef);
504 if (!success)
505 return NS_ERROR_FAILURE;
506 PRInt32 nodesToCreate = nonExtantNodes.Count();
507 if (nodesToCreate == 0)
508 return NS_ERROR_FILE_ALREADY_EXISTS;
509
510 OSErr err;
511 nsAutoString nextNodeName;
512 for (PRInt32 i = nodesToCreate - 1; i > 0; i--) {
513 nonExtantNodes.StringAt(i, nextNodeName);
514 err = ::FSCreateDirectoryUnicode(&pathFSRef,
515 nextNodeName.Length(),
516 (const UniChar *)nextNodeName.get(),
517 kFSCatInfoNone,
518 nsnull, &pathFSRef, nsnull, nsnull);
519 if (err != noErr)
520 return MacErrorMapper(err);
521 }
522 nonExtantNodes.StringAt(0, nextNodeName);
523 if (type == NORMAL_FILE_TYPE) {
524 err = ::FSCreateFileUnicode(&pathFSRef,
525 nextNodeName.Length(),
526 (const UniChar *)nextNodeName.get(),
527 kFSCatInfoNone,
528 nsnull, nsnull, nsnull);
529 }
530 else {
531 err = ::FSCreateDirectoryUnicode(&pathFSRef,
532 nextNodeName.Length(),
533 (const UniChar *)nextNodeName.get(),
534 kFSCatInfoNone,
535 nsnull, nsnull, nsnull, nsnull);
536 }
537
538 return MacErrorMapper(err);
539}
540
541/* attribute AString leafName; */
542NS_IMETHODIMP nsLocalFile::GetLeafName(nsAString& aLeafName)
543{
544 nsCAutoString nativeString;
545 nsresult rv = GetNativeLeafName(nativeString);
546 if (NS_FAILED(rv))
547 return rv;
548 CopyUTF8toUTF16NFC(nativeString, aLeafName);
549 return NS_OK;
550}
551
552NS_IMETHODIMP nsLocalFile::SetLeafName(const nsAString& aLeafName)
553{
554 return SetNativeLeafName(NS_ConvertUTF16toUTF8(aLeafName));
555}
556
557/* [noscript] attribute ACString nativeLeafName; */
558NS_IMETHODIMP nsLocalFile::GetNativeLeafName(nsACString& aNativeLeafName)
559{
560 // Check we are correctly initialized.
561 CHECK_mBaseRef();
562
563 nsresult rv = NS_ERROR_FAILURE;
564 CFStringRef leafStrRef = ::CFURLCopyLastPathComponent(mBaseRef);
565 if (leafStrRef) {
566 rv = CFStringReftoUTF8(leafStrRef, aNativeLeafName);
567 ::CFRelease(leafStrRef);
568 }
569 return rv;
570}
571
572NS_IMETHODIMP nsLocalFile::SetNativeLeafName(const nsACString& aNativeLeafName)
573{
574 // Check we are correctly initialized.
575 CHECK_mBaseRef();
576
577 nsresult rv = NS_ERROR_FAILURE;
578 CFURLRef parentURLRef = ::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, mBaseRef);
579 if (parentURLRef) {
580 CFStringRef nodeStrRef = ::CFStringCreateWithCString(kCFAllocatorDefault,
581 PromiseFlatCString(aNativeLeafName).get(),
582 kCFStringEncodingUTF8);
583
584 if (nodeStrRef) {
585 CFURLRef newURLRef = ::CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
586 parentURLRef, nodeStrRef, PR_FALSE);
587 if (newURLRef) {
588 SetBaseRef(newURLRef);
589 ::CFRelease(newURLRef);
590 rv = NS_OK;
591 }
592 ::CFRelease(nodeStrRef);
593 }
594 ::CFRelease(parentURLRef);
595 }
596 return rv;
597}
598
599/* void copyTo (in nsIFile newParentDir, in AString newName); */
600NS_IMETHODIMP nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString& newName)
601{
602 return CopyInternal(newParentDir, newName, PR_FALSE);
603}
604
605/* [noscrpit] void CopyToNative (in nsIFile newParentDir, in ACString newName); */
606NS_IMETHODIMP nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString& newName)
607{
608 return CopyInternal(newParentDir, NS_ConvertUTF8toUTF16(newName), PR_FALSE);
609}
610
611/* void copyToFollowingLinks (in nsIFile newParentDir, in AString newName); */
612NS_IMETHODIMP nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString& newName)
613{
614 return CopyInternal(newParentDir, newName, PR_TRUE);
615}
616
617/* [noscript] void copyToFollowingLinksNative (in nsIFile newParentDir, in ACString newName); */
618NS_IMETHODIMP nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString& newName)
619{
620 return CopyInternal(newParentDir, NS_ConvertUTF8toUTF16(newName), PR_TRUE);
621}
622
623/* void moveTo (in nsIFile newParentDir, in AString newName); */
624NS_IMETHODIMP nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString& newName)
625{
626 return MoveToNative(newParentDir, NS_ConvertUTF16toUTF8(newName));
627}
628
629/* [noscript] void moveToNative (in nsIFile newParentDir, in ACString newName); */
630NS_IMETHODIMP nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString& newName)
631{
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;
711}
712
713/* void remove (in boolean recursive); */
714NS_IMETHODIMP nsLocalFile::Remove(PRBool recursive)
715{
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; */
759NS_IMETHODIMP nsLocalFile::GetPermissions(PRUint32 *aPermissions)
760{
761 NS_ENSURE_ARG_POINTER(aPermissions);
762
763 FSRef fsRef;
764 nsresult rv = GetFSRefInternal(fsRef);
765 if (NS_FAILED(rv))
766 return rv;
767
768 FSCatalogInfo catalogInfo;
769 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo,
770 nsnull, nsnull, nsnull);
771 if (err != noErr)
772 return MacErrorMapper(err);
773 FSPermissionInfo *permPtr = (FSPermissionInfo*)catalogInfo.permissions;
774 *aPermissions = permPtr->mode;
775 return NS_OK;
776}
777
778NS_IMETHODIMP nsLocalFile::SetPermissions(PRUint32 aPermissions)
779{
780 FSRef fsRef;
781 nsresult rv = GetFSRefInternal(fsRef);
782 if (NS_FAILED(rv))
783 return rv;
784
785 FSCatalogInfo catalogInfo;
786 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo,
787 nsnull, nsnull, nsnull);
788 if (err != noErr)
789 return MacErrorMapper(err);
790 FSPermissionInfo *permPtr = (FSPermissionInfo*)catalogInfo.permissions;
791 permPtr->mode = (UInt16)aPermissions;
792 err = ::FSSetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo);
793 return MacErrorMapper(err);
794}
795
796/* attribute unsigned long permissionsOfLink; */
797NS_IMETHODIMP nsLocalFile::GetPermissionsOfLink(PRUint32 *aPermissionsOfLink)
798{
799 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
800 return NS_ERROR_NOT_IMPLEMENTED;
801}
802
803NS_IMETHODIMP nsLocalFile::SetPermissionsOfLink(PRUint32 aPermissionsOfLink)
804{
805 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
806 return NS_ERROR_NOT_IMPLEMENTED;
807}
808
809/* attribute PRInt64 lastModifiedTime; */
810NS_IMETHODIMP nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModifiedTime)
811{
812 // Check we are correctly initialized.
813 CHECK_mBaseRef();
814
815 NS_ENSURE_ARG_POINTER(aLastModifiedTime);
816
817 FSRef fsRef;
818 nsresult rv = GetFSRefInternal(fsRef);
819 if (NS_FAILED(rv))
820 return rv;
821
822 FSCatalogInfo catalogInfo;
823 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoContentMod, &catalogInfo,
824 nsnull, nsnull, nsnull);
825 if (err != noErr)
826 return MacErrorMapper(err);
827 *aLastModifiedTime = HFSPlustoNSPRTime(catalogInfo.contentModDate);
828 return NS_OK;
829}
830
831NS_IMETHODIMP nsLocalFile::SetLastModifiedTime(PRInt64 aLastModifiedTime)
832{
833 // Check we are correctly initialized.
834 CHECK_mBaseRef();
835
836 OSErr err;
837 nsresult rv;
838 FSRef fsRef;
839 FSCatalogInfo catalogInfo;
840
841 rv = GetFSRefInternal(fsRef);
842 if (NS_FAILED(rv))
843 return rv;
844
845 FSRef parentRef;
846 PRBool notifyParent;
847
848 /* Get the node flags, the content modification date and time, and the parent ref */
849 err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags + kFSCatInfoContentMod,
850 &catalogInfo, NULL, NULL, &parentRef);
851 if (err != noErr)
852 return MacErrorMapper(err);
853
854 /* Notify the parent if this is a file */
855 notifyParent = (0 == (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask));
856
857 NSPRtoHFSPlusTime(aLastModifiedTime, catalogInfo.contentModDate);
858 err = ::FSSetCatalogInfo(&fsRef, kFSCatInfoContentMod, &catalogInfo);
859 if (err != noErr)
860 return MacErrorMapper(err);
861
862 /* Send a notification for the parent of the file, or for the directory */
863 err = FNNotify(notifyParent ? &parentRef : &fsRef, kFNDirectoryModifiedMessage, kNilOptions);
864 if (err != noErr)
865 return MacErrorMapper(err);
866
867 return NS_OK;
868}
869
870/* attribute PRInt64 lastModifiedTimeOfLink; */
871NS_IMETHODIMP nsLocalFile::GetLastModifiedTimeOfLink(PRInt64 *aLastModifiedTimeOfLink)
872{
873 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
874 return NS_ERROR_NOT_IMPLEMENTED;
875}
876NS_IMETHODIMP nsLocalFile::SetLastModifiedTimeOfLink(PRInt64 aLastModifiedTimeOfLink)
877{
878 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
879 return NS_ERROR_NOT_IMPLEMENTED;
880}
881
882/* attribute PRInt64 fileSize; */
883NS_IMETHODIMP nsLocalFile::GetFileSize(PRInt64 *aFileSize)
884{
885 NS_ENSURE_ARG_POINTER(aFileSize);
886 *aFileSize = 0;
887
888 FSRef fsRef;
889 nsresult rv = GetFSRefInternal(fsRef);
890 if (NS_FAILED(rv))
891 return rv;
892
893 FSCatalogInfo catalogInfo;
894 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags + kFSCatInfoDataSizes, &catalogInfo,
895 nsnull, nsnull, nsnull);
896 if (err != noErr)
897 return MacErrorMapper(err);
898
899 // FSGetCatalogInfo can return a bogus size for directories sometimes, so only
900 // rely on the answer for files
901 if ((catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0)
902 *aFileSize = catalogInfo.dataLogicalSize;
903 return NS_OK;
904}
905
906NS_IMETHODIMP nsLocalFile::SetFileSize(PRInt64 aFileSize)
907{
908 // Check we are correctly initialized.
909 CHECK_mBaseRef();
910
911 FSRef fsRef;
912 nsresult rv = GetFSRefInternal(fsRef);
913 if (NS_FAILED(rv))
914 return rv;
915
916 SInt16 refNum;
917 OSErr err = ::FSOpenFork(&fsRef, 0, nsnull, fsWrPerm, &refNum);
918 if (err != noErr)
919 return MacErrorMapper(err);
920 err = ::FSSetForkSize(refNum, fsFromStart, aFileSize);
921 ::FSCloseFork(refNum);
922
923 return MacErrorMapper(err);
924}
925
926/* readonly attribute PRInt64 fileSizeOfLink; */
927NS_IMETHODIMP nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSizeOfLink)
928{
929 // Check we are correctly initialized.
930 CHECK_mBaseRef();
931
932 NS_ENSURE_ARG_POINTER(aFileSizeOfLink);
933
934 StFollowLinksState followLinks(*this, PR_FALSE);
935 return GetFileSize(aFileSizeOfLink);
936}
937
938/* readonly attribute AString target; */
939NS_IMETHODIMP nsLocalFile::GetTarget(nsAString& aTarget)
940{
941 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
942 return NS_ERROR_NOT_IMPLEMENTED;
943}
944
945/* [noscript] readonly attribute ACString nativeTarget; */
946NS_IMETHODIMP nsLocalFile::GetNativeTarget(nsACString& aNativeTarget)
947{
948 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
949 return NS_ERROR_NOT_IMPLEMENTED;
950}
951
952/* readonly attribute AString path; */
953NS_IMETHODIMP nsLocalFile::GetPath(nsAString& aPath)
954{
955 nsCAutoString nativeString;
956 nsresult rv = GetNativePath(nativeString);
957 if (NS_FAILED(rv))
958 return rv;
959 CopyUTF8toUTF16NFC(nativeString, aPath);
960 return NS_OK;
961}
962
963/* [noscript] readonly attribute ACString nativePath; */
964NS_IMETHODIMP nsLocalFile::GetNativePath(nsACString& aNativePath)
965{
966 // Check we are correctly initialized.
967 CHECK_mBaseRef();
968
969 nsresult rv = NS_ERROR_FAILURE;
970 CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(mBaseRef, kCFURLPOSIXPathStyle);
971 if (pathStrRef) {
972 rv = CFStringReftoUTF8(pathStrRef, aNativePath);
973 ::CFRelease(pathStrRef);
974 }
975 return rv;
976}
977
978/* boolean exists (); */
979NS_IMETHODIMP nsLocalFile::Exists(PRBool *_retval)
980{
981 // Check we are correctly initialized.
982 CHECK_mBaseRef();
983
984 NS_ENSURE_ARG_POINTER(_retval);
985 *_retval = PR_FALSE;
986
987 FSRef fsRef;
988 if (NS_SUCCEEDED(GetFSRefInternal(fsRef, PR_TRUE))) {
989 *_retval = PR_TRUE;
990 }
991
992 return NS_OK;
993}
994
995/* boolean isWritable (); */
996NS_IMETHODIMP nsLocalFile::IsWritable(PRBool *_retval)
997{
998 // Check we are correctly initialized.
999 CHECK_mBaseRef();
1000
1001 NS_ENSURE_ARG_POINTER(_retval);
1002 *_retval = PR_FALSE;
1003
1004 FSRef fsRef;
1005 nsresult rv = GetFSRefInternal(fsRef);
1006 if (NS_FAILED(rv))
1007 return rv;
1008 if (::FSCheckLock(&fsRef) == noErr) {
1009 PRUint32 permissions;
1010 rv = GetPermissions(&permissions);
1011 if (NS_FAILED(rv))
1012 return rv;
1013 *_retval = ((permissions & S_IWUSR) != 0);
1014 }
1015 return NS_OK;
1016}
1017
1018/* boolean isReadable (); */
1019NS_IMETHODIMP nsLocalFile::IsReadable(PRBool *_retval)
1020{
1021 // Check we are correctly initialized.
1022 CHECK_mBaseRef();
1023
1024 NS_ENSURE_ARG_POINTER(_retval);
1025 *_retval = PR_FALSE;
1026
1027 PRUint32 permissions;
1028 nsresult rv = GetPermissions(&permissions);
1029 if (NS_FAILED(rv))
1030 return rv;
1031 *_retval = ((permissions & S_IRUSR) != 0);
1032 return NS_OK;
1033}
1034
1035/* boolean isExecutable (); */
1036NS_IMETHODIMP nsLocalFile::IsExecutable(PRBool *_retval)
1037{
1038 // Check we are correctly initialized.
1039 CHECK_mBaseRef();
1040
1041 NS_ENSURE_ARG_POINTER(_retval);
1042 *_retval = PR_FALSE;
1043
1044 FSRef fsRef;
1045 nsresult rv = GetFSRefInternal(fsRef);
1046 if (NS_FAILED(rv))
1047 return rv;
1048
1049 LSRequestedInfo theInfoRequest = kLSRequestAllInfo;
1050 LSItemInfoRecord theInfo;
1051 if (::LSCopyItemInfoForRef(&fsRef, theInfoRequest, &theInfo) == noErr) {
1052 if ((theInfo.flags & kLSItemInfoIsApplication) != 0)
1053 *_retval = PR_TRUE;
1054 }
1055 return NS_OK;
1056}
1057
1058/* boolean isHidden (); */
1059NS_IMETHODIMP nsLocalFile::IsHidden(PRBool *_retval)
1060{
1061 NS_ENSURE_ARG_POINTER(_retval);
1062 *_retval = PR_FALSE;
1063
1064 FSRef fsRef;
1065 nsresult rv = GetFSRefInternal(fsRef);
1066 if (NS_FAILED(rv))
1067 return rv;
1068
1069 FSCatalogInfo catalogInfo;
1070 HFSUniStr255 leafName;
1071 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catalogInfo,
1072 &leafName, nsnull, nsnull);
1073 if (err != noErr)
1074 return MacErrorMapper(err);
1075
1076 FileInfo *fInfoPtr = (FileInfo *)(catalogInfo.finderInfo); // Finder flags are in the same place whether we use FileInfo or FolderInfo
1077 if ((fInfoPtr->finderFlags & kIsInvisible) != 0) {
1078 *_retval = PR_TRUE;
1079 }
1080 else {
1081 // If the leaf name begins with a '.', consider it invisible
1082 if (leafName.length >= 1 && leafName.unicode[0] == UniChar('.'))
1083 *_retval = PR_TRUE;
1084 }
1085 return NS_OK;
1086}
1087
1088/* boolean isDirectory (); */
1089NS_IMETHODIMP nsLocalFile::IsDirectory(PRBool *_retval)
1090{
1091 NS_ENSURE_ARG_POINTER(_retval);
1092 *_retval = PR_FALSE;
1093
1094 FSRef fsRef;
1095 nsresult rv = GetFSRefInternal(fsRef, PR_FALSE);
1096 if (NS_FAILED(rv))
1097 return rv;
1098
1099 FSCatalogInfo catalogInfo;
1100 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo,
1101 nsnull, nsnull, nsnull);
1102 if (err != noErr)
1103 return MacErrorMapper(err);
1104 *_retval = ((catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0);
1105 return NS_OK;
1106}
1107
1108/* boolean isFile (); */
1109NS_IMETHODIMP nsLocalFile::IsFile(PRBool *_retval)
1110{
1111 NS_ENSURE_ARG_POINTER(_retval);
1112 *_retval = PR_FALSE;
1113
1114 FSRef fsRef;
1115 nsresult rv = GetFSRefInternal(fsRef, PR_FALSE);
1116 if (NS_FAILED(rv))
1117 return rv;
1118
1119 FSCatalogInfo catalogInfo;
1120 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo,
1121 nsnull, nsnull, nsnull);
1122 if (err != noErr)
1123 return MacErrorMapper(err);
1124 *_retval = ((catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0);
1125 return NS_OK;
1126}
1127
1128/* boolean isSymlink (); */
1129NS_IMETHODIMP nsLocalFile::IsSymlink(PRBool *_retval)
1130{
1131 // Check we are correctly initialized.
1132 CHECK_mBaseRef();
1133
1134 NS_ENSURE_ARG(_retval);
1135 *_retval = PR_FALSE;
1136
1137 // Check we are correctly initialized.
1138 CHECK_mBaseRef();
1139
1140 FSRef fsRef;
1141 if (::CFURLGetFSRef(mBaseRef, &fsRef)) {
1142 Boolean isAlias, isFolder;
1143 if (::FSIsAliasFile(&fsRef, &isAlias, &isFolder) == noErr)
1144 *_retval = isAlias;
1145 }
1146 return NS_OK;
1147}
1148
1149/* boolean isSpecial (); */
1150NS_IMETHODIMP nsLocalFile::IsSpecial(PRBool *_retval)
1151{
1152 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
1153 return NS_ERROR_NOT_IMPLEMENTED;
1154}
1155
1156/* nsIFile clone (); */
1157NS_IMETHODIMP nsLocalFile::Clone(nsIFile **_retval)
1158{
1159 // Just copy-construct ourselves
1160 *_retval = new nsLocalFile(*this);
1161 if (!*_retval)
1162 return NS_ERROR_OUT_OF_MEMORY;
1163
1164 NS_ADDREF(*_retval);
1165
1166 return NS_OK;
1167}
1168
1169/* boolean equals (in nsIFile inFile); */
1170NS_IMETHODIMP nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval)
1171{
1172 return EqualsInternal(inFile, PR_TRUE, _retval);
1173}
1174
1175nsresult
1176nsLocalFile::EqualsInternal(nsISupports* inFile, PRBool aUpdateCache,
1177 PRBool *_retval)
1178{
1179 NS_ENSURE_ARG_POINTER(_retval);
1180 *_retval = PR_FALSE;
1181
1182 nsCOMPtr<nsILocalFileMac> inMacFile(do_QueryInterface(inFile));
1183 if (!inFile)
1184 return NS_OK;
1185
1186 nsLocalFile* inLF =
1187 NS_STATIC_CAST(nsLocalFile*, (nsILocalFileMac*) inMacFile);
1188
1189 // If both exist, compare FSRefs
1190 FSRef thisFSRef, inFSRef;
1191 nsresult rv1 = GetFSRefInternal(thisFSRef, aUpdateCache);
1192 nsresult rv2 = inLF->GetFSRefInternal(inFSRef, aUpdateCache);
1193 if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) {
1194 *_retval = (thisFSRef == inFSRef);
1195 return NS_OK;
1196 }
1197 // If one exists and the other doesn't, not equal
1198 if (rv1 != rv2)
1199 return NS_OK;
1200
1201 // Arg, we have to get their paths and compare
1202 nsCAutoString thisPath, inPath;
1203 if (NS_FAILED(GetNativePath(thisPath)))
1204 return NS_ERROR_FAILURE;
1205 if (NS_FAILED(inMacFile->GetNativePath(inPath)))
1206 return NS_ERROR_FAILURE;
1207 *_retval = thisPath.Equals(inPath);
1208
1209 return NS_OK;
1210}
1211
1212/* boolean contains (in nsIFile inFile, in boolean recur); */
1213NS_IMETHODIMP nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval)
1214{
1215 // Check we are correctly initialized.
1216 CHECK_mBaseRef();
1217
1218 NS_ENSURE_ARG_POINTER(_retval);
1219 *_retval = PR_FALSE;
1220
1221 PRBool isDir;
1222 nsresult rv = IsDirectory(&isDir);
1223 if (NS_FAILED(rv))
1224 return rv;
1225 if (!isDir)
1226 return NS_OK; // must be a dir to contain someone
1227
1228 nsCAutoString thisPath, inPath;
1229 if (NS_FAILED(GetNativePath(thisPath)) || NS_FAILED(inFile->GetNativePath(inPath)))
1230 return NS_ERROR_FAILURE;
1231 size_t thisPathLen = thisPath.Length();
1232 if ((inPath.Length() > thisPathLen + 1) && (strncasecmp(thisPath.get(), inPath.get(), thisPathLen) == 0)) {
1233 // Now make sure that the |inFile|'s path has a separator at thisPathLen,
1234 // and there's at least one more character after that.
1235 if (inPath[thisPathLen] == kPathSepChar)
1236 *_retval = PR_TRUE;
1237 }
1238 return NS_OK;
1239}
1240
1241/* readonly attribute nsIFile parent; */
1242NS_IMETHODIMP nsLocalFile::GetParent(nsIFile * *aParent)
1243{
1244 NS_ENSURE_ARG_POINTER(aParent);
1245 *aParent = nsnull;
1246
1247 // Check we are correctly initialized.
1248 CHECK_mBaseRef();
1249
1250 nsLocalFile *newFile = nsnull;
1251
1252 // If it can be determined without error that a file does not
1253 // have a parent, return nsnull for the parent and NS_OK as the result.
1254 // See bug 133617.
1255 nsresult rv = NS_OK;
1256 CFURLRef parentURLRef = ::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, mBaseRef);
1257 if (parentURLRef) {
1258 rv = NS_ERROR_FAILURE;
1259 newFile = new nsLocalFile;
1260 if (newFile) {
1261 rv = newFile->InitWithCFURL(parentURLRef);
1262 if (NS_SUCCEEDED(rv)) {
1263 NS_ADDREF(*aParent = newFile);
1264 rv = NS_OK;
1265 }
1266 }
1267 ::CFRelease(parentURLRef);
1268 }
1269 return rv;
1270}
1271
1272/* readonly attribute nsISimpleEnumerator directoryEntries; */
1273NS_IMETHODIMP nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **aDirectoryEntries)
1274{
1275 NS_ENSURE_ARG_POINTER(aDirectoryEntries);
1276 *aDirectoryEntries = nsnull;
1277
1278 nsresult rv;
1279 PRBool isDir;
1280 rv = IsDirectory(&isDir);
1281 if (NS_FAILED(rv))
1282 return rv;
1283 if (!isDir)
1284 return NS_ERROR_FILE_NOT_DIRECTORY;
1285
1286 nsDirEnumerator* dirEnum = new nsDirEnumerator;
1287 if (dirEnum == nsnull)
1288 return NS_ERROR_OUT_OF_MEMORY;
1289 NS_ADDREF(dirEnum);
1290 rv = dirEnum->Init(this);
1291 if (NS_FAILED(rv)) {
1292 NS_RELEASE(dirEnum);
1293 return rv;
1294 }
1295 *aDirectoryEntries = dirEnum;
1296
1297 return NS_OK;
1298}
1299
1300
1301//*****************************************************************************
1302// nsLocalFile::nsILocalFile
1303//*****************************************************************************
1304#pragma mark -
1305#pragma mark [nsILocalFile]
1306
1307/* void initWithPath (in AString filePath); */
1308NS_IMETHODIMP nsLocalFile::InitWithPath(const nsAString& filePath)
1309{
1310 return InitWithNativePath(NS_ConvertUTF16toUTF8(filePath));
1311}
1312
1313/* [noscript] void initWithNativePath (in ACString filePath); */
1314NS_IMETHODIMP nsLocalFile::InitWithNativePath(const nsACString& filePath)
1315{
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() != '/')
1329 return NS_ERROR_FILE_UNRECOGNIZED_PATH;
1330 else
1331 fixedPath.Assign(filePath);
1332
1333 // A path with consecutive '/'s which are not between
1334 // nodes crashes CFURLGetFSRef(). Consecutive '/'s which
1335 // are between actual nodes are OK. So, convert consecutive
1336 // '/'s to a single one.
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;
1342
1343 CFStringRef pathAsCFString;
1344 CFURLRef pathAsCFURL;
1345
1346 pathAsCFString = ::CFStringCreateWithCString(nsnull, fixedPath.get(), kCFStringEncodingUTF8);
1347 if (!pathAsCFString)
1348 return NS_ERROR_FAILURE;
1349 pathAsCFURL = ::CFURLCreateWithFileSystemPath(nsnull, pathAsCFString, kCFURLPOSIXPathStyle, PR_FALSE);
1350 if (!pathAsCFURL) {
1351 ::CFRelease(pathAsCFString);
1352 return NS_ERROR_FAILURE;
1353 }
1354 SetBaseRef(pathAsCFURL);
1355 ::CFRelease(pathAsCFURL);
1356 ::CFRelease(pathAsCFString);
1357 return NS_OK;
1358}
1359
1360/* void initWithFile (in nsILocalFile aFile); */
1361NS_IMETHODIMP nsLocalFile::InitWithFile(nsILocalFile *aFile)
1362{
1363 NS_ENSURE_ARG(aFile);
1364
1365 nsCOMPtr<nsILocalFileMac> aFileMac(do_QueryInterface(aFile));
1366 if (!aFileMac)
1367 return NS_ERROR_UNEXPECTED;
1368 CFURLRef urlRef;
1369 nsresult rv = aFileMac->GetCFURL(&urlRef);
1370 if (NS_FAILED(rv))
1371 return rv;
1372 rv = InitWithCFURL(urlRef);
1373 ::CFRelease(urlRef);
1374 return rv;
1375}
1376
1377/* attribute PRBool followLinks; */
1378NS_IMETHODIMP nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
1379{
1380 NS_ENSURE_ARG_POINTER(aFollowLinks);
1381
1382 *aFollowLinks = mFollowLinks;
1383 return NS_OK;
1384}
1385
1386NS_IMETHODIMP nsLocalFile::SetFollowLinks(PRBool aFollowLinks)
1387{
1388 if (aFollowLinks != mFollowLinks) {
1389 mFollowLinks = aFollowLinks;
1390 UpdateTargetRef();
1391 }
1392 return NS_OK;
1393}
1394
1395/* [noscript] PRFileDescStar openNSPRFileDesc (in long flags, in long mode); */
1396NS_IMETHODIMP nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval)
1397{
1398 NS_ENSURE_ARG_POINTER(_retval);
1399
1400 nsCAutoString path;
1401 nsresult rv = GetPathInternal(path);
1402 if (NS_FAILED(rv))
1403 return rv;
1404
1405 *_retval = PR_Open(path.get(), flags, mode);
1406 if (! *_retval)
1407 return NS_ErrorAccordingToNSPR();
1408
1409 return NS_OK;
1410}
1411
1412/* [noscript] FILE openANSIFileDesc (in string mode); */
1413NS_IMETHODIMP nsLocalFile::OpenANSIFileDesc(const char *mode, FILE **_retval)
1414{
1415 NS_ENSURE_ARG_POINTER(_retval);
1416
1417 nsCAutoString path;
1418 nsresult rv = GetPathInternal(path);
1419 if (NS_FAILED(rv))
1420 return rv;
1421
1422 *_retval = fopen(path.get(), mode);
1423 if (! *_retval)
1424 return NS_ERROR_FAILURE;
1425
1426 return NS_OK;
1427}
1428
1429/* [noscript] PRLibraryStar load (); */
1430NS_IMETHODIMP nsLocalFile::Load(PRLibrary **_retval)
1431{
1432 // Check we are correctly initialized.
1433 CHECK_mBaseRef();
1434
1435 NS_ENSURE_ARG_POINTER(_retval);
1436
1437 NS_TIMELINE_START_TIMER("PR_LoadLibrary");
1438
1439 nsCAutoString path;
1440 nsresult rv = GetPathInternal(path);
1441 if (NS_FAILED(rv))
1442 return rv;
1443
1444#ifdef NS_BUILD_REFCNT_LOGGING
1445 nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
1446#endif
1447
1448 *_retval = PR_LoadLibrary(path.get());
1449
1450#ifdef NS_BUILD_REFCNT_LOGGING
1451 nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
1452#endif
1453
1454 NS_TIMELINE_STOP_TIMER("PR_LoadLibrary");
1455 NS_TIMELINE_MARK_TIMER1("PR_LoadLibrary", path.get());
1456
1457 if (!*_retval)
1458 return NS_ERROR_FAILURE;
1459
1460 return NS_OK;
1461}
1462
1463/* readonly attribute PRInt64 diskSpaceAvailable; */
1464NS_IMETHODIMP nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
1465{
1466 // Check we are correctly initialized.
1467 CHECK_mBaseRef();
1468
1469 NS_ENSURE_ARG_POINTER(aDiskSpaceAvailable);
1470
1471 FSRef fsRef;
1472 nsresult rv = GetFSRefInternal(fsRef);
1473 if (NS_FAILED(rv))
1474 return rv;
1475
1476 OSErr err;
1477 FSCatalogInfo catalogInfo;
1478 err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoVolume, &catalogInfo,
1479 nsnull, nsnull, nsnull);
1480 if (err != noErr)
1481 return MacErrorMapper(err);
1482
1483 FSVolumeInfo volumeInfo;
1484 err = ::FSGetVolumeInfo(catalogInfo.volume, 0, nsnull, kFSVolInfoSizes,
1485 &volumeInfo, nsnull, nsnull);
1486 if (err != noErr)
1487 return MacErrorMapper(err);
1488
1489 *aDiskSpaceAvailable = volumeInfo.freeBytes;
1490 return NS_OK;
1491}
1492
1493/* void appendRelativePath (in AString relativeFilePath); */
1494NS_IMETHODIMP nsLocalFile::AppendRelativePath(const nsAString& relativeFilePath)
1495{
1496 return AppendRelativeNativePath(NS_ConvertUTF16toUTF8(relativeFilePath));
1497}
1498
1499/* [noscript] void appendRelativeNativePath (in ACString relativeFilePath); */
1500NS_IMETHODIMP nsLocalFile::AppendRelativeNativePath(const nsACString& relativeFilePath)
1501{
1502 if (relativeFilePath.IsEmpty())
1503 return NS_OK;
1504 // No leading '/'
1505 if (relativeFilePath.First() == '/')
1506 return NS_ERROR_FILE_UNRECOGNIZED_PATH;
1507
1508 // Parse the nodes and call Append() for each
1509 nsACString::const_iterator nodeBegin, pathEnd;
1510 relativeFilePath.BeginReading(nodeBegin);
1511 relativeFilePath.EndReading(pathEnd);
1512 nsACString::const_iterator nodeEnd(nodeBegin);
1513
1514 while (nodeEnd != pathEnd) {
1515 FindCharInReadable(kPathSepChar, nodeEnd, pathEnd);
1516 nsresult rv = AppendNative(Substring(nodeBegin, nodeEnd));
1517 if (NS_FAILED(rv))
1518 return rv;
1519 if (nodeEnd != pathEnd) // If there's more left in the string, inc over the '/' nodeEnd is on.
1520 ++nodeEnd;
1521 nodeBegin = nodeEnd;
1522 }
1523 return NS_OK;
1524}
1525
1526/* attribute ACString persistentDescriptor; */
1527NS_IMETHODIMP nsLocalFile::GetPersistentDescriptor(nsACString& aPersistentDescriptor)
1528{
1529 FSRef fsRef;
1530 nsresult rv = GetFSRefInternal(fsRef);
1531 if (NS_FAILED(rv))
1532 return rv;
1533
1534 AliasHandle aliasH;
1535 OSErr err = ::FSNewAlias(nsnull, &fsRef, &aliasH);
1536 if (err != noErr)
1537 return MacErrorMapper(err);
1538
1539 PRUint32 bytes = ::GetHandleSize((Handle) aliasH);
1540 ::HLock((Handle) aliasH);
1541 // Passing nsnull for dest makes NULL-term string
1542 char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull);
1543 ::DisposeHandle((Handle) aliasH);
1544 NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
1545
1546 aPersistentDescriptor = buf;
1547 PR_Free(buf);
1548
1549 return NS_OK;
1550}
1551
1552NS_IMETHODIMP nsLocalFile::SetPersistentDescriptor(const nsACString& aPersistentDescriptor)
1553{
1554 if (aPersistentDescriptor.IsEmpty())
1555 return NS_ERROR_INVALID_ARG;
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
1564 nsresult rv = NS_OK;
1565
1566 PRUint32 dataSize = aPersistentDescriptor.Length();
1567 char* decodedData = PL_Base64Decode(PromiseFlatCString(aPersistentDescriptor).get(), dataSize, nsnull);
1568 if (!decodedData) {
1569 NS_ERROR("SetPersistentDescriptor was given bad data");
1570 return NS_ERROR_FAILURE;
1571 }
1572
1573 // Cast to an alias record and resolve.
1574 AliasRecord aliasHeader = *(AliasPtr)decodedData;
1575 PRInt32 aliasSize = GetAliasSizeFromRecord(aliasHeader);
1576 if (aliasSize > (dataSize * 3) / 4) { // be paranoid about having too few data
1577 PR_Free(decodedData);
1578 return NS_ERROR_FAILURE;
1579 }
1580
1581 // Move the now-decoded data into the Handle.
1582 // The size of the decoded data is 3/4 the size of the encoded data. See plbase64.h
1583 Handle newHandle = nsnull;
1584 if (::PtrToHand(decodedData, &newHandle, aliasSize) != noErr)
1585 rv = NS_ERROR_OUT_OF_MEMORY;
1586 PR_Free(decodedData);
1587 if (NS_FAILED(rv))
1588 return rv;
1589
1590 Boolean changed;
1591 FSRef resolvedFSRef;
1592 OSErr err = ::FSResolveAlias(nsnull, (AliasHandle)newHandle, &resolvedFSRef, &changed);
1593
1594 rv = MacErrorMapper(err);
1595 DisposeHandle(newHandle);
1596 if (NS_FAILED(rv))
1597 return rv;
1598
1599 return InitWithFSRef(&resolvedFSRef);
1600}
1601
1602/* void reveal (); */
1603NS_IMETHODIMP nsLocalFile::Reveal()
1604{
1605 FSRef fsRefToReveal;
1606 AppleEvent aeEvent = {0, nil};
1607 AppleEvent aeReply = {0, nil};
1608 StAEDesc aeDirDesc, listElem, myAddressDesc, fileList;
1609 OSErr err;
1610 ProcessSerialNumber process;
1611
1612 nsresult rv = GetFSRefInternal(fsRefToReveal);
1613 if (NS_FAILED(rv))
1614 return rv;
1615
1616 err = ::FindRunningAppBySignature ('MACS', process);
1617 if (err == noErr) {
1618 err = ::AECreateDesc(typeProcessSerialNumber, (Ptr)&process, sizeof(process), &myAddressDesc);
1619 if (err == noErr) {
1620 // Create the FinderEvent
1621 err = ::AECreateAppleEvent(kAEMiscStandards, kAEMakeObjectsVisible, &myAddressDesc,
1622 kAutoGenerateReturnID, kAnyTransactionID, &aeEvent);
1623 if (err == noErr) {
1624 // Create the file list
1625 err = ::AECreateList(nil, 0, false, &fileList);
1626 if (err == noErr) {
1627 FSSpec fsSpecToReveal;
1628 err = ::FSRefMakeFSSpec(&fsRefToReveal, &fsSpecToReveal);
1629 if (err == noErr) {
1630 err = ::AEPutPtr(&fileList, 0, typeFSS, &fsSpecToReveal, sizeof(FSSpec));
1631 if (err == noErr) {
1632 err = ::AEPutParamDesc(&aeEvent, keyDirectObject, &fileList);
1633 if (err == noErr) {
1634 err = ::AESend(&aeEvent, &aeReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, nil, nil);
1635 if (err == noErr)
1636 ::SetFrontProcess(&process);
1637 }
1638 }
1639 }
1640 }
1641 }
1642 }
1643 }
1644
1645 return NS_OK;
1646}
1647
1648/* void launch (); */
1649NS_IMETHODIMP nsLocalFile::Launch()
1650{
1651 FSRef fsRef;
1652 nsresult rv = GetFSRefInternal(fsRef);
1653 if (NS_FAILED(rv))
1654 return rv;
1655
1656 OSErr err = ::LSOpenFSRef(&fsRef, NULL);
1657 return MacErrorMapper(err);
1658}
1659
1660
1661//*****************************************************************************
1662// nsLocalFile::nsILocalFileMac
1663//*****************************************************************************
1664#pragma mark -
1665#pragma mark [nsILocalFileMac]
1666
1667/* void initWithCFURL (in CFURLRef aCFURL); */
1668NS_IMETHODIMP nsLocalFile::InitWithCFURL(CFURLRef aCFURL)
1669{
1670 NS_ENSURE_ARG(aCFURL);
1671
1672 SetBaseRef(aCFURL);
1673 return NS_OK;
1674}
1675
1676/* void initWithFSRef ([const] in FSRefPtr aFSRef); */
1677NS_IMETHODIMP nsLocalFile::InitWithFSRef(const FSRef *aFSRef)
1678{
1679 NS_ENSURE_ARG(aFSRef);
1680 nsresult rv = NS_ERROR_FAILURE;
1681
1682 CFURLRef newURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, aFSRef);
1683 if (newURLRef) {
1684 SetBaseRef(newURLRef);
1685 ::CFRelease(newURLRef);
1686 rv = NS_OK;
1687 }
1688 return rv;
1689}
1690
1691/* void initWithFSSpec ([const] in FSSpecPtr aFileSpec); */
1692NS_IMETHODIMP nsLocalFile::InitWithFSSpec(const FSSpec *aFileSpec)
1693{
1694 NS_ENSURE_ARG(aFileSpec);
1695
1696 FSRef fsRef;
1697 OSErr err = ::FSpMakeFSRef(aFileSpec, &fsRef);
1698 if (err == noErr)
1699 return InitWithFSRef(&fsRef);
1700 else if (err == fnfErr) {
1701 CInfoPBRec pBlock;
1702 FSSpec parentDirSpec;
1703
1704 memset(&pBlock, 0, sizeof(CInfoPBRec));
1705 parentDirSpec.name[0] = 0;
1706 pBlock.dirInfo.ioVRefNum = aFileSpec->vRefNum;
1707 pBlock.dirInfo.ioDrDirID = aFileSpec->parID;
1708 pBlock.dirInfo.ioNamePtr = (StringPtr)parentDirSpec.name;
1709 pBlock.dirInfo.ioFDirIndex = -1; //get info on parID
1710 err = ::PBGetCatInfoSync(&pBlock);
1711 if (err != noErr)
1712 return MacErrorMapper(err);
1713
1714 parentDirSpec.vRefNum = aFileSpec->vRefNum;
1715 parentDirSpec.parID = pBlock.dirInfo.ioDrParID;
1716 err = ::FSpMakeFSRef(&parentDirSpec, &fsRef);
1717 if (err != noErr)
1718 return MacErrorMapper(err);
1719 HFSUniStr255 unicodeName;
1720 err = ::HFSNameGetUnicodeName(aFileSpec->name, kTextEncodingUnknown, &unicodeName);
1721 if (err != noErr)
1722 return MacErrorMapper(err);
1723 nsresult rv = InitWithFSRef(&fsRef);
1724 if (NS_FAILED(rv))
1725 return rv;
1726 return Append(nsDependentString(unicodeName.unicode, unicodeName.length));
1727 }
1728 return MacErrorMapper(err);
1729}
1730
1731/* void initToAppWithCreatorCode (in OSType aAppCreator); */
1732NS_IMETHODIMP nsLocalFile::InitToAppWithCreatorCode(OSType aAppCreator)
1733{
1734 FSRef fsRef;
1735 OSErr err = ::LSFindApplicationForInfo(aAppCreator, nsnull, nsnull, &fsRef, nsnull);
1736 if (err != noErr)
1737 return MacErrorMapper(err);
1738 return InitWithFSRef(&fsRef);
1739}
1740
1741/* CFURLRef getCFURL (); */
1742NS_IMETHODIMP nsLocalFile::GetCFURL(CFURLRef *_retval)
1743{
1744 NS_ENSURE_ARG_POINTER(_retval);
1745 CFURLRef whichURLRef = mFollowLinks ? mTargetRef : mBaseRef;
1746 if (whichURLRef)
1747 ::CFRetain(whichURLRef);
1748 *_retval = whichURLRef;
1749 return whichURLRef ? NS_OK : NS_ERROR_FAILURE;
1750}
1751
1752/* FSRef getFSRef (); */
1753NS_IMETHODIMP nsLocalFile::GetFSRef(FSRef *_retval)
1754{
1755 NS_ENSURE_ARG_POINTER(_retval);
1756 return GetFSRefInternal(*_retval);
1757}
1758
1759/* FSSpec getFSSpec (); */
1760NS_IMETHODIMP nsLocalFile::GetFSSpec(FSSpec *_retval)
1761{
1762 NS_ENSURE_ARG_POINTER(_retval);
1763
1764 // Check we are correctly initialized.
1765 CHECK_mBaseRef();
1766
1767 OSErr err;
1768 FSRef fsRef;
1769 nsresult rv = GetFSRefInternal(fsRef);
1770 if (NS_SUCCEEDED(rv)) {
1771 // If the leaf node exists, things are simple.
1772 err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNone,
1773 nsnull, nsnull, _retval, nsnull);
1774 return MacErrorMapper(err);
1775 }
1776 else if (rv == NS_ERROR_FILE_NOT_FOUND) {
1777 // If the parent of the leaf exists, make an FSSpec from that.
1778 CFURLRef parentURLRef = ::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, mBaseRef);
1779 if (!parentURLRef)
1780 return NS_ERROR_FAILURE;
1781
1782 err = fnfErr;
1783 if (::CFURLGetFSRef(parentURLRef, &fsRef)) {
1784 FSCatalogInfo catalogInfo;
1785 if ((err = ::FSGetCatalogInfo(&fsRef,
1786 kFSCatInfoVolume + kFSCatInfoNodeID + kFSCatInfoTextEncoding,
1787 &catalogInfo, nsnull, nsnull, nsnull)) == noErr) {
1788 nsAutoString leafName;
1789 if (NS_SUCCEEDED(GetLeafName(leafName))) {
1790 Str31 hfsName;
1791 if ((err = ::UnicodeNameGetHFSName(leafName.Length(),
1792 leafName.get(),
1793 catalogInfo.textEncodingHint,
1794 catalogInfo.nodeID == fsRtDirID,
1795 hfsName)) == noErr)
1796 err = ::FSMakeFSSpec(catalogInfo.volume, catalogInfo.nodeID, hfsName, _retval);
1797 }
1798 }
1799 }
1800 ::CFRelease(parentURLRef);
1801 rv = MacErrorMapper(err);
1802 }
1803 return rv;
1804}
1805
1806/* readonly attribute PRInt64 fileSizeWithResFork; */
1807NS_IMETHODIMP nsLocalFile::GetFileSizeWithResFork(PRInt64 *aFileSizeWithResFork)
1808{
1809 NS_ENSURE_ARG_POINTER(aFileSizeWithResFork);
1810
1811 FSRef fsRef;
1812 nsresult rv = GetFSRefInternal(fsRef);
1813 if (NS_FAILED(rv))
1814 return rv;
1815
1816 FSCatalogInfo catalogInfo;
1817 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoDataSizes + kFSCatInfoRsrcSizes,
1818 &catalogInfo, nsnull, nsnull, nsnull);
1819 if (err != noErr)
1820 return MacErrorMapper(err);
1821
1822 *aFileSizeWithResFork = catalogInfo.dataLogicalSize + catalogInfo.rsrcLogicalSize;
1823 return NS_OK;
1824}
1825
1826/* attribute OSType fileType; */
1827NS_IMETHODIMP nsLocalFile::GetFileType(OSType *aFileType)
1828{
1829 NS_ENSURE_ARG_POINTER(aFileType);
1830
1831 FSRef fsRef;
1832 nsresult rv = GetFSRefInternal(fsRef);
1833 if (NS_FAILED(rv))
1834 return rv;
1835
1836 FinderInfo fInfo;
1837 OSErr err = ::FSGetFinderInfo(&fsRef, &fInfo, nsnull, nsnull);
1838 if (err != noErr)
1839 return MacErrorMapper(err);
1840 *aFileType = fInfo.file.fileType;
1841 return NS_OK;
1842}
1843
1844NS_IMETHODIMP nsLocalFile::SetFileType(OSType aFileType)
1845{
1846 FSRef fsRef;
1847 nsresult rv = GetFSRefInternal(fsRef);
1848 if (NS_FAILED(rv))
1849 return rv;
1850
1851 OSErr err = ::FSChangeCreatorType(&fsRef, 0, aFileType);
1852 return MacErrorMapper(err);
1853}
1854
1855/* attribute OSType fileCreator; */
1856NS_IMETHODIMP nsLocalFile::GetFileCreator(OSType *aFileCreator)
1857{
1858 NS_ENSURE_ARG_POINTER(aFileCreator);
1859
1860 FSRef fsRef;
1861 nsresult rv = GetFSRefInternal(fsRef);
1862 if (NS_FAILED(rv))
1863 return rv;
1864
1865 FinderInfo fInfo;
1866 OSErr err = ::FSGetFinderInfo(&fsRef, &fInfo, nsnull, nsnull);
1867 if (err != noErr)
1868 return MacErrorMapper(err);
1869 *aFileCreator = fInfo.file.fileCreator;
1870 return NS_OK;
1871}
1872
1873NS_IMETHODIMP nsLocalFile::SetFileCreator(OSType aFileCreator)
1874{
1875 FSRef fsRef;
1876 nsresult rv = GetFSRefInternal(fsRef);
1877 if (NS_FAILED(rv))
1878 return rv;
1879
1880 OSErr err = ::FSChangeCreatorType(&fsRef, aFileCreator, 0);
1881 return MacErrorMapper(err);
1882}
1883
1884/* void setFileTypeAndCreatorFromMIMEType (in string aMIMEType); */
1885NS_IMETHODIMP nsLocalFile::SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType)
1886{
1887 // XXX - This should be cut from the API. Would create an evil dependency.
1888 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
1889 return NS_ERROR_NOT_IMPLEMENTED;
1890}
1891
1892/* void setFileTypeAndCreatorFromExtension (in string aExtension); */
1893NS_IMETHODIMP nsLocalFile::SetFileTypeAndCreatorFromExtension(const char *aExtension)
1894{
1895 // XXX - This should be cut from the API. Would create an evil dependency.
1896 NS_ERROR("NS_ERROR_NOT_IMPLEMENTED");
1897 return NS_ERROR_NOT_IMPLEMENTED;
1898}
1899
1900/* void launchWithDoc (in nsILocalFile aDocToLoad, in boolean aLaunchInBackground); */
1901NS_IMETHODIMP nsLocalFile::LaunchWithDoc(nsILocalFile *aDocToLoad, PRBool aLaunchInBackground)
1902{
1903 PRBool isExecutable;
1904 nsresult rv = IsExecutable(&isExecutable);
1905 if (NS_FAILED(rv))
1906 return rv;
1907 if (!isExecutable)
1908 return NS_ERROR_FILE_EXECUTION_FAILED;
1909
1910 FSRef appFSRef, docFSRef;
1911 rv = GetFSRefInternal(appFSRef);
1912 if (NS_FAILED(rv))
1913 return rv;
1914
1915 if (aDocToLoad) {
1916 nsCOMPtr<nsILocalFileMac> macDoc = do_QueryInterface(aDocToLoad);
1917 rv = macDoc->GetFSRef(&docFSRef);
1918 if (NS_FAILED(rv))
1919 return rv;
1920 }
1921
1922 LSLaunchFlags theLaunchFlags = kLSLaunchDefaults;
1923 LSLaunchFSRefSpec thelaunchSpec;
1924
1925 if (aLaunchInBackground)
1926 theLaunchFlags |= kLSLaunchDontSwitch;
1927 memset(&thelaunchSpec, 0, sizeof(LSLaunchFSRefSpec));
1928
1929 thelaunchSpec.appRef = &appFSRef;
1930 if (aDocToLoad) {
1931 thelaunchSpec.numDocs = 1;
1932 thelaunchSpec.itemRefs = &docFSRef;
1933 }
1934 thelaunchSpec.launchFlags = theLaunchFlags;
1935
1936 OSErr err = ::LSOpenFromRefSpec(&thelaunchSpec, NULL);
1937 if (err != noErr)
1938 return MacErrorMapper(err);
1939
1940 return NS_OK;
1941}
1942
1943/* void openDocWithApp (in nsILocalFile aAppToOpenWith, in boolean aLaunchInBackground); */
1944NS_IMETHODIMP nsLocalFile::OpenDocWithApp(nsILocalFile *aAppToOpenWith, PRBool aLaunchInBackground)
1945{
1946 nsresult rv;
1947 OSErr err;
1948
1949 FSRef docFSRef, appFSRef;
1950 rv = GetFSRefInternal(docFSRef);
1951 if (NS_FAILED(rv))
1952 return rv;
1953
1954 if (aAppToOpenWith) {
1955 nsCOMPtr<nsILocalFileMac> appFileMac = do_QueryInterface(aAppToOpenWith, &rv);
1956 if (!appFileMac)
1957 return rv;
1958
1959 PRBool isExecutable;
1960 rv = appFileMac->IsExecutable(&isExecutable);
1961 if (NS_FAILED(rv))
1962 return rv;
1963 if (!isExecutable)
1964 return NS_ERROR_FILE_EXECUTION_FAILED;
1965
1966 rv = appFileMac->GetFSRef(&appFSRef);
1967 if (NS_FAILED(rv))
1968 return rv;
1969 }
1970 else {
1971 OSType fileCreator;
1972 rv = GetFileCreator(&fileCreator);
1973 if (NS_FAILED(rv))
1974 return rv;
1975
1976 err = ::LSFindApplicationForInfo(fileCreator, nsnull, nsnull, &appFSRef, nsnull);
1977 if (err != noErr)
1978 return MacErrorMapper(err);
1979 }
1980
1981 LSLaunchFlags theLaunchFlags = kLSLaunchDefaults;
1982 LSLaunchFSRefSpec thelaunchSpec;
1983
1984 if (aLaunchInBackground)
1985 theLaunchFlags |= kLSLaunchDontSwitch;
1986 memset(&thelaunchSpec, 0, sizeof(LSLaunchFSRefSpec));
1987
1988 thelaunchSpec.appRef = &appFSRef;
1989 thelaunchSpec.numDocs = 1;
1990 thelaunchSpec.itemRefs = &docFSRef;
1991 thelaunchSpec.launchFlags = theLaunchFlags;
1992
1993 err = ::LSOpenFromRefSpec(&thelaunchSpec, NULL);
1994 if (err != noErr)
1995 return MacErrorMapper(err);
1996
1997 return NS_OK;
1998}
1999
2000/* boolean isPackage (); */
2001NS_IMETHODIMP nsLocalFile::IsPackage(PRBool *_retval)
2002{
2003 NS_ENSURE_ARG(_retval);
2004 *_retval = PR_FALSE;
2005
2006 FSRef fsRef;
2007 nsresult rv = GetFSRefInternal(fsRef);
2008 if (NS_FAILED(rv))
2009 return rv;
2010
2011 FSCatalogInfo catalogInfo;
2012 OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags + kFSCatInfoFinderInfo,
2013 &catalogInfo, nsnull, nsnull, nsnull);
2014 if (err != noErr)
2015 return MacErrorMapper(err);
2016 if ((catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) {
2017 FileInfo *fInfoPtr = (FileInfo *)(catalogInfo.finderInfo);
2018 if ((fInfoPtr->finderFlags & kHasBundle) != 0) {
2019 *_retval = PR_TRUE;
2020 }
2021 else {
2022 // Folders ending with ".app" are also considered to
2023 // be packages, even if the top-level folder doesn't have bundle set
2024 nsCAutoString name;
2025 if (NS_SUCCEEDED(rv = GetNativeLeafName(name))) {
2026 const char *extPtr = strrchr(name.get(), '.');
2027 if (extPtr) {
2028 if ((nsCRT::strcasecmp(extPtr, ".app") == 0))
2029 *_retval = PR_TRUE;
2030 }
2031 }
2032 }
2033 }
2034 return NS_OK;
2035}
2036
2037NS_IMETHODIMP
2038nsLocalFile::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
2061NS_IMETHODIMP
2062nsLocalFile::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
2082
2083//*****************************************************************************
2084// nsLocalFile Methods
2085//*****************************************************************************
2086#pragma mark -
2087#pragma mark [Protected Methods]
2088
2089nsresult nsLocalFile::SetBaseRef(CFURLRef aCFURLRef)
2090{
2091 NS_ENSURE_ARG(aCFURLRef);
2092
2093 ::CFRetain(aCFURLRef);
2094 if (mBaseRef)
2095 ::CFRelease(mBaseRef);
2096 mBaseRef = aCFURLRef;
2097
2098 mFollowLinksDirty = PR_TRUE;
2099 UpdateTargetRef();
2100 mCachedFSRefValid = PR_FALSE;
2101 return NS_OK;
2102}
2103
2104nsresult nsLocalFile::UpdateTargetRef()
2105{
2106 // Check we are correctly initialized.
2107 CHECK_mBaseRef();
2108
2109 if (mFollowLinksDirty) {
2110 if (mTargetRef) {
2111 ::CFRelease(mTargetRef);
2112 mTargetRef = nsnull;
2113 }
2114 if (mFollowLinks) {
2115 mTargetRef = mBaseRef;
2116 ::CFRetain(mTargetRef);
2117
2118 FSRef fsRef;
2119 if (::CFURLGetFSRef(mBaseRef, &fsRef)) {
2120 Boolean targetIsFolder, wasAliased;
2121 if (FSResolveAliasFile(&fsRef, true /*resolveAliasChains*/,
2122 &targetIsFolder, &wasAliased) == noErr && wasAliased) {
2123 ::CFRelease(mTargetRef);
2124 mTargetRef = CFURLCreateFromFSRef(NULL, &fsRef);
2125 if (!mTargetRef)
2126 return NS_ERROR_FAILURE;
2127 }
2128 }
2129 mFollowLinksDirty = PR_FALSE;
2130 }
2131 }
2132 return NS_OK;
2133}
2134
2135nsresult nsLocalFile::GetFSRefInternal(FSRef& aFSRef, PRBool bForceUpdateCache)
2136{
2137 if (bForceUpdateCache || !mCachedFSRefValid) {
2138 mCachedFSRefValid = PR_FALSE;
2139 CFURLRef whichURLRef = mFollowLinks ? mTargetRef : mBaseRef;
2140 NS_ENSURE_TRUE(whichURLRef, NS_ERROR_NULL_POINTER);
2141 if (::CFURLGetFSRef(whichURLRef, &mCachedFSRef))
2142 mCachedFSRefValid = PR_TRUE;
2143 }
2144 if (mCachedFSRefValid) {
2145 aFSRef = mCachedFSRef;
2146 return NS_OK;
2147 }
2148 // CFURLGetFSRef only returns a Boolean for success,
2149 // so we have to assume what the error was. This is
2150 // the only probable cause.
2151 return NS_ERROR_FILE_NOT_FOUND;
2152}
2153
2154nsresult nsLocalFile::GetPathInternal(nsACString& path)
2155{
2156 nsresult rv = NS_ERROR_FAILURE;
2157
2158 CFURLRef whichURLRef = mFollowLinks ? mTargetRef : mBaseRef;
2159 NS_ENSURE_TRUE(whichURLRef, NS_ERROR_NULL_POINTER);
2160
2161 CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(whichURLRef, kCFURLPOSIXPathStyle);
2162 if (pathStrRef) {
2163 rv = CFStringReftoUTF8(pathStrRef, path);
2164 ::CFRelease(pathStrRef);
2165 }
2166 return rv;
2167}
2168
2169nsresult nsLocalFile::CopyInternal(nsIFile* aParentDir,
2170 const nsAString& newName,
2171 PRBool followLinks)
2172{
2173 // Check we are correctly initialized.
2174 CHECK_mBaseRef();
2175
2176 StFollowLinksState srcFollowState(*this, followLinks);
2177
2178 nsresult rv;
2179 OSErr err;
2180 FSRef srcFSRef, newFSRef;
2181
2182 rv = GetFSRefInternal(srcFSRef);
2183 if (NS_FAILED(rv))
2184 return rv;
2185
2186 nsCOMPtr<nsIFile> newParentDir = aParentDir;
2187
2188 if (!newParentDir) {
2189 if (newName.IsEmpty())
2190 return NS_ERROR_INVALID_ARG;
2191 rv = GetParent(getter_AddRefs(newParentDir));
2192 if (NS_FAILED(rv))
2193 return rv;
2194 }
2195
2196 // If newParentDir does not exist, create it
2197 PRBool exists;
2198 rv = newParentDir->Exists(&exists);
2199 if (NS_FAILED(rv))
2200 return rv;
2201 if (!exists) {
2202 rv = newParentDir->Create(nsIFile::DIRECTORY_TYPE, 0777);
2203 if (NS_FAILED(rv))
2204 return rv;
2205 }
2206
2207 FSRef destFSRef;
2208 nsCOMPtr<nsILocalFileMac> newParentDirMac(do_QueryInterface(newParentDir));
2209 if (!newParentDirMac)
2210 return NS_ERROR_NO_INTERFACE;
2211 rv = newParentDirMac->GetFSRef(&destFSRef);
2212 if (NS_FAILED(rv))
2213 return rv;
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
2220 return MacErrorMapper(err);
2221}
2222
2223const PRInt64 kMillisecsPerSec = 1000LL;
2224const PRInt64 kUTCDateTimeFractionDivisor = 65535LL;
2225
2226PRInt64 nsLocalFile::HFSPlustoNSPRTime(const UTCDateTime& utcTime)
2227{
2228 // Start with seconds since Jan. 1, 1904 GMT
2229 PRInt64 result = ((PRInt64)utcTime.highSeconds << 32) + (PRInt64)utcTime.lowSeconds;
2230 // Subtract to convert to NSPR epoch of 1970
2231 result -= kJanuaryFirst1970Seconds;
2232 // Convert to millisecs
2233 result *= kMillisecsPerSec;
2234 // Convert the fraction to millisecs and add it
2235 result += ((PRInt64)utcTime.fraction * kMillisecsPerSec) / kUTCDateTimeFractionDivisor;
2236
2237 return result;
2238}
2239
2240void nsLocalFile::NSPRtoHFSPlusTime(PRInt64 nsprTime, UTCDateTime& utcTime)
2241{
2242 PRInt64 fraction = nsprTime % kMillisecsPerSec;
2243 PRInt64 seconds = (nsprTime / kMillisecsPerSec) + kJanuaryFirst1970Seconds;
2244 utcTime.highSeconds = (UInt16)((PRUint64)seconds >> 32);
2245 utcTime.lowSeconds = (UInt32)seconds;
2246 utcTime.fraction = (UInt16)((fraction * kUTCDateTimeFractionDivisor) / kMillisecsPerSec);
2247}
2248
2249nsresult nsLocalFile::CFStringReftoUTF8(CFStringRef aInStrRef, nsACString& aOutStr)
2250{
2251 nsresult rv = NS_ERROR_FAILURE;
2252 CFIndex usedBufLen, inStrLen = ::CFStringGetLength(aInStrRef);
2253 CFIndex charsConverted = ::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen),
2254 kCFStringEncodingUTF8, 0, PR_FALSE, nsnull, 0, &usedBufLen);
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
2266 nsAutoBuffer<UInt8, FILENAME_BUFFER_SIZE> buffer;
2267 if (buffer.EnsureElemCapacity(usedBufLen + 1)) {
2268 ::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen),
2269 kCFStringEncodingUTF8, 0, false, buffer.get(), usedBufLen, &usedBufLen);
2270 buffer.get()[usedBufLen] = '\0';
2271 aOutStr.Assign(nsDependentCString((char*)buffer.get()));
2272 rv = NS_OK;
2273 }
2274#endif
2275 }
2276 return rv;
2277}
2278
2279// nsIHashable
2280
2281NS_IMETHODIMP
2282nsLocalFile::Equals(nsIHashable* aOther, PRBool *aResult)
2283{
2284 return EqualsInternal(aOther, PR_FALSE, aResult);
2285}
2286
2287NS_IMETHODIMP
2288nsLocalFile::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;
2295}
2296
2297//*****************************************************************************
2298// Global Functions
2299//*****************************************************************************
2300#pragma mark -
2301#pragma mark [Global Functions]
2302
2303void nsLocalFile::GlobalInit()
2304{
2305}
2306
2307void nsLocalFile::GlobalShutdown()
2308{
2309}
2310
2311nsresult NS_NewLocalFile(const nsAString& path, PRBool followLinks, nsILocalFile* *result)
2312{
2313 nsLocalFile* file = new nsLocalFile;
2314 if (file == nsnull)
2315 return NS_ERROR_OUT_OF_MEMORY;
2316 NS_ADDREF(file);
2317
2318 file->SetFollowLinks(followLinks);
2319
2320 if (!path.IsEmpty()) {
2321 nsresult rv = file->InitWithPath(path);
2322 if (NS_FAILED(rv)) {
2323 NS_RELEASE(file);
2324 return rv;
2325 }
2326 }
2327 *result = file;
2328 return NS_OK;
2329}
2330
2331nsresult NS_NewNativeLocalFile(const nsACString& path, PRBool followLinks, nsILocalFile **result)
2332{
2333 return NS_NewLocalFile(NS_ConvertUTF8toUTF16(path), followLinks, result);
2334}
2335
2336nsresult NS_NewLocalFileWithFSSpec(const FSSpec* inSpec, PRBool followLinks, nsILocalFileMac **result)
2337{
2338 nsLocalFile* file = new nsLocalFile();
2339 if (file == nsnull)
2340 return NS_ERROR_OUT_OF_MEMORY;
2341 NS_ADDREF(file);
2342
2343 file->SetFollowLinks(followLinks);
2344
2345 nsresult rv = file->InitWithFSSpec(inSpec);
2346 if (NS_FAILED(rv)) {
2347 NS_RELEASE(file);
2348 return rv;
2349 }
2350 *result = file;
2351 return NS_OK;
2352}
2353
2354nsresult 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
2372//*****************************************************************************
2373// Static Functions
2374//*****************************************************************************
2375
2376static nsresult MacErrorMapper(OSErr inErr)
2377{
2378 nsresult outErr;
2379
2380 switch (inErr)
2381 {
2382 case noErr:
2383 outErr = NS_OK;
2384 break;
2385
2386 case fnfErr:
2387 outErr = NS_ERROR_FILE_NOT_FOUND;
2388 break;
2389
2390 case dupFNErr:
2391 outErr = NS_ERROR_FILE_ALREADY_EXISTS;
2392 break;
2393
2394 case dskFulErr:
2395 outErr = NS_ERROR_FILE_DISK_FULL;
2396 break;
2397
2398 case fLckdErr:
2399 outErr = NS_ERROR_FILE_IS_LOCKED;
2400 break;
2401
2402 // Can't find good map for some
2403 case bdNamErr:
2404 outErr = NS_ERROR_FAILURE;
2405 break;
2406
2407 default:
2408 outErr = NS_ERROR_FAILURE;
2409 break;
2410 }
2411 return outErr;
2412}
2413
2414static OSErr FindRunningAppBySignature(OSType aAppSig, ProcessSerialNumber& outPsn)
2415{
2416 ProcessInfoRec info;
2417 OSErr err = noErr;
2418
2419 outPsn.highLongOfPSN = 0;
2420 outPsn.lowLongOfPSN = kNoProcess;
2421
2422 while (PR_TRUE)
2423 {
2424 err = ::GetNextProcess(&outPsn);
2425 if (err == procNotFound)
2426 break;
2427 if (err != noErr)
2428 return err;
2429 info.processInfoLength = sizeof(ProcessInfoRec);
2430 info.processName = nil;
2431 info.processAppSpec = nil;
2432 err = ::GetProcessInformation(&outPsn, &info);
2433 if (err != noErr)
2434 return err;
2435
2436 if (info.processSignature == aAppSig)
2437 return noErr;
2438 }
2439 return procNotFound;
2440}
2441
2442// Convert a UTF-8 string to a UTF-16 string while normalizing to
2443// Normalization Form C (composed Unicode). We need this because
2444// Mac OS X file system uses NFD (Normalization Form D : decomposed Unicode)
2445// while most other OS', server-side programs usually expect NFC.
2446
2447typedef void (*UnicodeNormalizer) (CFMutableStringRef, CFStringNormalizationForm);
2448static void CopyUTF8toUTF16NFC(const nsACString& aSrc, nsAString& aResult)
2449{
2450 static PRBool sChecked = PR_FALSE;
2451 static UnicodeNormalizer sUnicodeNormalizer = NULL;
2452
2453 // CFStringNormalize was not introduced until Mac OS 10.2
2454 if (!sChecked) {
2455 CFBundleRef carbonBundle =
2456 CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
2457 if (carbonBundle)
2458 sUnicodeNormalizer = (UnicodeNormalizer)
2459 ::CFBundleGetFunctionPointerForName(carbonBundle,
2460 CFSTR("CFStringNormalize"));
2461 sChecked = PR_TRUE;
2462 }
2463
2464 if (!sUnicodeNormalizer) { // OS X 10.2 or earlier
2465 CopyUTF8toUTF16(aSrc, aResult);
2466 return;
2467 }
2468
2469 const nsAFlatCString &inFlatSrc = PromiseFlatCString(aSrc);
2470
2471 // The number of 16bit code units in a UTF-16 string will never be
2472 // larger than the number of bytes in the corresponding UTF-8 string.
2473 CFMutableStringRef inStr =
2474 ::CFStringCreateMutable(NULL, inFlatSrc.Length());
2475
2476 if (!inStr) {
2477 CopyUTF8toUTF16(aSrc, aResult);
2478 return;
2479 }
2480
2481 ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8);
2482
2483 sUnicodeNormalizer(inStr, kCFStringNormalizationFormC);
2484
2485 CFIndex length = CFStringGetLength(inStr);
2486 const UniChar* chars = CFStringGetCharactersPtr(inStr);
2487
2488 if (chars)
2489 aResult.Assign(chars, length);
2490 else {
2491 nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer;
2492 if (!buffer.EnsureElemCapacity(length))
2493 CopyUTF8toUTF16(aSrc, aResult);
2494 else {
2495 CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.get());
2496 aResult.Assign(buffer.get(), length);
2497 }
2498 }
2499 CFRelease(inStr);
2500}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette