Monitor changes to files and directories using kernel event notifications (kqueue) in Swift

Overview

SKQueue

SKQueue is a Swift libary used to monitor changes to the filesystem. It wraps the part of the kernel event notification interface of libc, kqueue. This means SKQueue has a very small footprint and is highly scalable, just like kqueue.

Requirements

  • Swift tools version 4

To build in older environments just replace Package.swift with this file.

Installation

Swift Package Manager

To use SKQueue, add the code below to your dependencies in Package.swift. Then run swift package fetch to fetch SKQueue.

.package(url: "https://github.com/daniel-pedersen/SKQueue.git", from: "1.2.0"),

Usage

To monitor the filesystem with SKQueue, you first need a SKQueueDelegate instance that can accept notifications. Paths to watch can then be added with addPath, as per the example below.

Example

import SKQueue

class SomeClass: SKQueueDelegate {
  func receivedNotification(_ notification: SKQueueNotification, path: String, queue: SKQueue) {
    print("\(notification.toStrings().map { $0.rawValue }) @ \(path)")
  }
}

let delegate = SomeClass()
let queue = SKQueue(delegate: delegate)!

queue.addPath("/Users/steve/Documents")
queue.addPath("/Users/steve/Documents/dog.jpg")
Action Sample output
Add or remove file in /Users/steve/Documents ["Write"] @ /Users/steve/Documents
Add or remove directory in /Users/steve/Documents ["Write", "SizeIncrease"] @ /Users/steve/Documents
Write to file /Users/steve/Documents/dog.jpg ["Rename", "SizeIncrease"] @ /Users/steve/Documents/dog.jpg

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D
Comments
  • Swift Package Manager support

    Swift Package Manager support

    Hi there!

    Thanks for making SKQueue, really helped me out with some tooling I'm working on for a side project.

    This PR adds support for the Swift Package Manager. Unfortunately SPM requires Swift 3.0, so in order to do that I had to merge @rezozo's PR #3. That PR is obviously still open with your concerns. LMK how you want to proceed with this, I'd happily implement the changes you pointed out on his PR if that's what's needed.

    Thanks!

    enhancement 
    opened by ChrisChares 5
  • SKQueue deprecation notice

    SKQueue deprecation notice

    So it seems like this library is still growing in popularity. I'm guessing the ease of use is appealing.

    Some background: I wrote this library back in 2014 when Swift was still unstable and I needed kqueue functionality for a project. Today I would have used the DispatchSource API, which exposes kqueue functionality optimized for GCD.

    But if y'all like this API I'll consider maintaining it.

    opened by daniel-pedersen 3
  • Adapted to Swift 3.0

    Adapted to Swift 3.0

    I've adapted the library to swift 3, just some small changes to what Xcode told me to change and what I knew I needed to change (such as the dispatch_global to DispatchQueue.global and some other stuff).

    Also added syntax highlighting to the README.md.

    enhancement 
    opened by jonohayon 3
  • New 1.3 release

    New 1.3 release

    Hey @daniel-pedersen, now that #12 is merged, would you mind tagging a new release? This would help packages depending on SKQueue, as they could specify a release tag in their dependencies instead of master. Depending on master directly sometimes leads to issues, especially when integrating SwiftPM dependencies with Xcode. Thanks!

    opened by MaxDesiatov 2
  • Question for what program did modification

    Question for what program did modification

    Hi, great lib!

    I'm making an application that continually saves state-files to disk. I'd like to be able to use e.g. a DropBox folder as storage. If the files is modified from another computer and synched with dropbox i'd like to get a notification so I can reload my cached in app state. I would like to filter away my own local modifications and only get notified by other processes modifications. Is it possible to somehow get what process that modified the file? It would be nice to not have to constantly read the files after modifications and compare them to my local cache.

    question 
    opened by potmo 1
  • Update Package.swift

    Update Package.swift

    Currently, when trying to build SKQueue with Swift 5.2.2 from Xcode 11.4.1, I get this error:

    .build/checkouts/SKQueue: error: manifest parse error(s):
    .build/checkouts/SKQueue/Package.swift:5:15: error: 'init(name:pkgConfig:providers:products:dependencies:targets:swiftLanguageVersions:cLanguageStandard:cxxLanguageStandard:)' 
    is unavailable
    let package = Package(
                  ^~~~~~~
    PackageDescription.Package:30:12: note: 'init(name:pkgConfig:providers:products:dependencies:targets:swiftLanguageVersions:cLanguageStandard:cxxLanguageStandard:)' 
    was introduced in PackageDescription 4.2
        public init(name: String, pkgConfig: String? = nil, providers: [PackageDescription.SystemPackageProvider]? = nil, products: [PackageDescription.Product] = [], dependencies: [PackageDescription.Package.Dependency] = [], targets: [PackageDescription.Target] = [], swiftLanguageVersions: [PackageDescription.SwiftVersion]? = nil, cLanguageStandard: PackageDescription.CLanguageStandard? = nil, cxxLanguageStandard: PackageDescription.CXXLanguageStandard? = nil)
    

    Bumping swift-tools-version in Package.swift to 4.2 fixes the problem.

    opened by MaxDesiatov 1
  • Stops notifying

    Stops notifying

    Couldn't really get things to work reliably.

    I monitor a simple html file. If I open it in TextWrangler it works, but if I open it in Xcode (9.4.1) or Coda (2.6.10), then I get a "Rename" notification then nothing. This is on 10.13.6

    Any ideas?

    L

    opened by laurent-humbert 1
  • Watch folder question

    Watch folder question

    Hello, I've been playing with SKQueue and noticed that the path is always the folder which is being watched. Not the file that was created or modified. Is this on purpose?

    question 
    opened by cheizer 1
  • Moving folder containing watched files does not trigger notification

    Moving folder containing watched files does not trigger notification

    Hey, first of all thanks for a great lib! I'm using it with success to watch files.

    One thing I noticed is that, if I watch a folder and some files contained in it (I'm not even sure I can add folder paths but it doesn't throw an error and isPathWatched returns true for folders too), then moving the folder's location on disk will not post any notification, not on the folder path nor the files' paths.

    Is there a way to make this work without too much hassle? It's weird that even the files inside the moved folder don't trigger a notif.

    Thanks!

    question 
    opened by beeb 1
  • Get always

    Get always "Write" notification!

    Hi, i tried this to get run. Every time I change a file in one of the folders tracked, I get a "Write" notification, even if I rename a file. You have a long list of different cases, but it seems 2 is the only number returned (= Write). Is this a bug or a feature? ;-) Dirk P.S.: I'm using Xcode 7.3 and OSX 10.11.6

    question 
    opened by schlemiel29 1
Releases(v1.2.1)
Owner
Daniel Pedersen
Daniel Pedersen
An app that converts the temperature in Fahrenheit your input, and then changes to Celsius.

Swift Temperature Converter An app that converts the temperature in Fahrenheit your input, and then changes to Celsius. Things you need to do ?? clone

Tsuen Hsueh 1 Aug 16, 2022
Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event.

Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event. Goals of this project One of th

Zigii Wong 410 Sep 9, 2022
Swift 3 framework for accessing data in Event Registry

Swift 3 framework for accessing data in Event Registry

Pavel Pantus 8 Nov 1, 2016
Merges a given number of PDF files into one file using the PDFKit framework

Titanium iOS PDF Merge Merges a given number of PDF files into one file using the PDFKit framework Requirements iOS 11+ Titanium SDK 9+ API's Methods

Hans Knöchel 6 Jan 26, 2022
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023
Validate iOS, Android, and Mac localizations. Find errors in .strings, .stringsdict, and strings.xml files.

Locheck An Xcode and Android localization file validator. Make sure your .strings, .stringsdict, and strings.xml files do not have any errors! What do

Asana 73 Dec 13, 2022
ZIP Foundation is a library to create, read and modify ZIP archive files.

ZIP Foundation is a library to create, read and modify ZIP archive files. It is written in Swift and based on Apple's libcompression for high performa

Thomas Zoechling 1.9k Dec 27, 2022
Steps and files needed to reproduce a CSP bug in Safari Web Extensions

CSP Safari bug repro There appears to be a discrepancy between how Safari handles CSP policies for extension pages compared to how other browsers do s

Brian Birtles 0 Nov 6, 2021
Parse iOS mobile provisioning files into Swift models

SwiftyProvisioningProfile This library provides a way to decode a .mobileprovision file into a Swift model. Installation The recommended installation

James Sherlock 60 Nov 25, 2022
Converter for your Rigol Oscilloscope .CSV files to LtSpice

rigol2spice A program to convert Rigol oscilloscope's .CSV files to a format readable by LTspice. Your Rigol oscilloscope can output .CSV files that c

Rui Carneiro 4 Aug 31, 2022
HxSTLParser is a basic STL parser capable of loading STL files into an SCNNode

HxSTLParser HxSTLParser is a basic STL parser capable of loading STL files into an SCNNode. Installing Via Carthage Just add it to your Cartfile githu

Victor 23 Dec 16, 2022
Creates SpriteKit game maps from TMX Map files.

PEMTileMap is a Swift package that generates SpriteKit game maps from TMX Map files. Maps, layers, tiles and objects are automatically rendered as SKN

hotdogsoup.nl 3 Jul 12, 2022
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.

TypeStyle TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app. Featu

Eugene Belinski 31 Dec 14, 2022
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Apple 4.1k Dec 28, 2022
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Zamzam Inc. 261 Dec 15, 2022
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

Viktor G 26 Dec 14, 2022
This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to load remote images

iOS NOW ⭐ This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to loa

William Tristão de Paula 1 Dec 7, 2021
Parsing indeterminate types with Decodable and Either enum using Swift

Decodable + Either Parsing indeterminate types with Decodable and Either enum us

Alonso Alvarez 1 Jan 9, 2022