Implemented the FileService service in the library target.
This commit is contained in:
parent
f6dcc80edc
commit
4d4ce5d647
31
Library/Sources/Internal/Services/FileService.swift
Normal file
31
Library/Sources/Internal/Services/FileService.swift
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct FileService: FileServicing {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
func listItems(in folder: String) async throws (FileServiceError) -> [String] {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
|
||||||
|
guard !folder.isEmpty else {
|
||||||
|
throw .folderPathEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
var isFolder: ObjCBool = false
|
||||||
|
|
||||||
|
guard fileManager.fileExists(atPath: folder, isDirectory: &isFolder) else {
|
||||||
|
throw .folderNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
guard isFolder.boolValue else {
|
||||||
|
throw .folderNotDirectory
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
return try fileManager.contentsOfDirectory(atPath: folder)
|
||||||
|
} catch {
|
||||||
|
throw .other(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import DoxyLibrary
|
||||||
|
|
||||||
|
@Suite("FileService", .tags(.service))
|
||||||
|
struct FileServiceTests {
|
||||||
|
}
|
@ -8,5 +8,6 @@ extension Tag {
|
|||||||
@Tag static var enumeration: Tag
|
@Tag static var enumeration: Tag
|
||||||
@Tag static var middleware: Tag
|
@Tag static var middleware: Tag
|
||||||
@Tag static var provider: Tag
|
@Tag static var provider: Tag
|
||||||
|
@Tag static var service: Tag
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user