Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/System/Internals/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,9 @@ internal var _S_IFLNK: mode_t { S_IFLNK }
internal var _S_IFSOCK: mode_t { S_IFSOCK }

#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD)
// `S_IFWHT` is `Int32` on FreeBSD.
@_alwaysEmitIntoClient
internal var _S_IFWHT: mode_t { S_IFWHT }
internal var _S_IFWHT: mode_t { .init(S_IFWHT) }
#endif

// MARK: - stat/chflags File Flags
Expand Down
21 changes: 10 additions & 11 deletions Tests/SystemTests/StatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private struct StatTests {
#expect(targetStat.type == .regular)
#expect(symlinkStat.type == .symbolicLink)
#expect(symlinkStat.size < targetStat.size)
#expect(symlinkStat.sizeAllocated < targetStat.sizeAllocated)
#expect(symlinkStat.sizeAllocated <= targetStat.sizeAllocated)

// Set each .st_atim back to its original value for comparison

Expand Down Expand Up @@ -368,14 +368,11 @@ private struct StatTests {
]
#elseif os(FreeBSD)
let userSettableFlags: FileFlags = [
.noDump, .userImmutable, .userAppend,
.opaque, .tracked, .hidden,
.userNoUnlink,
.offline,
.readOnly,
.reparse,
.sparse,
.system
.noDump, .hidden, .offline,
.readOnly, .sparse, .system
// The following flags throw EPERM on ZFS.
// .userImmutable, .userAppend, .opaque,
// .userNoUnlink, .reparse,
]
#else // os(OpenBSD)
let userSettableFlags: FileFlags = [
Expand All @@ -384,13 +381,15 @@ private struct StatTests {
#endif

flags.insert(userSettableFlags)
try #require(fchflags(fd.rawValue, flags.rawValue) == 0, "\(Errno.current)")
// On FreeBSD, the second argument of `fchflags` requires `UInt` instead of`UInt32`.
try #require(fchflags(fd.rawValue, .init(flags.rawValue)) == 0, "\(Errno.current)")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the fullness of time, the right solution will be to have a proper wrapper of chflags and fchflags that take a FileFlags parameter. This is good in the meantime.


stat = try fd.stat()
#expect(stat.flags == flags)

flags.remove(userSettableFlags)
try #require(fchflags(fd.rawValue, flags.rawValue) == 0, "\(Errno.current)")
// On FreeBSD, the second argument of `fchflags` requires `UInt` instead of`UInt32`.
try #require(fchflags(fd.rawValue, .init(flags.rawValue)) == 0, "\(Errno.current)")

stat = try fd.stat()
#expect(stat.flags == flags)
Expand Down