︙ | | |
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
-
+
-
|
{
if (dirChanged)
UnLock(CurrentDir(originalDirLock));
}
#endif
static id
attributeForKeyOrException(of_file_attributes_t attributes,
attributeForKeyOrException(OFFileAttributes attributes, OFFileAttributeKey key)
of_file_attribute_key_t key)
{
id object = [attributes objectForKey: key];
if (object == nil)
@throw [OFUndefinedKeyException exceptionWithObject: attributes
key: key];
|
︙ | | |
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
-
+
-
+
-
+
-
-
+
-
+
-
-
+
-
-
|
[ret retain];
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
#endif
- (of_file_attributes_t)attributesOfItemAtURL: (OFURL *)URL
- (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL
{
OFURLHandler *URLHandler;
if (URL == nil)
@throw [OFInvalidArgumentException exception];
if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
return [URLHandler attributesOfItemAtURL: URL];
}
#ifdef OF_HAVE_FILES
- (of_file_attributes_t)attributesOfItemAtPath: (OFString *)path
- (OFFileAttributes)attributesOfItemAtPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
of_file_attributes_t ret;
OFFileAttributes ret;
ret = [self attributesOfItemAtURL: [OFURL fileURLWithPath: path]];
[ret retain];
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
#endif
- (void)setAttributes: (of_file_attributes_t)attributes
ofItemAtURL: (OFURL *)URL
- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL
{
OFURLHandler *URLHandler;
if (URL == nil)
@throw [OFInvalidArgumentException exception];
if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
[URLHandler setAttributes: attributes
[URLHandler setAttributes: attributes ofItemAtURL: URL];
ofItemAtURL: URL];
}
#ifdef OF_HAVE_FILES
- (void)setAttributes: (of_file_attributes_t)attributes
- (void)setAttributes: (OFFileAttributes)attributes
ofItemAtPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
[self setAttributes: attributes
ofItemAtURL: [OFURL fileURLWithPath: path]];
objc_autoreleasePoolPop(pool);
}
#endif
- (bool)fileExistsAtURL: (OFURL *)URL
{
OFURLHandler *URLHandler;
|
︙ | | |
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
-
+
-
+
+
-
+
+
+
+
+
|
[self createDirectoryAtURL: [OFURL fileURLWithPath: path]
createParents: createParents];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtURL: (OFURL *)URL
- (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL
{
OFURLHandler *URLHandler;
if (URL == nil)
@throw [OFInvalidArgumentException exception];
if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
return [URLHandler contentsOfDirectoryAtURL: URL];
}
#ifdef OF_HAVE_FILES
- (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
OFArray OF_GENERIC(OFString *) *ret;
OFArray OF_GENERIC(OFURL *) *URLs;
OFMutableArray OF_GENERIC(OFString *) *ret;
ret = [self contentsOfDirectoryAtURL: [OFURL fileURLWithPath: path]];
URLs = [self contentsOfDirectoryAtURL: [OFURL fileURLWithPath: path]];
ret = [OFMutableArray arrayWithCapacity: URLs.count];
for (OFURL *URL in URLs)
[ret addObject: URL.lastPathComponent];
[ret retain];
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
|
︙ | | |
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
-
+
-
-
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
|
void *pool = objc_autoreleasePoolPush();
[self changeCurrentDirectoryPath: URL.fileSystemRepresentation];
objc_autoreleasePoolPop(pool);
}
- (void)copyItemAtPath: (OFString *)source
- (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination
toPath: (OFString *)destination
{
void *pool = objc_autoreleasePoolPush();
[self copyItemAtURL: [OFURL fileURLWithPath: source]
toURL: [OFURL fileURLWithPath: destination]];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)copyItemAtURL: (OFURL *)source
- (void)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination
toURL: (OFURL *)destination
{
void *pool;
OFURLHandler *URLHandler;
of_file_attributes_t attributes;
of_file_type_t type;
OFFileAttributes attributes;
OFFileAttributeType 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
if ([URLHandler copyItemAtURL: source toURL: destination])
toURL: destination])
return;
if ([self fileExistsAtURL: destination])
@throw [OFCopyItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: EEXIST];
@try {
attributes = [self attributesOfItemAtURL: source];
} @catch (OFRetrieveItemAttributesFailedException *e) {
@throw [OFCopyItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: e.errNo];
}
type = attributes.fileType;
if ([type isEqual: of_file_type_directory]) {
OFArray *contents;
if ([type isEqual: OFFileTypeDirectory]) {
OFArray OF_GENERIC(OFURL *) *contents;
@try {
[self createDirectoryAtURL: destination];
@try {
of_file_attribute_key_t key =
OFFileAttributeKey key = OFFilePOSIXPermissions;
of_file_attribute_key_posix_permissions;
OFNumber *permissions =
[attributes objectForKey: key];
of_file_attributes_t destinationAttributes;
OFFileAttributes destinationAttributes;
if (permissions != nil) {
destinationAttributes = [OFDictionary
dictionaryWithObject: permissions
forKey: key];
[self
setAttributes: destinationAttributes
|
︙ | | |
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
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
|
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
-
+
-
+
-
-
-
+
-
-
+
-
+
-
-
+
-
+
-
+
-
-
+
|
exceptionWithSourceURL: source
destinationURL: destination
errNo: [e errNo]];
@throw e;
}
for (OFString *item in contents) {
for (OFURL *item in contents) {
void *pool2 = objc_autoreleasePoolPush();
OFURL *sourceURL, *destinationURL;
OFURL *destinationURL = [destination
sourceURL =
[source URLByAppendingPathComponent: item];
URLByAppendingPathComponent:
destinationURL =
[destination URLByAppendingPathComponent: item];
item.lastPathComponent];
[self copyItemAtURL: sourceURL
[self copyItemAtURL: item toURL: destinationURL];
toURL: destinationURL];
objc_autoreleasePoolPop(pool2);
}
} else if ([type isEqual: of_file_type_regular]) {
} else if ([type isEqual: OFFileTypeRegular]) {
size_t pageSize = [OFSystemInfo pageSize];
OFStream *sourceStream = nil;
OFStream *destinationStream = nil;
char *buffer;
buffer = of_alloc(1, pageSize);
buffer = OFAllocMemory(1, pageSize);
@try {
sourceStream = [[OFURLHandler handlerForURL: source]
openItemAtURL: source
mode: @"r"];
destinationStream = [[OFURLHandler handlerForURL:
destination] openItemAtURL: destination
mode: @"w"];
while (!sourceStream.atEndOfStream) {
size_t length;
length = [sourceStream
readIntoBuffer: buffer
length: pageSize];
[destinationStream writeBuffer: buffer
length: length];
}
@try {
of_file_attribute_key_t key =
OFFileAttributeKey key = OFFilePOSIXPermissions;
of_file_attribute_key_posix_permissions;
OFNumber *permissions = [attributes
objectForKey: key];
of_file_attributes_t destinationAttributes;
OFFileAttributes destinationAttributes;
if (permissions != nil) {
destinationAttributes = [OFDictionary
dictionaryWithObject: permissions
forKey: key];
[self
setAttributes: destinationAttributes
|
︙ | | |
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
|
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
|
-
+
-
+
|
destinationURL: destination
errNo: [e errNo]];
@throw e;
} @finally {
[sourceStream close];
[destinationStream close];
free(buffer);
OFFreeMemory(buffer);
}
} else if ([type isEqual: of_file_type_symbolic_link]) {
} else if ([type isEqual: OFFileTypeSymbolicLink]) {
@try {
OFString *linkDestination =
attributes.fileSymbolicLinkDestination;
[self createSymbolicLinkAtURL: destination
withDestinationPath: linkDestination];
} @catch (id e) {
|
︙ | | |
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
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
750
751
752
753
754
755
756
757
|
-
+
-
-
-
-
+
-
-
+
-
-
+
-
|
destinationURL: destination
errNo: EINVAL];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_FILES
- (void)moveItemAtPath: (OFString *)source
- (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination
toPath: (OFString *)destination
{
void *pool = objc_autoreleasePoolPush();
[self moveItemAtURL: [OFURL fileURLWithPath: source]
toURL: [OFURL fileURLWithPath: destination]];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)moveItemAtURL: (OFURL *)source
- (void)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination
toURL: (OFURL *)destination
{
void *pool;
OFURLHandler *URLHandler;
if (source == nil || destination == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil)
@throw [OFUnsupportedProtocolException
exceptionWithURL: source];
@try {
if ([URLHandler moveItemAtURL: source
if ([URLHandler moveItemAtURL: source toURL: destination])
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
[self copyItemAtURL: source toURL: destination];
toURL: destination];
} @catch (OFCopyItemFailedException *e) {
[self removeItemAtURL: destination];
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: e.errNo];
|
︙ | | |
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
|
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
|
-
-
-
+
-
-
+
-
-
+
-
-
-
-
+
-
-
-
|
[URLHandler removeItemAtURL: URL];
}
#ifdef OF_HAVE_FILES
- (void)removeItemAtPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
[self removeItemAtURL: [OFURL fileURLWithPath: path]];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)linkItemAtURL: (OFURL *)source
- (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination
toURL: (OFURL *)destination
{
void *pool = objc_autoreleasePoolPush();
OFURLHandler *URLHandler;
if (source == nil || destination == nil)
@throw [OFInvalidArgumentException exception];
if (![destination.scheme isEqual: source.scheme])
@throw [OFInvalidArgumentException exception];
URLHandler = [OFURLHandler handlerForURL: source];
if (URLHandler == nil)
@throw [OFUnsupportedProtocolException
exceptionWithURL: source];
[URLHandler linkItemAtURL: source
[URLHandler linkItemAtURL: source toURL: destination];
toURL: destination];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
- (void)linkItemAtPath: (OFString *)source
- (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination
toPath: (OFString *)destination
{
void *pool = objc_autoreleasePoolPush();
[self linkItemAtURL: [OFURL fileURLWithPath: source]
toURL: [OFURL fileURLWithPath: destination]];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)createSymbolicLinkAtURL: (OFURL *)URL
withDestinationPath: (OFString *)target
{
void *pool = objc_autoreleasePoolPush();
OFURLHandler *URLHandler;
if (URL == nil || target == nil)
@throw [OFInvalidArgumentException exception];
URLHandler = [OFURLHandler handlerForURL: URL];
if (URLHandler == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
[URLHandler createSymbolicLinkAtURL: URL
[URLHandler createSymbolicLinkAtURL: URL withDestinationPath: target];
withDestinationPath: target];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
- (void)createSymbolicLinkAtPath: (OFString *)path
withDestinationPath: (OFString *)target
{
void *pool = objc_autoreleasePoolPush();
[self createSymbolicLinkAtURL: [OFURL fileURLWithPath: path]
withDestinationPath: target];
objc_autoreleasePoolPop(pool);
}
#endif
@end
@implementation OFDefaultFileManager
- (instancetype)autorelease
|
︙ | | |
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
|
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
|
- (void)release
{
}
- (unsigned int)retainCount
{
return OF_RETAIN_COUNT_MAX;
return OFMaxRetainCount;
}
@end
@implementation OFDictionary (FileAttributes)
- (unsigned long long)fileSize
{
return [attributeForKeyOrException(self, of_file_attribute_key_size)
return [attributeForKeyOrException(self, OFFileSize)
unsignedLongLongValue];
}
- (of_file_type_t)fileType
- (OFFileAttributeType)fileType
{
return attributeForKeyOrException(self, of_file_attribute_key_type);
return attributeForKeyOrException(self, OFFileType);
}
- (unsigned long)filePOSIXPermissions
{
return [attributeForKeyOrException(self,
of_file_attribute_key_posix_permissions) unsignedLongValue];
OFFilePOSIXPermissions) unsignedLongValue];
}
- (unsigned long)filePOSIXUID
- (unsigned long)fileOwnerAccountID
{
return [attributeForKeyOrException(self,
of_file_attribute_key_posix_uid) unsignedLongValue];
OFFileOwnerAccountID) unsignedLongValue];
}
- (unsigned long)filePOSIXGID
- (unsigned long)fileGroupOwnerAccountID
{
return [attributeForKeyOrException(self,
of_file_attribute_key_posix_gid) unsignedLongValue];
OFFileGroupOwnerAccountID) unsignedLongValue];
}
- (OFString *)fileOwner
- (OFString *)fileOwnerAccountName
{
return attributeForKeyOrException(self, of_file_attribute_key_owner);
return attributeForKeyOrException(self, OFFileOwnerAccountName);
}
- (OFString *)fileGroup
- (OFString *)fileGroupOwnerAccountName
{
return attributeForKeyOrException(self, of_file_attribute_key_group);
return attributeForKeyOrException(self, OFFileGroupOwnerAccountName);
}
- (OFDate *)fileLastAccessDate
{
return attributeForKeyOrException(self,
return attributeForKeyOrException(self, OFFileLastAccessDate);
of_file_attribute_key_last_access_date);
}
- (OFDate *)fileModificationDate
{
return attributeForKeyOrException(self,
return attributeForKeyOrException(self, OFFileModificationDate);
of_file_attribute_key_modification_date);
}
- (OFDate *)fileStatusChangeDate
{
return attributeForKeyOrException(self,
return attributeForKeyOrException(self, OFFileStatusChangeDate);
of_file_attribute_key_status_change_date);
}
- (OFDate *)fileCreationDate
{
return attributeForKeyOrException(self,
return attributeForKeyOrException(self, OFFileCreationDate);
of_file_attribute_key_creation_date);
}
- (OFString *)fileSymbolicLinkDestination
{
return attributeForKeyOrException(self,
return attributeForKeyOrException(self, OFFileSymbolicLinkDestination);
of_file_attribute_key_symbolic_link_destination);
}
@end
|