Describe the bug
FileManager claims to support setting .creationDate, but it doesn't.
The implementation of FileManager.replaceItemAt in corelibs-foundation uses this API: https://github.com/swiftlang/swift-corelibs-foundation/blob/f9c1d4eee71957c49eb66fd8fb5dac856d0efbf4/Sources/Foundation/FileManager%2BPOSIX.swift#L479-L491
This missing functionality caused us to comment out a test on swiftlang/swift-corelibs-foundation#5443
To Reproduce
Sample code to reproduce the behavior.
let myDate = Date.now
try FileManager.default.setAttributes([.creationDate : myDate], ofItemAtPath: "mypath.txt")
let attrs = try FileManager.default.attributesOfItem(atPath: "mypath.txt")
assert(attrs[.creationDate] == myDate) // fails
Expected behavior
I expect the attribute to be set or an error to be thrown on platforms where it's not supported. If an error can't be thrown on those platforms due to compatibility, at least some very clear documentation on .creationDate.
Configuration (please complete the following information):
- Swift Version: main
- OS: Ubuntu
- OS Version: noble
Regression information:
If applicable, please list older versions where this issue did not occur.
Additional context
It may not be possible to set creation date on Linux (see context: swiftlang/swift-corelibs-foundation#5443 (comment)) in which case I'd expect either good documentation or an error to be thrown.
The code path seems to end up at this TODO:
|
// Exclude some attributes (like .creationDate) from this check since they are unconditionally, implicitly included in `attributesForItem(atPath:)` results |
|
if attributes.keys.contains(where: { _swiftFoundationUnsupportedKeys.contains($0) }) { |
|
throw CocoaError.errorWithFilePath(.featureUnsupported, path) |
|
} else { |
|
return // TODO: support relevant cat info keys in swift-foundation |
|
} |
Describe the bug
FileManager claims to support setting
.creationDate, but it doesn't.The implementation of
FileManager.replaceItemAtin corelibs-foundation uses this API: https://github.com/swiftlang/swift-corelibs-foundation/blob/f9c1d4eee71957c49eb66fd8fb5dac856d0efbf4/Sources/Foundation/FileManager%2BPOSIX.swift#L479-L491This missing functionality caused us to comment out a test on swiftlang/swift-corelibs-foundation#5443
To Reproduce
Sample code to reproduce the behavior.
Expected behavior
I expect the attribute to be set or an error to be thrown on platforms where it's not supported. If an error can't be thrown on those platforms due to compatibility, at least some very clear documentation on
.creationDate.Configuration (please complete the following information):
Regression information:
If applicable, please list older versions where this issue did not occur.
Additional context
It may not be possible to set creation date on Linux (see context: swiftlang/swift-corelibs-foundation#5443 (comment)) in which case I'd expect either good documentation or an error to be thrown.
The code path seems to end up at this TODO:
swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift
Lines 133 to 138 in b460a1f