File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4444 run : rake install
4545 - name : Run exe
4646 run : |
47- tailcheck
47+ tailcheck --version
48+ tailcheck --help
49+ tailcheck test/data/pos1 test/data/not-exist test/data/pos2
Original file line number Diff line number Diff line change 33
44require 'fluent/tail_checker'
55
6- puts Fluent ::TailChecker ::VERSION
7-
86command = Fluent ::TailChecker ::TailCheck . new
97exit ( command . run )
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # Copyright 2025 Daijiro Fukuda
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+
17+ module Fluent
18+ module TailChecker
19+ UNWATCHED_POSITION = 0xffffffffffffffff
20+ POSITION_FILE_ENTRY_REGEX = /^([^\t ]+)\t ([0-9a-fA-F]+)\t ([0-9a-fA-F]+)/
21+
22+ class PosFile
23+ attr_reader :entries
24+
25+ def initialize ( path )
26+ @entries = PosFile . load_entries ( path )
27+ end
28+
29+ def self . load_entries ( path )
30+ entries = [ ]
31+
32+ File . open ( path , File ::RDONLY |File ::BINARY ) do |file |
33+ file . each_line do |line |
34+ m = POSITION_FILE_ENTRY_REGEX . match ( line )
35+ next if m . nil?
36+
37+ entries << PosEntry . new (
38+ m [ 1 ] ,
39+ m [ 2 ] . to_i ( 16 ) ,
40+ m [ 3 ] . to_i ( 16 ) ,
41+ )
42+ end
43+ end
44+
45+ entries
46+ end
47+ end
48+
49+ class PosEntry
50+ attr_reader :path , :pos , :ino
51+
52+ def initialize ( path , pos , ino )
53+ @path = path
54+ @pos = pos
55+ @ino = ino
56+ end
57+ end
58+ end
59+ end
Original file line number Diff line number Diff line change 1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17+ require "optparse"
18+
19+ require_relative "pos"
20+
1721module Fluent
1822 module TailChecker
1923 class TailCheck
20- def run
21- # TODO
22- puts "TailCheck command run."
24+ def initialize
25+ @pos_filepaths = [ ]
26+ end
27+
28+ def run ( argv = ARGV )
29+ parse_command_line ( argv )
30+ check
2331 true
2432 end
33+
34+ def parse_command_line ( argv )
35+ parser = OptionParser . new
36+ parser . version = VERSION
37+ parser . banner = <<~BANNER
38+ Usage: tailcheck pos_file [pos_file2 ...]
39+ Example: tailcheck /path/to/pos1 /path/to/pos2
40+
41+ BANNER
42+
43+ raw_paths = parser . parse ( argv )
44+ @pos_filepaths = validate_paths ( raw_paths ) . to_a
45+ end
46+
47+ def validate_paths ( paths )
48+ Enumerator . new do |y |
49+ paths . each do |path |
50+ unless FileTest . exist? ( path )
51+ $stderr. puts "File does not exist. Skipped. Path: #{ path } "
52+ next
53+ end
54+
55+ y << path
56+ end
57+ end
58+ end
59+
60+ def check
61+ @pos_filepaths . each do |path |
62+ check_pos ( path )
63+ end
64+ end
65+
66+ def check_pos ( path )
67+ posfile = PosFile . new ( path )
68+ # TODO
69+ p posfile
70+ rescue => e
71+ $stderr. puts "Can not open the file. Skipped. Path: #{ path } , Error: #{ e } "
72+ end
2573 end
2674 end
2775end
Original file line number Diff line number Diff line change 1+ /test/test.log 0000000000000008 00000000060e378c
2+ /test/test.log 0000000000000000 0000000000000000
Original file line number Diff line number Diff line change 1+ /test/test.log ffffffffffffffff 00000000060e3795
2+ /test/test.log ffffffffffffffff 00000000060e3796
3+ /test/test.log 0000000000000004 00000000060e3793
You can’t perform that action at this time.
0 commit comments