Skip to content

Commit 27439d1

Browse files
authored
(130669494) Only provide .busy file attribute when true (#759)
1 parent 6872bbe commit 27439d1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ extension _FileManagerImpl {
9898
attributes[.hfsCreatorCode] = _writeFileAttributePrimitive(kSymLinkCreator, as: UInt.self)
9999
attributes[.hfsTypeCode] = _writeFileAttributePrimitive(kSymLinkFileType, as: UInt.self)
100100
}
101-
attributes[.busy] = _writeFileAttributePrimitive((finderInfo.extendedFileInfo.extended_flags & 0x80 /*kExtendedFlagObjectIsBusy*/) != 0)
101+
// To preserve historical behavior, only set this attribute if the value is true
102+
let isBusy = (finderInfo.extendedFileInfo.extended_flags & 0x80 /*kExtendedFlagObjectIsBusy*/) != 0
103+
if isBusy {
104+
attributes[.busy] = _writeFileAttributePrimitive(true)
105+
}
102106
}
103107
#endif
104108

Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ final class FileManagerTests : XCTestCase {
642642
XCTAssertEqual(result[.immutable] as? Bool, test.immutable, "Item at path '\(test.path)' did not provide expected result for immutable key")
643643
XCTAssertEqual(result[.appendOnly] as? Bool, test.appendOnly, "Item at path '\(test.path)' did not provide expected result for appendOnly key")
644644

645+
XCTAssertNil(result[.busy], "Item at path '\(test.path)' has non-nil value for .busy attribute") // Should only be set when true
646+
645647
// Manually clean up attributes so removal does not fail
646648
try $0.setAttributes([.immutable: false, .appendOnly: false], ofItemAtPath: test.path)
647649
}

0 commit comments

Comments
 (0)