Skip to content

Commit fe632d9

Browse files
committed
Update Path and Filesystem
1 parent 98c1db4 commit fe632d9

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

Sources/File/FileSystem.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,55 @@ public protocol FileSystem: Equatable, CustomStringConvertible {
1212
init(store: Store<Self>)
1313
}
1414

15-
public extension FileSystem {
15+
extension FileSystem {
1616
/// FileSystem Description
17-
var description: String {
17+
public var description: String {
1818
return "(name: \(name), path: \(store.path.rawValue))"
1919
}
2020

2121
/// FileSystem URL
22-
var url: URL {
22+
public var url: URL {
2323
return URL(fileURLWithPath: store.path.rawValue)
2424
}
2525

2626
/// FileSystem Name
27-
var name: String {
27+
public var name: String {
2828
return url.pathComponents.last!
2929
}
3030

3131
/// File Extension in File System
32-
var `extension`: String? {
32+
public var `extension`: String? {
3333
let components = name.split(separator: ".")
3434
guard components.count > 1 else { return nil }
3535
return String(components.last!)
3636
}
3737

3838
/// The date when the item at this FileSystem was created
39-
var creationDate: Date? {
39+
public var creationDate: Date? {
4040
return store.attributes[.creationDate] as? Date
4141
}
4242

4343
/// The date when the item at this FileSystem was last modified
44-
var modificationDate: Date? {
44+
public var modificationDate: Date? {
4545
return store.attributes[.modificationDate] as? Date
4646
}
4747

4848
/// Initalizer path inside FileSystem
49-
init(path: Path) throws {
49+
public init(path: Path) throws {
5050
try self.init(store: Store(
5151
path: path,
5252
fileManager: .default
5353
))
5454
}
5555

56-
static func == (lhs: Self, rhs: Self) -> Bool {
56+
public static func == (lhs: Self, rhs: Self) -> Bool {
5757
return lhs.description == rhs.description
5858
}
5959
}
6060

61-
public extension FileSystem {
61+
extension FileSystem {
6262
/// Rename this FileSystem, keeping its exist `extension`
63-
func rename(to newName: String, keepExtensions: Bool = true) throws {
63+
public func rename(to newName: String, keepExtensions: Bool = true) throws {
6464
var newName = newName
6565
if keepExtensions {
6666
`extension`.map {
@@ -71,25 +71,25 @@ public extension FileSystem {
7171
}
7272

7373
/// Move this File System to a new parents Folder
74-
func move(to newParent: Folder) throws {
74+
public func move(to newParent: Folder) throws {
7575
let path = Path(newParent.store.path.rawValue + name)
7676
try store.move(to: path)
7777
}
7878

7979
/// Copy the content of this File System to a given folder
80-
func copy(to folder: Folder) throws -> Self {
80+
public func copy(to folder: Folder) throws -> Self {
8181
let path = Path(folder.store.path.rawValue + name)
8282
try store.copy(to: path)
8383
return try Self(path: path)
8484
}
8585

8686
/// Delete this FileSystem.
87-
func delete() throws {
87+
public func delete() throws {
8888
try store.delete()
8989
}
9090

9191
/// FileSystem `FileManager` Setting
92-
func managedBy(_ manager: FileManager) throws -> Self {
92+
public func managedBy(_ manager: FileManager) throws -> Self {
9393
return try Self(store: Store(
9494
path: store.path,
9595
fileManager: manager

Sources/File/Path.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ public struct Path {
66
public static let root = Path("/")
77

88
/// Home path.
9-
public static var home = Path("~")
9+
public static var home: Path {
10+
return Path(NSHomeDirectory())
11+
}
12+
13+
/// System Temporary path.
14+
public static var temporary: Path {
15+
return Path(NSTemporaryDirectory())
16+
}
1017

1118
/// Documents path.
1219
public static var documents: Path {
@@ -23,9 +30,6 @@ public struct Path {
2330
return Path(NSTemporaryDirectory()).standardized
2431
}
2532

26-
/// System Temporary path.
27-
public static var temporary = Path(NSTemporaryDirectory())
28-
2933
/// Standardized path
3034
public var standardized: Path {
3135
return Path((self.rawValue as NSString).standardizingPath)

Sources/File/Store.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ extension Store where fileSystem == Folder {
156156
}
157157

158158
/// Create File to path.
159-
func createFile(at filePath: Path, contents: Data? = nil) throws -> File {
159+
func createFile(at filePath: Path, contents: Data?) throws -> File {
160160
let filePath = path.rawValue + filePath.rawValue.removeSafePrefix("/")
161161
let parentPath = Path(filePath).parents.rawValue
162162
if parentPath != path.rawValue {
@@ -169,10 +169,10 @@ extension Store where fileSystem == Folder {
169169
throw FileError.folderCreateError(path: Path(parentPath), error: error)
170170
}
171171
}
172-
guard fileManager.createFile(atPath: filePath, contents: contents) else {
172+
guard fileManager.createFile(atPath: filePath, contents: contents),
173+
let store = try? Store<File>(path: Path(filePath), fileManager: fileManager) else {
173174
throw FileError.fileCreateError(path: Path(filePath))
174175
}
175-
let store = try Store<File>(path: Path(filePath), fileManager: fileManager)
176176
return File(store: store)
177177
}
178178
}

0 commit comments

Comments
 (0)