Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Sources/FileMonitor/FileMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// https://www.ausdertechnik.de
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

import FileMonitorShared
#if os(macOS)
import FileMonitorMacOS
Expand Down
14 changes: 14 additions & 0 deletions Sources/FileMonitorLinux/FileSystemWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions Sources/FileMonitorLinux/InotifyEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Sources/FileMonitorLinux/LinuxWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// https://www.ausdertechnik.de
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

import FileMonitorShared
#if canImport(CInotify)
import CInotify
Expand Down
15 changes: 15 additions & 0 deletions Sources/FileMonitorMacOS/MacosWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<URL> {
Set(lhs).subtracting(rhs)
}
}

#endif
4 changes: 4 additions & 0 deletions Sources/FileMonitorShared/FileChangeEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// https://www.ausdertechnik.de
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public enum FileChangeEvent {
case added(file: URL)
Expand Down
11 changes: 10 additions & 1 deletion Sources/FileMonitorShared/URL+isDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
19 changes: 5 additions & 14 deletions Sources/FileMonitorShared/Watcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// https://www.ausdertechnik.de
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif


public protocol WatcherDelegate {
func fileDidChanged(event: FileChangeEvent)
Expand All @@ -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<URL> {
Set(lhs).subtracting(rhs)
}
}
2 changes: 0 additions & 2 deletions Tests/FileMonitorTests/Extensions/String+Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//


import Foundation

/// Extends a `String` with functions to generate a random literal
///
extension String {
Expand Down
Loading