Skip to content

Added additional error checking to FileWatch::Tail#_open_file #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions lib/filewatch/tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,30 @@ def _open_file(path, event)
else
@files[path] = File.open(path)
end

stat = File::Stat.new(path)
rescue
# don't emit this message too often. if a file that we can't
# read is changing a lot, we'll try to open it more often,
# and might be spammy.
now = Time.now.to_i
if now - @lastwarn[path] > OPEN_WARN_INTERVAL
@logger.warn("failed to open #{path}: #{$!}")
@logger.warn("failed to open or stat #{path}: #{$!}")
@lastwarn[path] = now
else
@logger.debug("(warn supressed) failed to open #{path}: #{$!}")
@logger.debug("(warn supressed) failed to open or stat #{path}: #{$!}")
end
@files.delete(path)
return false
end

stat = File::Stat.new(path)

if @iswindows
fileId = Winhelper.GetWindowsUniqueFileIdentifier(path)
inode = [fileId, stat.dev_major, stat.dev_minor]
else
inode = [stat.ino.to_s, stat.dev_major, stat.dev_minor]
end
end

@statcache[path] = inode

if @sincedb.member?(inode)
Expand All @@ -153,7 +153,7 @@ def _open_file(path, event)
@logger.debug("#{path}: initial create, no sincedb, seeking to beginning of file")
@files[path].sysseek(0, IO::SEEK_SET)
@sincedb[inode] = 0
else
else
# seek to end
@logger.debug("#{path}: initial create, no sincedb, seeking to end #{stat.size}")
@files[path].sysseek(stat.size, IO::SEEK_SET)
Expand Down