Skip to content

Commit d40ae71

Browse files
author
aixing
committed
feat: Adds file attributes supports on mac os platform.
1 parent 06f95bd commit d40ae71

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Sources/Files.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class FileSystem {
4545
* to perform operations that are supported by both files & folders.
4646
*/
4747
public class Item: Equatable, CustomStringConvertible {
48+
#if os(macOS)
49+
/// The attributes of the `FileSystem.Item` on mac os platform.
50+
public typealias Attributes = [FileAttributeKey: Any]
51+
#endif
4852
/// Errror type used for invalid paths for files or folders
4953
public enum PathError: Error, Equatable, CustomStringConvertible {
5054
/// Thrown when an empty path was given when initializing a file
@@ -213,6 +217,20 @@ public class FileSystem {
213217
fileprivate let kind: Kind
214218
fileprivate let fileManager: FileManager
215219

220+
#if os(macOS)
221+
/// The file attributes of the item on file system.
222+
@available(macOS 10.5, *)
223+
public var attributes: Attributes? {
224+
get {
225+
return try? fileManager.attributesOfItem(atPath: path)
226+
}
227+
228+
set {
229+
try? fileManager.setAttributes(newValue ?? [:], ofItemAtPath: path)
230+
}
231+
}
232+
#endif
233+
216234
fileprivate init(path: String, kind: Kind, using fileManager: FileManager) throws {
217235
guard !path.isEmpty else {
218236
throw PathError.empty

0 commit comments

Comments
 (0)