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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
|
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
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
|
+
-
-
-
+
+
+
+
-
+
+
-
-
+
+
+
-
+
-
-
-
-
+
-
+
-
-
+
+
-
+
-
-
-
-
+
-
+
-
+
+
+
+
-
+
-
+
+
+
+
-
+
+
-
+
|
#endif
objc_autoreleasePoolPop(pool);
return ret;
}
- (void)of_setLastAccessDate: (OFDate *)lastAccessDate
- (void)of_setModificationDate: (OFDate *)date
ofItemAtURL: (OFURL *)URL
attributes: (of_file_attributes_t)attributes
andModificationDate: (OFDate *)modificationDate
ofItemAtURL: (OFURL *)URL
attributeKey: (of_file_attribute_key_t)attributeKey
attributes: (of_file_attributes_t)attributes
{
of_time_interval_t timeInterval = date.timeIntervalSince1970;
OFString *path = URL.fileSystemRepresentation;
#ifdef OF_WINDOWS
if (func__wutime64 != NULL) {
struct __utimbuf64 times = {
.actime =
(__time64_t)timeInterval,
(__time64_t)timeInterval
(__time64_t)lastAccessDate.timeIntervalSince1970,
.modtime =
(__time64_t)modificationDate.timeIntervalSince1970
};
if (func__wutime64([path UTF16String], ×) != 0) {
if (func__wutime64([path UTF16String], ×) != 0)
of_file_attribute_key_t failedAttribute =
of_file_attribute_key_modification_date;
@throw [OFSetItemAttributesFailedException
exceptionWithURL: URL
attributes: attributes
failedAttribute: failedAttribute
failedAttribute: attributeKey
errNo: errno];
}
} else {
struct _utimbuf times = {
.actime = (time_t)lastAccessDate.timeIntervalSince1970,
(time_t)timeInterval,
(time_t)timeInterval
.modtime =
(time_t)modificationDate.timeIntervalSince1970
};
int status;
if ([OFSystemInfo isWindowsNT])
status = _wutime([path UTF16String], ×);
else
status = _utime(
[path cStringWithEncoding: [OFLocale encoding]],
×);
if (status != 0) {
if (status != 0)
of_file_attribute_key_t failedAttribute =
of_file_attribute_key_modification_date;
@throw [OFSetItemAttributesFailedException
exceptionWithURL: URL
attributes: attributes
failedAttribute: failedAttribute
failedAttribute: attributeKey
errNo: errno];
}
}
}
#else
of_time_interval_t lastAccessTime =
lastAccessDate.timeIntervalSince1970;
of_time_interval_t modificationTime =
modificationDate.timeIntervalSince1970;
struct timeval times[2] = {
{
.tv_sec = (time_t)timeInterval,
.tv_sec = (time_t)lastAccessTime,
.tv_usec =
(int)((timeInterval - times[0].tv_sec) * 1000)
(int)((lastAccessTime - times[0].tv_sec) * 1000)
},
{
.tv_sec = (time_t)modificationTime,
.tv_usec =
times[0]
(int)((modificationTime - times[1].tv_sec) * 1000)
},
};
if (utimes([path cStringWithEncoding: [OFLocale encoding]], times) != 0)
@throw [OFSetItemAttributesFailedException
exceptionWithURL: URL
attributes: attributes
failedAttribute: of_file_attribute_key_modification_date
failedAttribute: attributeKey
errNo: errno];
#endif
}
- (void)of_setPOSIXPermissions: (OFNumber *)permissions
ofItemAtURL: (OFURL *)URL
attributes: (of_file_attributes_t)attributes
|
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
|
777
778
779
780
781
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
|
+
-
+
-
-
-
+
+
|
ofItemAtURL: (OFURL *)URL
{
void *pool = objc_autoreleasePoolPush();
OFEnumerator OF_GENERIC(of_file_attribute_key_t) *keyEnumerator;
OFEnumerator *objectEnumerator;
of_file_attribute_key_t key;
id object;
OFDate *lastAccessDate, *modificationDate;
if (URL == nil)
@throw [OFInvalidArgumentException exception];
if (![URL.scheme isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
keyEnumerator = [attributes keyEnumerator];
objectEnumerator = [attributes objectEnumerator];
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil) {
if ([key isEqual: of_file_attribute_key_modification_date])
if ([key isEqual: of_file_attribute_key_modification_date] ||
[self of_setModificationDate: object
ofItemAtURL: URL
attributes: attributes];
[key isEqual: of_file_attribute_key_last_access_date])
continue;
else if ([key isEqual: of_file_attribute_key_posix_permissions])
[self of_setPOSIXPermissions: object
ofItemAtURL: URL
attributes: attributes];
else if ([key isEqual: of_file_attribute_key_owner])
[self of_setOwner: object
andGroup: nil
|
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
attributeKey: key
attributes: attributes];
else
@throw [OFNotImplementedException
exceptionWithSelector: _cmd
object: self];
}
lastAccessDate = [attributes
objectForKey: of_file_attribute_key_last_access_date];
modificationDate = [attributes
objectForKey: of_file_attribute_key_modification_date];
if (lastAccessDate != nil || modificationDate != nil) {
of_file_attribute_key_t attributeKey;
if (modificationDate != nil)
attributeKey = of_file_attribute_key_modification_date;
else
attributeKey = of_file_attribute_key_last_access_date;
if (lastAccessDate == nil)
lastAccessDate = modificationDate;
if (modificationDate == nil)
modificationDate = lastAccessDate;
[self of_setLastAccessDate: lastAccessDate
andModificationDate: modificationDate
ofItemAtURL: URL
attributeKey: attributeKey
attributes: attributes];
}
objc_autoreleasePoolPop(pool);
}
- (bool)fileExistsAtURL: (OFURL *)URL
{
void *pool = objc_autoreleasePoolPush();
|