470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
+
+
+
+
+
+
+
+
+
|
objc_autoreleasePoolPop(pool);
}
- (void)copyItemAtURL: (OFURL *)source
toURL: (OFURL *)destination
{
void *pool;
OF_KINDOF(OFURLHandler *) URLHandler;
of_file_attributes_t attributes;
of_file_type_t type;
if (source == nil || destination == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil)
@throw [OFUnsupportedProtocolException
exceptionWithURL: source];
if ([URLHandler copyItemAtURL: source
toURL: destination])
return;
if ([self fileExistsAtURL: destination])
@throw [OFCopyItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: EEXIST];
|
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
objc_autoreleasePoolPop(pool);
}
- (void)moveItemAtPath: (OFString *)source
toPath: (OFString *)destination
{
if (source == nil || destination == nil)
@throw [OFInvalidArgumentException exception];
if ([self fileExistsAtPath: destination])
@throw [OFMoveItemFailedException
exceptionWithSourcePath: source
destinationPath: destination
errNo: EEXIST];
#if defined(OF_WINDOWS)
void *pool = objc_autoreleasePoolPush();
if (_wrename([source UTF16String], [destination UTF16String]) != 0) {
if (errno != EXDEV)
@throw [OFMoveItemFailedException
exceptionWithSourcePath: source
destinationPath: destination
errNo: errno];
#elif defined(OF_MORPHOS)
of_string_encoding_t encoding = [OFLocalization encoding];
[self moveItemAtURL: [OFURL fileURLWithPath: source]
if (!Rename([source cStringWithEncoding: encoding],
[destination cStringWithEncoding: encoding]) != 0) {
LONG err;
if ((err = IoErr()) != ERROR_RENAME_ACROSS_DEVICES) {
int errNo;
switch (err) {
case ERROR_OBJECT_IN_USE:
case ERROR_DISK_NOT_VALIDATED:
errNo = EBUSY;
break;
case ERROR_OBJECT_EXISTS:
errNo = EEXIST;
break;
case ERROR_OBJECT_NOT_FOUND:
errNo = ENOENT;
break;
case ERROR_DISK_WRITE_PROTECTED:
errNo = EROFS;
break;
default:
errNo = 0;
break;
}
@throw [OFMoveItemFailedException
exceptionWithSourcePath: source
destinationPath: destination
errNo: errNo];
}
#else
of_string_encoding_t encoding = [OFLocalization encoding];
if (rename([source cStringWithEncoding: encoding],
[destination cStringWithEncoding: encoding]) != 0) {
if (errno != EXDEV)
@throw [OFMoveItemFailedException
exceptionWithSourcePath: source
destinationPath: destination
errNo: errno];
#endif
@try {
[self copyItemAtPath: source
toPath: destination];
toURL: [OFURL fileURLWithPath: destination]];
} @catch (OFCopyItemFailedException *e) {
[self removeItemAtPath: destination];
@throw [OFMoveItemFailedException
exceptionWithSourcePath: source
destinationPath: destination
errNo: [e errNo]];
}
@try {
[self removeItemAtPath: source];
} @catch (OFRemoveItemFailedException *e) {
@throw [OFMoveItemFailedException
exceptionWithSourcePath: source
destinationPath: destination
errNo: [e errNo]];
}
}
#ifdef OF_WINDOWS
objc_autoreleasePoolPop(pool);
#endif
}
- (void)moveItemAtURL: (OFURL *)source
toURL: (OFURL *)destination
{
void *pool;
OF_KINDOF(OFURLHandler *) URLHandler;
if (source == nil || destination == nil)
@throw [OFInvalidArgumentException exception];
void *pool = objc_autoreleasePoolPush();
pool = objc_autoreleasePoolPush();
if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil)
@throw [OFUnsupportedProtocolException
exceptionWithURL: source];
[self moveItemAtPath: [source fileSystemRepresentation]
toPath: [destination fileSystemRepresentation]];
@try {
if ([URLHandler moveItemAtURL: source
toURL: destination])
return;
} @catch (OFMoveItemFailedException *e) {
if ([e errNo] != EXDEV)
@throw e;
}
if ([self fileExistsAtURL: destination])
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: EEXIST];
@try {
[self copyItemAtURL: source
toURL: destination];
} @catch (OFCopyItemFailedException *e) {
[self removeItemAtURL: destination];
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: [e errNo]];
}
@try {
[self removeItemAtURL: source];
} @catch (OFRemoveItemFailedException *e) {
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: [e errNo]];
}
objc_autoreleasePoolPop(pool);
}
- (void)removeItemAtURL: (OFURL *)URL
{
OF_KINDOF(OFURLHandler *) URLHandler;
|