我建议使用rb-inotify gem(它是 linux inotify内核子系统的包装器,它为您的应用程序提供有关文件系统更改的事件)。
使用它,您可以监视您的FULL
目录并将每个操作镜像到SMALL
目录中。
以下存根应该可以帮助您:
require 'rb-inotify'
notifier = INotify::Notifier.new
# you might want events like :moved_to etc. - have a look at the documentation :)
notifier.watch("path/to/FULL", :create, :modify, :delete) do |e|
puts e.absolute_name # gives you the absolute path to the file/directory, which caused the event
puts e.flags # gives you the event types that caused this event (e.g. :modified)
if e.flags.include? :create
if e.flags.include? :isdir
# create matching dir in SMALL
else
# create new image in SMALL
end
elsif e.flags.include? :modify
# generate new SMALL image if it's not a dir
elsif e.flags.include? :deleted
# delete matching dir/file in SMALL
end
end
notifier.run # loops forever and waits for filesystem events
# alternatively use
notifier.process # blocks untils first filesystem changes was processed
请查看gem 文档和inotify 文档(查看哪些事件类型是可能的)。