src/from_find.rb
# Expected input on stream is as output by the following command:
#   find . -exec stat -f "%T %z %m %N" {} + -exec tag {} +
Expected input on stream is as output by the following command:
find .
Expected input on stream is as output by the following command : find .
def parse_stream(stream, idx)
  stream.each do |line|
    stat = line.match /^([\*\/]?) (\d+) (\d+) (.+)$/
    if stat then
      idx.touch(
        name: stat[4],
        size: stat[2].to_i,
        type: if stat[1] == '/' then :dir else :file end,
        date: Time.at(stat[3].to_i))
    else
      tag = line.match /^([^\t]+)\t(\S+)$/
      if tag then
        idx.touch(name: tag[1], tags: tag[2].split(',').to_set)
      else
      end
    end
  end
end
def parse_stream ( stream , idx ) stream . each do | line | stat = line . match / ^([ \* \/ ]?) ( \d +) ( \d +) (.+)$ / if stat then idx . touch ( name : stat [ 4 ] , size : stat [ 2 ] . to_i , type : if stat [ 1 ] == '/' then :dir else :file end , date : Time . at ( stat [ 3 ] . to_i ) ) else tag = line . match / ^([^ \t ]+) \t ( \S +)$ / if tag then idx . touch ( name : tag [ 1 ] , tags : tag [ 2 ] . split ( ',' ) . to_set ) else end end end end
Expected input on stream is as output by the following command:
find .
Expected input on stream is as output by the following command : find .
# ignore: tag output just the file-nae if there is no tag. # difficult to discriminate from real error.
stream
<not_specific>
idx
<not_specific>