ObjFW  Check-in [c88d1d3054]

Overview
Comment:Add support for typed extended attributes on Haiku
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c88d1d30542bcf5905dc8197c768c5242124178262ed91470f43acb503c7f739
User & Date: js on 2024-04-03 17:50:01
Other Links: manifest | tags
Context
2024-04-03
20:51
OFFileIRIHandler: Fix missing retain + autorelease check-in: 98e5c7dd28 user: js tags: trunk
17:50
Add support for typed extended attributes on Haiku check-in: c88d1d3054 user: js tags: trunk
02:37
Update README.md for the license change check-in: 06aecbe734 user: js tags: trunk
Changes

Modified src/OFFileIRIHandler.m from [218769cb2b] to [112ff9e77e].

36
37
38
39
40
41
42

43
44
45
46
47
48
49
# include <sys/stat.h>
#endif
#include <sys/time.h>
#if defined(OF_LINUX) || defined(OF_MACOS)
# include <sys/xattr.h>
#endif
#ifdef OF_HAIKU

# include <kernel/fs_attr.h>
#endif
#ifdef OF_WINDOWS
# include <utime.h>
#endif
#ifdef OF_DJGPP
# include <syslimits.h>







>







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# include <sys/stat.h>
#endif
#include <sys/time.h>
#if defined(OF_LINUX) || defined(OF_MACOS)
# include <sys/xattr.h>
#endif
#ifdef OF_HAIKU
# include <ctype.h>
# include <kernel/fs_attr.h>
#endif
#ifdef OF_WINDOWS
# include <utime.h>
#endif
#ifdef OF_DJGPP
# include <syslimits.h>
1611
1612
1613
1614
1615
1616
1617


1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634

	objc_autoreleasePoolPop(pool);

	return true;
}

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES


- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path = IRI.fileSystemRepresentation;
	OFStringEncoding encoding = [OFLocale encoding];
	const char *cPath = [path cStringWithEncoding: encoding];
	const char *cName = [name cStringWithEncoding: encoding];
	void *value = NULL;
	OFData *data;
# if defined(OF_LINUX) || defined(OF_MACOS)
#  if defined(OF_LINUX)
	ssize_t size = lgetxattr(cPath, cName, NULL, 0);
#  elif defined(OF_MACOS)
	ssize_t size = getxattr(cPath, cName, NULL, 0, 0, XATTR_NOFOLLOW);
#  endif








>
>
|
|







<







1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629

1630
1631
1632
1633
1634
1635
1636

	objc_autoreleasePoolPop(pool);

	return true;
}

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
- (void)getExtendedAttributeData: (OFData **)data
			 andType: (id *)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path = IRI.fileSystemRepresentation;
	OFStringEncoding encoding = [OFLocale encoding];
	const char *cPath = [path cStringWithEncoding: encoding];
	const char *cName = [name cStringWithEncoding: encoding];
	void *value = NULL;

# if defined(OF_LINUX) || defined(OF_MACOS)
#  if defined(OF_LINUX)
	ssize_t size = lgetxattr(cPath, cName, NULL, 0);
#  elif defined(OF_MACOS)
	ssize_t size = getxattr(cPath, cName, NULL, 0, 0, XATTR_NOFOLLOW);
#  endif

1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658



1659
1660
1661
1662
1663
1664
1665
		if ((size = getxattr(cPath, cName, value, size, 0,
		    XATTR_NOFOLLOW)) < 0)
#  endif
			@throw [OFGetItemAttributesFailedException
			    exceptionWithIRI: IRI
				       errNo: errno];

		data = [OFData dataWithItemsNoCopy: value
					     count: size
				      freeWhenDone: true];
		value = NULL;
	} @finally {
		OFFreeMemory(value);
	}



# elif defined(OF_HAIKU)
	int fd = open(cPath, O_RDONLY);
	struct attr_info info;

	if (fd == -1)
		@throw [OFGetItemAttributesFailedException
		    exceptionWithIRI: IRI







|
|
|




>
>
>







1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
		if ((size = getxattr(cPath, cName, value, size, 0,
		    XATTR_NOFOLLOW)) < 0)
#  endif
			@throw [OFGetItemAttributesFailedException
			    exceptionWithIRI: IRI
				       errNo: errno];

		*data = [OFData dataWithItemsNoCopy: value
					      count: size
				       freeWhenDone: true];
		value = NULL;
	} @finally {
		OFFreeMemory(value);
	}

	if (type != NULL)
		*type = nil;
# elif defined(OF_HAIKU)
	int fd = open(cPath, O_RDONLY);
	struct attr_info info;

	if (fd == -1)
		@throw [OFGetItemAttributesFailedException
		    exceptionWithIRI: IRI
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689



1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703

1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714




1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729

1730







1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
		errno = 0;
		if (fs_read_attr(fd, cName, B_ANY_TYPE, 0, value,
		    (size_t)info.size) != (ssize_t)info.size)
			@throw [OFGetItemAttributesFailedException
			    exceptionWithIRI: IRI
				       errNo: errno];

		data = [OFData dataWithItemsNoCopy: value
					     count: (size_t)info.size
				      freeWhenDone: true];
		value = NULL;



	} @finally {
		OFFreeMemory(value);
		close(fd);
	}
# endif

	[data retain];

	objc_autoreleasePoolPop(pool);

	return [data autorelease];
}

- (void)setExtendedAttributeData: (OFData *)data

			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path = IRI.fileSystemRepresentation;
	OFStringEncoding encoding = [OFLocale encoding];
	const char *cPath = [path cStringWithEncoding: encoding];
	const char *cName = [name cStringWithEncoding: encoding];
	size_t size = data.count * data.itemSize;

# if defined(OF_LINUX) || defined(OF_MACOS)




#  if defined(OF_LINUX)
	if (lsetxattr(cPath, cName, data.items, size, 0) != 0) {
#  elif defined(OF_MACOS)
	if (setxattr(cPath, cName, data.items, size, 0, XATTR_NOFOLLOW) != 0) {
#  endif
		int errNo = errno;

		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_HAIKU)

	int fd;








	if (size > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if ((fd = open(cPath, O_WRONLY)) == -1) {
		int errNo = errno;

		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}

	@try {
		if (fs_write_attr(fd, cName, B_RAW_TYPE, 0, data.items, size) !=
		    (ssize_t)size) {
			int errNo = errno;

			/*
			 * TODO: Add an attribute (prefix?) for extended
			 *	 attributes?
			 */
			@throw [OFSetItemAttributesFailedException







|
|
|

>
>
>






|


<
<



>











>
>
>
>















>

>
>
>
>
>
>
>
















|
|







1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706


1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
		errno = 0;
		if (fs_read_attr(fd, cName, B_ANY_TYPE, 0, value,
		    (size_t)info.size) != (ssize_t)info.size)
			@throw [OFGetItemAttributesFailedException
			    exceptionWithIRI: IRI
				       errNo: errno];

		*data = [OFData dataWithItemsNoCopy: value
					      count: (size_t)info.size
				       freeWhenDone: true];
		value = NULL;

		if (type != NULL)
			*type = [OFNumber numberWithUnsignedLong: info.type];
	} @finally {
		OFFreeMemory(value);
		close(fd);
	}
# endif

	[*data retain];

	objc_autoreleasePoolPop(pool);


}

- (void)setExtendedAttributeData: (OFData *)data
			 andType: (id)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path = IRI.fileSystemRepresentation;
	OFStringEncoding encoding = [OFLocale encoding];
	const char *cPath = [path cStringWithEncoding: encoding];
	const char *cName = [name cStringWithEncoding: encoding];
	size_t size = data.count * data.itemSize;

# if defined(OF_LINUX) || defined(OF_MACOS)
	if (type != nil)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
								 object: self];

#  if defined(OF_LINUX)
	if (lsetxattr(cPath, cName, data.items, size, 0) != 0) {
#  elif defined(OF_MACOS)
	if (setxattr(cPath, cName, data.items, size, 0, XATTR_NOFOLLOW) != 0) {
#  endif
		int errNo = errno;

		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_HAIKU)
	unsigned long long typeInt;
	int fd;

	if (type != nil && ![type isKindOfClass: [OFNumber class]])
		@throw [OFInvalidArgumentException exception];

	typeInt = (type != nil ? [type unsignedLongLongValue] : 0);
	if (typeInt > UINT32_MAX)
		@throw [OFInvalidArgumentException exception];

	if (size > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if ((fd = open(cPath, O_WRONLY)) == -1) {
		int errNo = errno;

		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}

	@try {
		if (fs_write_attr(fd, cName, (uint32_t)typeInt, 0,
		    data.items, size) != (ssize_t)size) {
			int errNo = errno;

			/*
			 * TODO: Add an attribute (prefix?) for extended
			 *	 attributes?
			 */
			@throw [OFSetItemAttributesFailedException

Modified src/OFFileManager.h from [d993a52986] to [d46ba4ebbc].

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
750
751
752
 * @brief Returns the extended attribute data for the specified name of the
 *	  item at the specified path.
 *
 * This method is not available on some systems.
 *
 * @param name The name of the extended attribute
 * @param path The path of the item to return the extended attribute from


 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (OFData *)extendedAttributeDataForName: (OFString *)name
			    ofItemAtPath: (OFString *)path;
























#endif

/**
 * @brief Returns the extended attribute data for the specified name of the
 *	  item at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to return the extended attribute from


 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException No handler is registered for the IRI's
 *					 scheme
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI;



























#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified path.
 *
 * This method is not available on some systems.
 *
 * @param data The data for the extended attribute
 * @param name The name of the extended attribute
 * @param path The path of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item
 */
- (void)setExtendedAttributeData: (OFData *)data
























			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path;
#endif

/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified IRI.







>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










>
>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
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
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
 * @brief Returns the extended attribute data for the specified name of the
 *	  item at the specified path.
 *
 * This method is not available on some systems.
 *
 * @param name The name of the extended attribute
 * @param path The path of the item to return the extended attribute from
 * @return The extended attribute data for the specified name of the item at
 *	   the specified IRI
 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (OFData *)extendedAttributeDataForName: (OFString *)name
			    ofItemAtPath: (OFString *)path;

/**
 * @brief Gets the extended attribute data and type for the specified name
 *	  of the item at the specified path.
 *
 * This method is not available on some systems.
 *
 * @param data A pointer to `OFData *` that gets set to the data of the
 *	       extended attribute
 * @param type A pointer to `id` that gets set to the type of the extended
 *	       attribute, if not `NULL`. Gets set to `nil` if the extended
 *	       attribute has no type. The type of the type depends on the
 *	       system.
 * @param name The name of the extended attribute
 * @param path The path of the item to return the extended attribute from
 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
			 andType: (id _Nullable *_Nullable)type
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path;
#endif

/**
 * @brief Returns the extended attribute data for the specified name of the
 *	  item at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to return the extended attribute from
 * @return The extended attribute data for the specified name of the item at
 *	   the specified IRI
 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException No handler is registered for the IRI's
 *					 scheme
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI;

/**
 * @brief Gets the extended attribute data and type for the specified name
 *	  of the item at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param data A pointer to `OFData *` that gets set to the data of the
 *	       extended attribute
 * @param type A pointer to `id` that gets set to the type of the extended
 *	       attribute, if not `NULL`. Gets set to `nil` if the extended
 *	       attribute has no type. The type of the type depends on the IRI
 *	       handler.
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to return the extended attribute from
 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException No handler is registered for the IRI's
 *					 scheme
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
			 andType: (id _Nullable *_Nullable)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified path.
 *
 * This method is not available on some systems.
 *
 * @param data The data for the extended attribute
 * @param name The name of the extended attribute
 * @param path The path of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item
 */
- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path;

/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified path.
 *
 * This method is not available on some systems.
 *
 * @param data The data for the extended attribute
 * @param type The type for the extended attribute. `nil` does not mean to keep
 *	       the existing type, but to set it to no type. The type of the
 *	       type depends on the system.
 * @param name The name of the extended attribute
 * @param path The path of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item or a
 *				    type was specified and typed extended
 *				    attributes are not supported
 */
- (void)setExtendedAttributeData: (OFData *)data
			 andType: (nullable id)type
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path;
#endif

/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified IRI.
760
761
762
763
764
765
766


























767
768
769
770
771
772
773
 *					     failed
 * @throw OFUnsupportedProtocolException No handler is registered for the IRI's
 *					 scheme
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item
 */
- (void)setExtendedAttributeData: (OFData *)data


























			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
/**
 * @brief Removes the extended attribute for the specified name of the item at
 *	  the specified path.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
 *					     failed
 * @throw OFUnsupportedProtocolException No handler is registered for the IRI's
 *					 scheme
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item
 */
- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param data The data for the extended attribute
 * @param type The type for the extended attribute. `nil` does not mean to keep
 *	       the existing type, but to set it to no type. The type of the
 *	       type depends on the IRI handler.
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException No handler is registered for the IRI's
 *					 scheme
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item or a
 *				    type was specified and typed extended
 *				    attributes are not supported
 */
- (void)setExtendedAttributeData: (OFData *)data
			 andType: (nullable id)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
/**
 * @brief Removes the extended attribute for the specified name of the item at
 *	  the specified path.

Modified src/OFFileManager.m from [48b993c33e] to [fee3c0b404].

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











973
974
975
976
977
978
979
980
981
982
983
984

985
986
987
988
989
990
991
992
993











994

995

996
997
998

999
1000
1001
1002
1003
1004
1005
	objc_autoreleasePoolPop(pool);
}
#endif

- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI
{
















	OFIRIHandler *IRIHandler;

	if (IRI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithIRI: IRI];




	return [IRIHandler extendedAttributeDataForName: name ofItemAtIRI: IRI];










}

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
- (OFData *)extendedAttributeDataForName: (OFString *)name
			    ofItemAtPath: (OFString *)path
{















	void *pool = objc_autoreleasePoolPush();
	OFData *ret;

	ret = [self

	    extendedAttributeDataForName: name
			     ofItemAtIRI: [OFIRI fileIRIWithPath: path
						     isDirectory: false]];

	ret = [ret retain];



	objc_autoreleasePoolPop(pool);

	return [ret autorelease];


}
#endif

- (void)setExtendedAttributeData: (OFData *)data











			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	OFIRIHandler *IRIHandler;

	if (IRI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithIRI: IRI];

	[IRIHandler setExtendedAttributeData: data

				     forName: name
				 ofItemAtIRI: IRI];
}

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path
{











	void *pool = objc_autoreleasePoolPush();

	[self setExtendedAttributeData: data

			       forName: name
			   ofItemAtIRI: [OFIRI fileIRIWithPath: path
						   isDirectory: false]];

	objc_autoreleasePoolPop(pool);
}
#endif

- (void)removeExtendedAttributeForName: (OFString *)name
			   ofItemAtIRI: (OFIRI *)IRI
{







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
|
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<

|
>
|
|
|
>
|
>
>



|
>
>




>
>
>
>
>
>
>
>
>
>
>












>









>
>
>
>
>
>
>
>
>
>
>

>

>



>







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
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
	objc_autoreleasePoolPop(pool);
}
#endif

- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI
{
	OFData *data;

	[self getExtendedAttributeData: &data
			       andType: NULL
			       forName: name
			   ofItemAtIRI: IRI];

	return data;
}

- (void)getExtendedAttributeData: (OFData **)data
			 andType: (id *)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	void *pool = objc_autoreleasePoolPush();
	OFIRIHandler *IRIHandler;

	if (IRI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithIRI: IRI];

	[IRIHandler getExtendedAttributeData: data
				     andType: type
				     forName: name
				 ofItemAtIRI: IRI];

	[*data retain];
	if (type != NULL)
		[*type retain];

	objc_autoreleasePoolPop(pool);

	[*data autorelease];
	if (type != NULL)
		[*type autorelease];
}

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
- (OFData *)extendedAttributeDataForName: (OFString *)name
			    ofItemAtPath: (OFString *)path
{
	OFData *data;

	[self getExtendedAttributeData: &data
			       andType: NULL
			       forName: name
			  ofItemAtPath: path];

	return data;
}

- (void)getExtendedAttributeData: (OFData **)data
			 andType: (id *)type
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();


	[self getExtendedAttributeData: data
			       andType: type
			       forName: name
			   ofItemAtIRI: [OFIRI fileIRIWithPath: path
						   isDirectory: false]];

	[*data retain];
	if (type != NULL)
		[*type retain];

	objc_autoreleasePoolPop(pool);

	[*data autorelease];
	if (type != NULL)
		[*type autorelease];
}
#endif

- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	[self setExtendedAttributeData: data
			       andType: nil
			       forName: name
			   ofItemAtIRI: IRI];
}

- (void)setExtendedAttributeData: (OFData *)data
			 andType: (id)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	OFIRIHandler *IRIHandler;

	if (IRI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((IRIHandler = [OFIRIHandler handlerForIRI: IRI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithIRI: IRI];

	[IRIHandler setExtendedAttributeData: data
				     andType: type
				     forName: name
				 ofItemAtIRI: IRI];
}

#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path
{
	[self setExtendedAttributeData: data
			       andType: nil
			       forName: name
			  ofItemAtPath: path];
}

- (void)setExtendedAttributeData: (OFData *)data
			 andType: (id)type
			 forName: (OFString *)name
		    ofItemAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();

	[self setExtendedAttributeData: data
			       andType: type
			       forName: name
			   ofItemAtIRI: [OFIRI fileIRIWithPath: path
						   isDirectory: false]];

	objc_autoreleasePoolPop(pool);
}
#endif

- (void)removeExtendedAttributeForName: (OFString *)name
			   ofItemAtIRI: (OFIRI *)IRI
{

Modified src/OFIRIHandler.h from [8a510068dc] to [d079d12198].

301
302
303
304
305
306
307


308
309
310
311
312
313
314
315




























316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334





























335
336
337
338
339
340
341
 * @brief Returns the extended attribute data for the specified name of the
 *	  item at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to return the extended attribute from


 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's
 *					 scheme
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (OFData *)extendedAttributeDataForName: (OFString *)name




























			     ofItemAtIRI: (OFIRI *)IRI;

/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param data The data for the extended attribute
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's
 *					 scheme
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item
 */
- (void)setExtendedAttributeData: (OFData *)data





























			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

/**
 * @brief Removes the extended attribute for the specified name of the item at
 *	  the specified IRI.
 *







>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
 * @brief Returns the extended attribute data for the specified name of the
 *	  item at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to return the extended attribute from
 * @return The extended attribute data for the specified name of the item at
 *	   the specified IRI
 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's
 *					 scheme
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI
   OF_DEPRECATED(ObjFW, 1, 1,
   "Use -[getExtendedAttributeData:andType:forName:ofItemAtIRI:] instead");

/**
 * @brief Gets the extended attribute data and type for the specified name
 *	  of the item at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param data A pointer to `OFData *` that gets set to the data of the
 *	       extended attribute
 * @param type A pointer to `id` that gets set to the type of the extended
 *	       attribute, if not `NULL`. Gets set to `nil` if the extended
 *	       attribute has no type. The type of the type depends on the IRI
 *	       handler.
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to return the extended attribute from
 * @throw OFGetItemAttributesFailedException Getting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's
 *					 scheme
 * @throw OFNotImplementedException Getting extended attributes is not
 *				    implemented for the specified item
 */
- (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
			 andType: (id _Nullable *_Nullable)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

/**
 * @brief Sets the extended attribute data for the specified name of the item
 *	  at the specified IRI.
 *
 * This method is not available for all IRIs.
 *
 * @param data The data for the extended attribute
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's
 *					 scheme
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item
 */
- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
    OF_DEPRECATED(ObjFW, 1, 1,
    "Use -[setExtendedAttributeData:andType:forName:ofItemAtIRI:] instead");

/**
 * @brief Sets the extended attribute data and type for the specified name of
 *	  the item at the specified IRI.
 *
 * This method is not available for all IRIs.
 * Not all IRIs support a non-nil type.
 *
 * @param data The data for the extended attribute
 * @param type The type for the extended attribute. `nil` does not mean to keep
 *	       the existing type, but to set it to no type. The type of the
 *	       type depends on the IRI handler.
 * @param name The name of the extended attribute
 * @param IRI The IRI of the item to set the extended attribute on
 * @throw OFSetItemAttributesFailedException Setting the extended attribute
 *					     failed
 * @throw OFUnsupportedProtocolException The handler cannot handle the IRI's
 *					 scheme
 * @throw OFNotImplementedException Setting extended attributes is not
 *				    implemented for the specified item or a
 *				    type was specified and typed extended
 *				    attributes are not supported
 */
- (void)setExtendedAttributeData: (OFData *)data
			 andType: (nullable id)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI;

/**
 * @brief Removes the extended attribute for the specified name of the item at
 *	  the specified IRI.
 *

Modified src/OFIRIHandler.m from [a371e30c0d] to [55f4357182].

218
219
220
221
222
223
224









































225
226
227
228
229
230
231










































232
233
234
235
236
237
238
{
	return false;
}

- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI
{









































	OF_UNRECOGNIZED_SELECTOR
}

- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{










































	OF_UNRECOGNIZED_SELECTOR
}

- (void)removeExtendedAttributeForName: (OFString *)name
			   ofItemAtIRI: (OFIRI *)IRI
{
	OF_UNRECOGNIZED_SELECTOR







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
{
	return false;
}

- (OFData *)extendedAttributeDataForName: (OFString *)name
			     ofItemAtIRI: (OFIRI *)IRI
{
	OFData *data;

	[self getExtendedAttributeData: &data
			       andType: NULL
			       forName: name
			   ofItemAtIRI: IRI];

	return data;
}

- (void)getExtendedAttributeData: (OFData **)data
			 andType: (id *)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	/*
	 * Only call into -[extendedAttributeDataForName:ofItemAtIRI:] if it
	 * has been overridden. This is to be backwards-compatible to
	 * subclasses that predate the introduction of
	 * -[getExtendedAttributeData:andType:forName:ofItemAtIRI:].
	 * Without this check, this would result in an infinite loop.
	 */
	SEL selector = @selector(extendedAttributeDataForName:ofItemAtIRI:);

	if (class_getMethodImplementation(object_getClass(self), selector) !=
	    class_getMethodImplementation([OFIRIHandler class], selector)) {
		/*
		 * Use -[performSelector:withObject:withObject:] to avoid
		 * deprecation warning. This entire thing is purely for
		 * backwards compatibility.
		 */
		*data = [self performSelector: selector
				   withObject: name
				   withObject: IRI];
	
		if (type != NULL)
			*type = nil;

		return;
	}

	OF_UNRECOGNIZED_SELECTOR
}

- (void)setExtendedAttributeData: (OFData *)data
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{
	[self setExtendedAttributeData: data
			       andType: nil
			       forName: name
			   ofItemAtIRI: IRI];
}

- (void)setExtendedAttributeData: (OFData *)data
			 andType: (id)type
			 forName: (OFString *)name
		     ofItemAtIRI: (OFIRI *)IRI
{

	if (type == nil) {
		/*
		 * Only call into
		 * -[setExtendedAttributeData:forName:ofItemAtIRI:] if it has
		 * been overridden. This is to be backwards-compatible to
		 * subclasses that predate the introduction of
		 * -[setExtendedAttributeData:andType:forName:ofItemAtIRI:].
		 * Without this check, this would result in an infinite loop.
		 */
		SEL selector =
		    @selector(setExtendedAttributeData:forName:ofItemAtIRI:);

		if (class_getMethodImplementation(object_getClass(self),
		    selector) !=
		    class_getMethodImplementation([OFIRIHandler class],
		    selector)) {
			/*
			 * Use
			 * -[performSelector:withObject:withObject:withObject:]
			 * to avoid deprecation warning. This entire thing is
			 * purely for backwards compatibility.
			 */
			[self performSelector: selector
				   withObject: data
				   withObject: name
				   withObject: IRI];
			return;
		}
	}

	OF_UNRECOGNIZED_SELECTOR
}

- (void)removeExtendedAttributeForName: (OFString *)name
			   ofItemAtIRI: (OFIRI *)IRI
{
	OF_UNRECOGNIZED_SELECTOR

Modified tests/OFFileManagerTests.m from [d49ed79a95] to [b78b36e860].

398
399
400
401
402
403
404
















































405
	OTAssertFalse([extendedAttributeNames containsObject: @"user.test"]);
	OTAssertThrowsSpecific(
	    [_fileManager extendedAttributeDataForName: @"user.test"
					  ofItemAtPath: testFilePath],
	    OFGetItemAttributesFailedException);
}
#endif
















































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
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
	OTAssertFalse([extendedAttributeNames containsObject: @"user.test"]);
	OTAssertThrowsSpecific(
	    [_fileManager extendedAttributeDataForName: @"user.test"
					  ofItemAtPath: testFilePath],
	    OFGetItemAttributesFailedException);
}
#endif

#ifdef OF_HAIKU
- (void)testGetExtendedAttributeDataAndTypeForNameOfItemAtPath
{
	OFData *data;
	id type;

	[_fileManager getExtendedAttributeData: &data
				       andType: &type
				       forName: @"BEOS:TYPE"
				  ofItemAtPath: @"/boot/system/lib/libbe.so"];
	OTAssertEqualObjects(type,
	    [OFNumber numberWithUnsignedLong: B_MIME_STRING_TYPE]);
	OTAssertEqualObjects(data,
	    [OFData dataWithItems: "application/x-vnd.Be-elfexecutable"
			    count: 35]);
}

- (void)testSetExtendedAttributeDataAndTypeForNameOfItemAtPath
{
	OFString *testFilePath = _testFileIRI.fileSystemRepresentation;
	OFData *data, *expectedData = [OFData dataWithItems: "foobar" count: 6];
	id type, expectedType = [OFNumber numberWithUnsignedLong: 1234];

	[_fileManager setExtendedAttributeData: expectedData
				       andType: expectedType
				       forName: @"testattribute"
				  ofItemAtPath: testFilePath];

	[_fileManager getExtendedAttributeData: &data
				       andType: &type
				       forName: @"testattribute"
				  ofItemAtPath: testFilePath];

	OTAssertEqualObjects(data, expectedData);
	OTAssertEqualObjects(type, expectedType);

	[_fileManager removeExtendedAttributeForName: @"testattribute"
					ofItemAtPath: testFilePath];

	OTAssertThrowsSpecific(
	    [_fileManager getExtendedAttributeData: &data
					   andType: &type
					   forName: @"testattribute"
				      ofItemAtPath: testFilePath],
	    OFGetItemAttributesFailedException);
}
#endif
@end