diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 790a8fa..b25b4ee 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -13,11 +13,11 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Install Swift uses: swift-actions/setup-swift@v1 with: - swift-version: 5.9 + swift-version: 6.3 - name: Build run: swift build -v - name: Run tests diff --git a/Sources/FileMonitor/FileMonitor.swift b/Sources/FileMonitor/FileMonitor.swift index 65f9c11..2665989 100644 --- a/Sources/FileMonitor/FileMonitor.swift +++ b/Sources/FileMonitor/FileMonitor.swift @@ -3,7 +3,12 @@ // https://www.ausdertechnik.de // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif + import FileMonitorShared #if os(macOS) import FileMonitorMacOS diff --git a/Sources/FileMonitorLinux/FileSystemWatcher.swift b/Sources/FileMonitorLinux/FileSystemWatcher.swift index bda7477..cbebaf6 100644 --- a/Sources/FileMonitorLinux/FileSystemWatcher.swift +++ b/Sources/FileMonitorLinux/FileSystemWatcher.swift @@ -2,10 +2,24 @@ // aus der Technik, on 19.05.23. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif +import Dispatch #if canImport(CInotify) import CInotify #endif +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif canImport(Darwin) +import Darwin.C +#else +#error("Unsupported platform") +#endif #if os(Linux) public class FileSystemWatcher { diff --git a/Sources/FileMonitorLinux/InotifyEvent.swift b/Sources/FileMonitorLinux/InotifyEvent.swift index 5415c5e..2ac64af 100644 --- a/Sources/FileMonitorLinux/InotifyEvent.swift +++ b/Sources/FileMonitorLinux/InotifyEvent.swift @@ -5,7 +5,12 @@ // Heavily inspired by https://github.com/felix91gr/FileSystemWatcher/blob/master/Sources/fswatcher.swift // See https://www.man7.org/linux/man-pages/man7/inotify.7.html +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif + import Dispatch /// A single Inotify event diff --git a/Sources/FileMonitorLinux/LinuxWatcher.swift b/Sources/FileMonitorLinux/LinuxWatcher.swift index 9fa8252..ad94485 100644 --- a/Sources/FileMonitorLinux/LinuxWatcher.swift +++ b/Sources/FileMonitorLinux/LinuxWatcher.swift @@ -3,7 +3,12 @@ // https://www.ausdertechnik.de // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif + import FileMonitorShared #if canImport(CInotify) import CInotify diff --git a/Sources/FileMonitorMacOS/MacosWatcher.swift b/Sources/FileMonitorMacOS/MacosWatcher.swift index de1b72a..f6b8801 100644 --- a/Sources/FileMonitorMacOS/MacosWatcher.swift +++ b/Sources/FileMonitorMacOS/MacosWatcher.swift @@ -57,4 +57,19 @@ public final class MacosWatcher: WatcherProtocol { fileWatcher.stop(); } } + +public extension WatcherProtocol { + func getCurrentFiles(in directory: URL) throws -> [URL] { + try FileManager.default.contentsOfDirectory( + at: directory, + includingPropertiesForKeys: [.creationDateKey, .typeIdentifierKey], + options: [.skipsHiddenFiles] + ) + } + + func getDifferencesInFiles(lhs: [URL], rhs: [URL]) -> Set { + Set(lhs).subtracting(rhs) + } +} + #endif diff --git a/Sources/FileMonitorShared/FileChangeEvent.swift b/Sources/FileMonitorShared/FileChangeEvent.swift index f9a3b23..04ea429 100644 --- a/Sources/FileMonitorShared/FileChangeEvent.swift +++ b/Sources/FileMonitorShared/FileChangeEvent.swift @@ -3,7 +3,11 @@ // https://www.ausdertechnik.de // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif public enum FileChangeEvent { case added(file: URL) diff --git a/Sources/FileMonitorShared/URL+isDirectory.swift b/Sources/FileMonitorShared/URL+isDirectory.swift index 854d005..bb3bf0a 100644 --- a/Sources/FileMonitorShared/URL+isDirectory.swift +++ b/Sources/FileMonitorShared/URL+isDirectory.swift @@ -3,13 +3,22 @@ // https://www.ausdertechnik.de // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif + public extension URL { // Is the URL a directory? var isDirectory: Bool { +#if os(macOS) var boolFalse: ObjCBool = false - return FileManager.default.fileExists(atPath: path, isDirectory: &boolFalse) && boolFalse.boolValue +#else + var boolFalse: Bool = false +#endif + return FileManager.default.fileExists(atPath: path, isDirectory: &boolFalse) && boolFalse } } diff --git a/Sources/FileMonitorShared/Watcher.swift b/Sources/FileMonitorShared/Watcher.swift index 5bf1a91..9d9d200 100644 --- a/Sources/FileMonitorShared/Watcher.swift +++ b/Sources/FileMonitorShared/Watcher.swift @@ -3,7 +3,12 @@ // https://www.ausdertechnik.de // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif + public protocol WatcherDelegate { func fileDidChanged(event: FileChangeEvent) @@ -16,17 +21,3 @@ public protocol WatcherProtocol { func observe() throws func stop() } - -public extension WatcherProtocol { - func getCurrentFiles(in directory: URL) throws -> [URL] { - try FileManager.default.contentsOfDirectory( - at: directory, - includingPropertiesForKeys: [.creationDateKey, .typeIdentifierKey], - options: [.skipsHiddenFiles] - ) - } - - func getDifferencesInFiles(lhs: [URL], rhs: [URL]) -> Set { - Set(lhs).subtracting(rhs) - } -} diff --git a/Tests/FileMonitorTests/Extensions/String+Random.swift b/Tests/FileMonitorTests/Extensions/String+Random.swift index 90e9d49..78ad07b 100644 --- a/Tests/FileMonitorTests/Extensions/String+Random.swift +++ b/Tests/FileMonitorTests/Extensions/String+Random.swift @@ -3,8 +3,6 @@ // -import Foundation - /// Extends a `String` with functions to generate a random literal /// extension String {