rbfind 2.6 → 2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rbfind +9 -5
  3. data/lib/rbfind.rb +37 -26
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0a448408396d2339b4aa0656dfeb579c6533373623ca9e6cb0e4b48812e2b03
4
- data.tar.gz: d71f32510fdc92315c7f5aaa16d08560d6bc6b1d9515af85913f3c4a4f42e6ba
3
+ metadata.gz: b57d2e44d4df6453083635d22ab01c92ea5b54fed8c121a313ac351048f16b51
4
+ data.tar.gz: 20518a97f6e446de75b6397a0e725a9f1c93d5c61f93743072a2b60e322c75a5
5
5
  SHA512:
6
- metadata.gz: bab39e437deaa7cf9d4e283f83c5ee354c3f28b4ed7159b90adfdcc7210c2dfce80593cfadcceb3c0702c4641c93b66b4fd2e4351deccd62adb9267754aaf588
7
- data.tar.gz: 44adde8bccbb1f840187bb9973a7e835d098f05c715fa22cf493a06fa8c00bc5bdbdb7e0d5da77db925034f3315f16148fd7431ed8b745febaeaadda0d5fd560
6
+ metadata.gz: 6ad6d7f05ad3de24d717dc7d274ea5dc75fd5ee81640c1de03bef875727a5f33ed80846ad7445a990ac925734a1dbed66312bac0686bcbb7d16bd1d33ae2d710
7
+ data.tar.gz: 9b97002d3fd98ffd891d5d10b6fc60087a18f2a2b828a0a0099554fa2f50fe0e562a3cd4a062602e9210508d389b733974ddeb9442e0636083cc4e98a8740777
data/bin/rbfind CHANGED
@@ -43,6 +43,7 @@ module RbFind
43
43
  [ %w(--puts-path -p), nil, "do 'puts path/cpath' on true block"],
44
44
  [ %w(--ls-l -P), nil, "do 'ls -l' style output on true block"],
45
45
  [ %w(--long -Q), nil, "alternate long format on true block"],
46
+ [ %w(--ino -J), nil, "show inodes and number of hard links"],
46
47
  [ %w(--wider -+), nil, "widen fields in long output format"],
47
48
  [ %w(--slash -/), nil, "append a slash to directory names"],
48
49
  [ %w(--lines -l), :blk, "surround block by 'lines { |$_,$.| ... }'"],
@@ -95,7 +96,8 @@ module RbFind
95
96
  when '--puts-path' then @puts = true
96
97
  when '--ls-l' then @puts = :ls ; @wds = 6 ; @wd = 6
97
98
  when '--long' then @puts = :alt ; @wds = 7 ; @wd = 4
98
- when '--wider' then @wd and @wd += 2.succ ; @wds and @wds += @puts == :alt ? 4 : 3
99
+ when '--ino' then @puts = :ino ; @wds = 8 ; @wd = 2
100
+ when '--wider' then @wd and @wd += 2.succ ; @wds and @wds += @puts != :ls ? 4 : 3
99
101
  when '--slash' then @slash = true
100
102
  when '--lines' then @lines = :plain ; @block = arg
101
103
  when '--reallines' then @lines = :plain ; @real = true ; @block = arg
@@ -161,12 +163,14 @@ module RbFind
161
163
  if @puts then
162
164
  @block = "( #@block ) and "
163
165
  @block << case @puts
164
- when :alt then
165
- "spcsep stype+modes, user!.w#@wd, group!.w#@wd, size.w_#@wds, " +
166
- "mtime.long, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
167
166
  when :ls then
168
167
  "spcsep stype+modes, user.w#@wd, group.w#@wd, size.w#@wds, " +
169
168
  "mtime.lsish, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
169
+ when :alt then
170
+ "spcsep stype+modes, user!.w#@wd, group!.w#@wd, size.w_#@wds, " +
171
+ "mtime.long, #{opath} + #{co ? 'carrow' : 'arrow'}.to_s"
172
+ when :ino then
173
+ "spcsep ino.w#@wds, nlink.w#@wd, #{opath}"
170
174
  else
171
175
  "puts #{opath}"
172
176
  end
@@ -359,7 +363,7 @@ module RbFind
359
363
 
360
364
  def show
361
365
  puts "arguments:"
362
- @args.each { |a| puts_val a }.any? or puts_val "(none)"
366
+ @args.each { |a| puts_val a }.any? or puts_val "(none)"
363
367
  puts "parameters:"
364
368
  @params.each { |k,v| puts_val k, "=", v }.any? or puts_val "(none)"
365
369
  puts "block:"
data/lib/rbfind.rb CHANGED
@@ -8,7 +8,7 @@ require "rbfind/csv"
8
8
 
9
9
  module RbFind
10
10
 
11
- VERSION = "2.6".freeze
11
+ VERSION = "2.7".freeze
12
12
 
13
13
  =begin rdoc
14
14
 
@@ -275,7 +275,7 @@ Sort without case sensitivity and preceding dot:
275
275
 
276
276
  def initialize max_depth: nil, depth_first: nil, follow: nil,
277
277
  sort: true, dirs: false, reverse: false, error: nil, &block
278
- @params = Params.new max_depth, depth_first, follow,
278
+ @params = Params.new max_depth&.nonzero?, depth_first, follow,
279
279
  (sort_parser sort), dirs, reverse, error, block
280
280
  @start = Time.instance_eval { @start = Time.now }
281
281
  Time.instance_eval { @start = Time.now }
@@ -299,13 +299,12 @@ Sort without case sensitivity and preceding dot:
299
299
  if args.empty? then
300
300
  visit_dir Dir::CUR_DIR
301
301
  else
302
- args.each { |base|
303
- handle_error do
304
- File.lstat base rescue raise "`#{base}` doesn't exist."
302
+ step_depth do
303
+ args.each { |base|
305
304
  e = Entry.new base, self
306
- enter e
307
- end
308
- }
305
+ enter e if handle_error do e.stat end
306
+ }
307
+ end
309
308
  end
310
309
  end
311
310
 
@@ -315,10 +314,32 @@ Sort without case sensitivity and preceding dot:
315
314
 
316
315
  private
317
316
 
317
+ def step_depth
318
+ @depth += 1
319
+ yield
320
+ ensure
321
+ @depth -= 1
322
+ end
323
+
318
324
  def enter elem
319
325
  c_, @current = @current, elem
320
326
  @count += 1
321
- visit_depth
327
+ if @params.depth_first then
328
+ enter_dir
329
+ begin
330
+ call_block
331
+ rescue Prune
332
+ handle_error do
333
+ raise "#{self.class}: prune with :depth_first is pointless."
334
+ end
335
+ end
336
+ else
337
+ begin
338
+ call_block
339
+ enter_dir if @current.path
340
+ rescue Prune
341
+ end
342
+ end
322
343
  ensure
323
344
  @current = c_
324
345
  end
@@ -327,22 +348,14 @@ Sort without case sensitivity and preceding dot:
327
348
  return if @params.max_depth and @params.max_depth == @depth
328
349
  list = (Dir.new dir).children.map { |f| Entry.new f, self }
329
350
  @params.sort.call list
330
- @params.reverse and list.reverse!
331
- @params.dirs and list = list.partition { |e| e.rstat.directory? }.flatten
332
- begin
333
- @depth += 1
334
- list.each { |e| enter e }
335
- ensure
336
- @depth -= 1
351
+ list.reverse! if @params.reverse
352
+ if @params.dirs then
353
+ list = list.partition { |e| e.rstat.directory? rescue nil }
354
+ list.reverse! if @params.depth_first
355
+ list.flatten!
337
356
  end
338
- end
339
-
340
- def visit_depth
341
- if @params.depth_first then
342
- enter_dir
343
- call_block
344
- else
345
- call_block and enter_dir
357
+ step_depth do
358
+ list.each { |e| enter e }
346
359
  end
347
360
  end
348
361
 
@@ -363,9 +376,7 @@ Sort without case sensitivity and preceding dot:
363
376
  @current.instance_eval &@params.block
364
377
  rescue Done
365
378
  end
366
- @current.path
367
379
  end
368
- rescue Prune
369
380
  end
370
381
 
371
382
  def handle_error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfind
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.6'
4
+ version: '2.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A replacement for the standard UNIX command find.