Skip to content

HP-UX implementation (workaround) with full sincedb file support #41

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 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions lib/filewatch/hpuxhelper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Hpuxhelper

def self.GetHpuxFileInode(path)
hpuxfileino = ""
IO.popen("ls -i #{path} | awk '{print $1}'").each do |line|
hpuxfileino = line.chomp
end
return hpuxfileino
end

def self.GetHpuxFileFilesystemMountPoint(path)
hpuxfsname = ""
IO.popen("df -n #{path} | awk '{print $1}'").each do |line|
hpuxfsname = line.chomp
end
return hpuxfsname
end
end
21 changes: 14 additions & 7 deletions lib/filewatch/tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
require "filewatch/watch"
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
require "filewatch/winhelper"
elsif RbConfig::CONFIG['host_os'] == "HP-UX"
require "filewatch/hpuxhelper"
end
require "logger"
require "rbconfig"

include Java if defined? JRUBY_VERSION
require "JRubyFileExtension.jar" if defined? JRUBY_VERSION
require "java/JRubyFileExtension.jar" if defined? JRUBY_VERSION

module FileWatch
class Tail
Expand All @@ -22,6 +24,7 @@ class NoSinceDBPathGiven < StandardError; end
public
def initialize(opts={})
@iswindows = ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) != nil)
@ishpux = ((RbConfig::CONFIG['host_os'] == "HP-UX") != false)

if opts[:logger]
@logger = opts[:logger]
Expand Down Expand Up @@ -127,14 +130,18 @@ def _open_file(path, event)
end

stat = File::Stat.new(path)

if @iswindows
fileId = Winhelper.GetWindowsUniqueFileIdentifier(path)
inode = [fileId, stat.dev_major, stat.dev_minor]
elsif @ishpux
fileId = Hpuxhelper.GetHpuxFileInode(path)
filesystemMountPoint = Hpuxhelper.GetHpuxFileFilesystemMountPoint(path)
inode = [fileId, filesystemMountPoint, 0]
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 +160,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 Expand Up @@ -226,7 +233,7 @@ def _sincedb_write
path = @opts[:sincedb_path]
tmp = "#{path}.new"
begin
db = File.open(tmp, "w")
db = File.open(tmp, "w+")
rescue => e
@logger.warn("_sincedb_write failed: #{tmp}: #{e}")
return
Expand All @@ -249,4 +256,4 @@ def quit
@watch.quit
end # def quit
end # class Tail
end # module FileWatch
end # module FileWatch
40 changes: 29 additions & 11 deletions lib/filewatch/watch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "logger"
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
require "filewatch/winhelper"
elsif RbConfig::CONFIG['host_os'] == "HP-UX"
require "filewatch/hpuxhelper"
end

module FileWatch
Expand All @@ -10,6 +12,7 @@ class Watch
public
def initialize(opts={})
@iswindows = ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) != nil)
@ishpux = ((RbConfig::CONFIG['host_os'] == "HP-UX") != false)
if opts[:logger]
@logger = opts[:logger]
else
Expand Down Expand Up @@ -75,10 +78,14 @@ def each(&block)
if @iswindows
fileId = Winhelper.GetWindowsUniqueFileIdentifier(path)
inode = [fileId, stat.dev_major, stat.dev_minor]
elsif @ishpux
fileId = Hpuxhelper.GetHpuxFileInode(path)
filesystemMountPoint = Hpuxhelper.GetHpuxFileFilesystemMountPoint(path)
inode = [fileId, filesystemMountPoint, 0]
else
inode = [stat.ino.to_s, stat.dev_major, stat.dev_minor]
end

if inode != @files[path][:inode]
@logger.debug("#{path}: old inode was #{@files[path][:inode].inspect}, new is #{inode.inspect}")
yield(:delete, path)
Expand Down Expand Up @@ -147,19 +154,30 @@ def _discover_file(path, initial=false)
next if skip

stat = File::Stat.new(file)
@files[file] = {
:size => 0,
:inode => [stat.ino, stat.dev_major, stat.dev_minor],
:create_sent => false,
}

if @iswindows

if @iswindows
fileId = Winhelper.GetWindowsUniqueFileIdentifier(path)
@files[file][:inode] = [fileId, stat.dev_major, stat.dev_minor]
@files[file] = {
:size => 0,
:inode => [fileId, stat.dev_major, stat.dev_minor],
:create_sent => false,
}
elsif @ishpux
fileId = Hpuxhelper.GetHpuxFileInode(path)
filesystemMountPoint = Hpuxhelper.GetHpuxFileFilesystemMountPoint(path)
@files[file] = {
:size => 0,
:inode => [fileId, filesystemMountPoint, 0],
:create_sent => false,
}
else
@files[file][:inode] = [stat.ino.to_s, stat.dev_major, stat.dev_minor]
@files[file] = {
:size => 0,
:inode => [stat.ino.to_s, stat.dev_major, stat.dev_minor],
:create_sent => false,
}
end

if initial
@files[file][:initial] = true
end
Expand Down
File renamed without changes.
File renamed without changes.