forked from ttilley/fssm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support watching of individual files.
- Loading branch information
Showing
9 changed files
with
111 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module FSSM::State | ||
class Directory | ||
attr_reader :path | ||
|
||
def initialize(path) | ||
@path = path | ||
@cache = FSSM::Tree::Cache.new | ||
end | ||
|
||
def refresh(base=nil, skip_callbacks=false) | ||
previous, current = recache(base || @path.to_pathname) | ||
|
||
unless skip_callbacks | ||
deleted(previous, current) | ||
created(previous, current) | ||
modified(previous, current) | ||
end | ||
end | ||
|
||
private | ||
|
||
def created(previous, current) | ||
(current.keys - previous.keys).each {|created| @path.create(created)} | ||
end | ||
|
||
def deleted(previous, current) | ||
(previous.keys - current.keys).each {|deleted| @path.delete(deleted)} | ||
end | ||
|
||
def modified(previous, current) | ||
(current.keys & previous.keys).each do |file| | ||
@path.update(file) if (current[file] <=> previous[file]) != 0 | ||
end | ||
end | ||
|
||
def recache(base) | ||
base = FSSM::Pathname.for(base) | ||
previous = @cache.files | ||
snapshot(base) | ||
current = @cache.files | ||
[previous, current] | ||
end | ||
|
||
def snapshot(base) | ||
base = FSSM::Pathname.for(base) | ||
@cache.unset(base) | ||
@path.glob.each {|glob| add_glob(base, glob)} | ||
end | ||
|
||
def add_glob(base, glob) | ||
FSSM::Pathname.glob(base.join(glob).to_s).each do |fn| | ||
@cache.set(fn) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module FSSM::State | ||
class File | ||
attr_reader :path | ||
|
||
def initialize(path) | ||
@path = path | ||
end | ||
|
||
def refresh(base=nil, skip_callbacks=false) | ||
base ||= @path.to_pathname | ||
used_to_exist, @exists = @exists, base.exists? | ||
# this handles bad symlinks without failing. why handle bad symlinks at | ||
# all? well, we could still be interested in their creation and deletion. | ||
old_mtime, @mtime = @mtime, base.symlink? ? Time.at(0) : base.mtime if @exists | ||
|
||
unless skip_callbacks | ||
@path.delete(@path.to_s) if used_to_exist && !@exists | ||
@path.create(@path.to_s) if !used_to_exist && @exists | ||
@path.update(@path.to_s) if used_to_exist && @exists && old_mtime != @mtime | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters