setAttributes(_:on:context:replyHandler:)
Sets the given attributes on an item.
Declaration
func setAttributes(_ newAttributes: FSItem.SetAttributesRequest, on item: FSItem, context: FSContext, replyHandler reply: @escaping @Sendable (FSSetAttributesResult?, (any Error)?) -> Void)func setAttributes(_ newAttributes: FSItem.SetAttributesRequest, on item: FSItem, context: FSContext) async throws -> FSSetAttributesResultParameters
- newAttributes:
A request containing the attributes to set.
- item:
The item on which to set the attributes.
- context:
An object that enables context-aware file system decisions throughout the operation.
- reply:
A block or closure to indicate success or failure. If setting attributes succeeds, pass an instance of Fssetattributesresult containing the item’s updated attributes and the volume’s updated free space, along with a
nilerror. If setting attributes fails, pass the relevant error as the second parameter; FSKit ignores the Fssetattributesresult instance in this case. For anasyncSwift implementation, there’s no reply handler; simply return the result instance or throw an error.
Discussion
Several attributes are considered “read-only”, and an attempt to set these attributes results in an error with the code EINVAL.
A request may set size beyond the end of the file. If the underlying file system doesn’t support sparse files, allocate space to fill the new file size. Either fill this space with zeroes, or configure it to read as zeroes.
If a request sets the file size below the current end-of-file, truncate the file and return any unused space to the file system as free space.
Ignore attempts to set the size of directories or symbolic links; don’t produce an error.
If the caller attempts to set an attribute not supported by the on-disk file system format, don’t produce an error. The upper layers of the framework will detect this situation.