diskcatalog 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b472547e057c9be023aff84991ecefb6a3d85d1010e7de9d27420b3aed32f2eb
4
- data.tar.gz: dbd3f42b6f63b554827007a98373c52372d3caaddcdc0e4a1a24517e78085967
3
+ metadata.gz: fecee62476c7ba3617e40c7508c6e89c1f7fd66f18c87b5e2b18d17b443275aa
4
+ data.tar.gz: ab1b8549fd18d8770b0e8919a4e2196bc0731c188b503fbbd5fa8bf76b378038
5
5
  SHA512:
6
- metadata.gz: df21bf04899b92bd001afad66f84e71517012ef0e24f8bf67e605ac6d8c4f7e2416ead0fa6519f64422f60cc9b84ee8cf1b6302bce892a584f3650202bd6768c
7
- data.tar.gz: 74ef4bc98b74c718040fd23642f03eb4a5e713267da7774a54f830fd72ba4f9434c374822894e8177f58015e8115d79f8717f3d73897045ced9ee8f425fc8d84
6
+ metadata.gz: f407c0a3853b19894ed9f99332e9c88e2e51b9ea244ac48154d87385547f663cccccd842b70c12c08881cf20c5846248250ef14271b3bf6e2ea9a048527507a8
7
+ data.tar.gz: 9219b5b01ab1068a8865b95ec6412e05a8f4396dca81a471996d44e455a2c2812ef0177de5cf314e27a411a7334579eaeaadd6d77d457efd70a614bb399ecb00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diskcatalog (0.2.0)
4
+ diskcatalog (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,6 +10,7 @@ GEM
10
10
  rake (13.0.6)
11
11
 
12
12
  PLATFORMS
13
+ arm64-darwin-22
13
14
  x64-mingw32
14
15
  x86_64-darwin-22
15
16
 
@@ -0,0 +1,61 @@
1
+ module MyFind
2
+
3
+ #
4
+ # Calls the associated block with the name of every file and directory listed
5
+ # as arguments, then recursively on their subdirectories, and so on.
6
+ #
7
+ # Returns an enumerator if no block is given.
8
+ #
9
+ # See the +Find+ module documentation for an example.
10
+ #
11
+ def find(*paths, ignore_error: true) # :yield: path
12
+ block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
13
+
14
+ fs_encoding = Encoding.find("filesystem")
15
+
16
+ paths.collect!{|d| raise Errno::ENOENT, d unless File.exist?(d); d.dup}.each do |path|
17
+ path = path.to_path if path.respond_to? :to_path
18
+ enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
19
+ ps = [path]
20
+ while file = ps.shift
21
+ catch(:prune) do
22
+ yield file.dup
23
+ begin
24
+ s = File.lstat(file)
25
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EPERM
26
+ raise unless ignore_error
27
+ next
28
+ end
29
+ if s.directory? then
30
+ begin
31
+ fs = Dir.children(file, encoding: enc)
32
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EPERM
33
+ raise unless ignore_error
34
+ next
35
+ end
36
+ fs.sort!
37
+ fs.reverse_each {|f|
38
+ f = File.join(file, f)
39
+ ps.unshift f
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ nil
46
+ end
47
+
48
+ #
49
+ # Skips the current file or directory, restarting the loop with the next
50
+ # entry. If the current file is a directory, that directory will not be
51
+ # recursively entered. Meaningful only within the block associated with
52
+ # Find::find.
53
+ #
54
+ # See the +Find+ module documentation for an example.
55
+ #
56
+ def prune
57
+ throw :prune
58
+ end
59
+
60
+ module_function :find, :prune
61
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diskcatalog
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/diskcatalog.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "diskcatalog/my_find"
3
4
  require_relative "diskcatalog/version"
4
5
 
5
- require 'find'
6
6
  require 'optparse'
7
7
  require 'fileutils'
8
8
  require 'yaml'
9
9
 
10
+
11
+
10
12
  module Diskcatalog
11
13
  class Error < StandardError; end
12
-
14
+
13
15
  class Config
14
16
  CATALOGDIR = File.expand_path("~/.catalog")
15
17
 
@@ -120,15 +122,20 @@ module Diskcatalog
120
122
  raise RuntimeError
121
123
  end
122
124
  out = File.open(@opt.output_files, "w:utf-8")
123
- Find.find(@opt.dir, ignore_error: true) do |f|
124
- if FileTest.file?(f)
125
- size = File.size(f)
126
- mtime = File.mtime(f).strftime("%Y-%m-%d")
127
- out.puts "#{f}\t#{size}\t#{mtime}"
128
- elsif FileTest.directory?(f)
129
- STDERR.puts f
130
- end
131
- end
125
+ begin
126
+ MyFind.find(@opt.dir, ignore_error: true) do |f|
127
+ if FileTest.file?(f)
128
+ size = File.size(f)
129
+ mtime = File.mtime(f).strftime("%Y-%m-%d")
130
+ out.puts "#{f}\t#{size}\t#{mtime}"
131
+ elsif FileTest.directory?(f)
132
+ STDERR.puts f
133
+ end
134
+ end
135
+ rescue => e
136
+ p e.class
137
+ puts e.message
138
+ end
132
139
  out.close if out
133
140
  end
134
141
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskcatalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - src
@@ -33,6 +33,7 @@ files:
33
33
  - exe/diskcatalog
34
34
  - exe/mkcat
35
35
  - lib/diskcatalog.rb
36
+ - lib/diskcatalog/my_find.rb
36
37
  - lib/diskcatalog/version.rb
37
38
  - run_mkcat.cmd
38
39
  - run_mkcat.sh