Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Filesystem monitor for elixir

License

NotificationsYou must be signed in to change notification settings

falood/file_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module VersionHex DocsTotal DownloadLicenseLast UpdatedCI LinuxCI MacOSCI Windows

An Elixir file change watcher wrapper based onFS, the native file system listener.

System Support

On MacOS 10.14, to compilemac_listener, run:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

On newer versions this file doesn't exist. But it still should work just fine as long as you have xcode installed.

Usage

Addfile_system to thedeps of your mix.exs

defmoduleMyApp.MixfiledouseMix.Projectdefprojectdo...enddefpdepsdo[{:file_system,"~> 1.0",only::test},]end...end

Subscription API

You can spawn a worker and subscribe to events from it:

{:ok,pid}=FileSystem.start_link(dirs:["/path/to/some/files"])FileSystem.subscribe(pid)

or

{:ok,pid}=FileSystem.start_link(dirs:["/path/to/some/files"],name::my_monitor_name)FileSystem.subscribe(:my_monitor_name)

Thepid you subscribed from will now receive messages like:

{:file_event, worker_pid, {file_path, events}}

and

{:file_event, worker_pid, :stop}

Example Using GenServer

defmoduleWatcherdouseGenServerdefstart_link(args)doGenServer.start_link(__MODULE__,args)enddefinit(args)do{:ok,watcher_pid}=FileSystem.start_link(args)FileSystem.subscribe(watcher_pid){:ok,%{watcher_pid:watcher_pid}}enddefhandle_info({:file_event,watcher_pid,{path,events}},%{watcher_pid:watcher_pid}=state)do# Your own logic for path and events{:noreply,state}enddefhandle_info({:file_event,watcher_pid,:stop},%{watcher_pid:watcher_pid}=state)do# Your own logic when monitor stop{:noreply,state}endend

Backend Options

For each platform, you can pass extra options to the underlying listenerprocess.

Each backend supports different extra options, check backend moduledocumentation for more details.

Here is an example to get instant notifications on file changes for MacOS:

FileSystem.start_link(dirs:["/path/to/some/files"],latency:0,watch_root:true)

[8]ページ先頭

©2009-2025 Movatter.jp