fm 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40f701f7d9cf760dfc9a76c431d47b8f1ddb031b
4
- data.tar.gz: d9c4e22714f8d3b726ecb932e75889df445115db
3
+ metadata.gz: f65eb48c6ca670fb90fbdf816381ff87bf72952c
4
+ data.tar.gz: 6217ce69bb16183e8a6fb73abb17a00f0bf382ef
5
5
  SHA512:
6
- metadata.gz: 1c80d0e806f342edbce81a1e5d7ecc5390cfffdbc4940c4aabc17557862c677a18ecda6e6d790125615b7ac188edabd0e82cd7519acb8e2f97b8a48649734665
7
- data.tar.gz: 17a293a95dc60e18303fb4c71adf32e3896b4307dbf163780af4bf697ac242d25cf31407676e37b2215aaad8be0c0a33f611ad738bfbfae2155a9243602731e5
6
+ metadata.gz: 155faf79df27ffa1a79ee767622e5d600a8db246ff01e61c9004a93c9af8a0de7ee7b7f88547ba35b7f7f80876cd0b4f8df7d907e49e898fee844a62d0cd7b9e
7
+ data.tar.gz: d170cac39c565eca7097b51d1cc565a59622c819b3f10c2b49a46b2b5d7ceecce4351eef9b180072980d1cac6773ea925c3fb473055be3be4c79f8bfb52ae239
@@ -4,11 +4,15 @@ module FM
4
4
  attr_reader :fsize
5
5
  attr_reader :digest
6
6
  attr_reader :path
7
+ attr_accessor :mtime
8
+ attr_accessor :itime
7
9
 
8
- def initialize(fsize, path, digest)
10
+ def initialize(fsize, path, digest, mtime, itime = Time.now)
9
11
  @fsize = fsize
10
12
  @digest = digest
11
13
  @path = path
14
+ @mtime = mtime
15
+ @itime = itime # Last index time.
12
16
  end
13
17
  end
14
18
 
@@ -52,13 +52,55 @@ module FM
52
52
  nskipfiles = 0
53
53
  ndupfiles = 0
54
54
  nfailfiles = 0
55
+ duplist = {}
55
56
  puts "Indexing #{indexpath} ..."
56
57
  t0 = Time.now
57
58
 
59
+ dlist = []
60
+ h.each do |skey, svalue|
61
+ h[skey].each do |dkey, dvalue|
62
+ h[skey][dkey].each do |f|
63
+ fsize = -1
64
+ digest = ""
65
+ fe = File.exists?(f.path)
66
+
67
+ if fe && File.mtime(f.path) == f.mtime
68
+ next
69
+ end
70
+
71
+ if fe
72
+ fsize = File.size(f.path)
73
+ digest = Digest::MD5.hexdigest(File.read(f.path))
74
+ end
75
+ if fsize != f.fsize || digest != f.digest
76
+ dlist.push(f)
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ dlist.each do |f|
83
+ fsize = f.fsize
84
+ path = f.path
85
+ digest = f.digest
86
+
87
+ h[fsize][digest].delete_if { |v| v.path == path }
88
+ if h[fsize][digest].size == 0
89
+ h[fsize].delete(digest)
90
+ if h[fsize].size == 0
91
+ h.delete(fsize)
92
+ end
93
+ end
94
+
95
+ needupdate = true
96
+ end
97
+ dlist = nil
98
+
58
99
  for fpath in Dir.glob("#{indexpath}/**/*", File::FNM_DOTMATCH).select { |e| e.force_encoding("binary"); File.ftype(e) == "file" && has_folder?(".git", e) == false && has_folder?(".hg", e) == false }
59
100
  begin
60
101
  fpath = File.realpath(fpath).force_encoding("binary")
61
102
  fsize = File.size(fpath)
103
+ fmtime = File.mtime(fpath)
62
104
 
63
105
  if fsize == 0
64
106
  nskipfiles += 1
@@ -68,37 +110,34 @@ module FM
68
110
 
69
111
  # Lazy index the file.
70
112
  if h[fsize].nil?
71
- h[fsize] = fpath
113
+ digest = Digest::MD5.hexdigest(File.read(fpath))
114
+ h[fsize] = { digest => [ FMFile.new(fsize, fpath, digest, fmtime) ] }
72
115
  needupdate = true
73
116
  nnewfiles += 1
74
- puts "[NEW]: #{fpath} nil"
117
+ puts "[NEW]: #{fpath} #{digest}"
75
118
  else
76
- if h[fsize].is_a?(String)
77
- p = h[fsize]
78
- if p == fpath
119
+
120
+ h[fsize].values.each do |v|
121
+ if v.any? { |f| f.mtime == fmtime && f.path == fpath }
79
122
  next
80
123
  end
81
-
82
- d = Digest::MD5.hexdigest(File.read(p))
83
- h[fsize] = { d => [ FMFile.new(fsize, p, d) ] }
84
- needupdate = true
85
124
  end
125
+
86
126
  digest = Digest::MD5.hexdigest(File.read(fpath))
87
127
  if h[fsize][digest].nil?
88
- h[fsize][digest] = [ FMFile.new(fsize, fpath, digest) ]
128
+ h[fsize][digest] = [ FMFile.new(fsize, fpath, digest, fmtime) ]
89
129
  needupdate = true
90
130
  nnewfiles += 1
91
131
  puts "[NEW]: #{fpath} #{digest}"
92
132
  elsif h[fsize][digest].size == 1 && h[fsize][digest].first.path == fpath
93
133
  else
94
134
  ndupfiles += 1
95
- puts "[DUP]: #{fpath}"
96
- h[fsize][digest].each do |f|
97
- puts " #{f.path}" if f.path != fpath
135
+ if duplist[digest].nil?
136
+ duplist[digest] = h[fsize][digest]
98
137
  end
99
138
 
100
139
  unless h[fsize][digest].any? { |f| f.path == fpath }
101
- fmfile = FMFile.new(fsize, fpath, digest)
140
+ fmfile = FMFile.new(fsize, fpath, digest, fmtime)
102
141
  h[fsize][digest].push(fmfile)
103
142
  needupdate = true
104
143
  end
@@ -109,6 +148,14 @@ module FM
109
148
  puts "[FAIL]: file=\"#{fpath}\" #{e.message}"
110
149
  end
111
150
  end
151
+
152
+ duplist.values.each do |dup|
153
+ puts "[DUP]: #{dup.first.path}"
154
+ dup[1..-1].each do |f|
155
+ puts " #{f.path}"
156
+ end
157
+ end
158
+
112
159
  t1 = Time.now
113
160
  puts "Indexing completed in #{(t1-t0).round(2)}s."
114
161
 
@@ -1,3 +1,3 @@
1
1
  module FM
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShinYee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler