diff --git a/lib/filewatch/hpuxhelper.rb b/lib/filewatch/hpuxhelper.rb new file mode 100644 index 0000000..ca92603 --- /dev/null +++ b/lib/filewatch/hpuxhelper.rb @@ -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 \ No newline at end of file diff --git a/lib/filewatch/tail.rb b/lib/filewatch/tail.rb index 6c27bfe..5716b2f 100644 --- a/lib/filewatch/tail.rb +++ b/lib/filewatch/tail.rb @@ -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 @@ -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] @@ -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) @@ -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) @@ -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 @@ -249,4 +256,4 @@ def quit @watch.quit end # def quit end # class Tail -end # module FileWatch +end # module FileWatch \ No newline at end of file diff --git a/lib/filewatch/watch.rb b/lib/filewatch/watch.rb index 8715130..7063b86 100644 --- a/lib/filewatch/watch.rb +++ b/lib/filewatch/watch.rb @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/java/JRubyFileExtension.jar b/lib/java/JRubyFileExtension.jar similarity index 100% rename from java/JRubyFileExtension.jar rename to lib/java/JRubyFileExtension.jar diff --git a/java/RubyFileExt.java b/lib/java/RubyFileExt.java similarity index 100% rename from java/RubyFileExt.java rename to lib/java/RubyFileExt.java