diskcatalog 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/lib/diskcatalog/my_find.rb +61 -0
- data/lib/diskcatalog/version.rb +1 -1
- data/lib/diskcatalog.rb +18 -11
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fecee62476c7ba3617e40c7508c6e89c1f7fd66f18c87b5e2b18d17b443275aa
|
4
|
+
data.tar.gz: ab1b8549fd18d8770b0e8919a4e2196bc0731c188b503fbbd5fa8bf76b378038
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f407c0a3853b19894ed9f99332e9c88e2e51b9ea244ac48154d87385547f663cccccd842b70c12c08881cf20c5846248250ef14271b3bf6e2ea9a048527507a8
|
7
|
+
data.tar.gz: 9219b5b01ab1068a8865b95ec6412e05a8f4396dca81a471996d44e455a2c2812ef0177de5cf314e27a411a7334579eaeaadd6d77d457efd70a614bb399ecb00
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/diskcatalog/version.rb
CHANGED
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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.
|
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
|