fontist 3.0.25 → 3.0.26
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/lib/fontist/system_index.rb +71 -6
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 215b46de2d4feadfbd1d3644dd060cc5afdd54afd30ba1f6a50e428c5c2be4ef
|
|
4
|
+
data.tar.gz: 7eea12f0743488fbfbd4c5d924a2bfce06de918aaa9cf4bbc24b92fbe02d937f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93ddd5d5863d137e0ed95f9e8829b2bb84797b7887f8d9a122f8259f920bde832f3d810b1057539504b1f7b584ba7e4d245726943cdcdc1a874c9656c52b125c
|
|
7
|
+
data.tar.gz: 2af73abb7b5d07aa4a5699aa309fbeec7e8053b7944f902a26a7e70804e3ff71c511dda0e0bb68e4e1e7e5f2e841e265eb08c06095de5f8390dd82e312190b79
|
data/lib/fontist/system_index.rb
CHANGED
|
@@ -140,6 +140,33 @@ module Fontist
|
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
+
# Scan metadata for a system index collection, persisted in a
|
|
144
|
+
# companion file beside the index (an index file is a flat entry
|
|
145
|
+
# list and cannot carry scalars). Restoring it across processes is
|
|
146
|
+
# what makes the 30-minute scan threshold and the directory-mtime
|
|
147
|
+
# change check work at all.
|
|
148
|
+
class SystemIndexMetadata < Lutaml::Model::Serializable
|
|
149
|
+
attribute :last_scan_time, :integer, default: -> { 0 }
|
|
150
|
+
attribute :directory_mtimes, :string, collection: true, default: -> { [] }
|
|
151
|
+
|
|
152
|
+
key_value do
|
|
153
|
+
map "last_scan_time", to: :last_scan_time
|
|
154
|
+
map "directory_mtimes", to: :directory_mtimes
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def self.load(path)
|
|
158
|
+
return new unless File.exist?(path)
|
|
159
|
+
|
|
160
|
+
from_yaml(File.read(path))
|
|
161
|
+
rescue Lutaml::Model::Error, Psych::SyntaxError, TypeError
|
|
162
|
+
new
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def save(path)
|
|
166
|
+
File.write(path, to_yaml)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
143
170
|
class SystemIndexFontCollection < Lutaml::Model::Collection
|
|
144
171
|
include Utils::Locking
|
|
145
172
|
|
|
@@ -151,14 +178,40 @@ module Fontist
|
|
|
151
178
|
attribute :directory_mtimes, :string, collection: true, default: -> { [] }
|
|
152
179
|
|
|
153
180
|
key_value do
|
|
181
|
+
# A bare entry list: the scan metadata lives in a companion
|
|
182
|
+
# metadata file (see SystemIndexMetadata), because a flat list
|
|
183
|
+
# cannot carry scalars and lutaml ignores scalar maps declared
|
|
184
|
+
# alongside map_instances
|
|
154
185
|
map_instances to: :fonts
|
|
155
|
-
map "last_scan_time", to: :last_scan_time
|
|
156
|
-
map "directory_mtimes", to: :directory_mtimes
|
|
157
186
|
end
|
|
158
187
|
|
|
159
188
|
# Don't rebuild index more frequently than this (in seconds)
|
|
160
189
|
INDEX_REBUILD_THRESHOLD = 30 * 60 # 30 minutes
|
|
161
190
|
|
|
191
|
+
def metadata_path
|
|
192
|
+
"#{@path}.metadata.yml"
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def persist_metadata
|
|
196
|
+
return unless @path
|
|
197
|
+
|
|
198
|
+
SystemIndexMetadata
|
|
199
|
+
.new(last_scan_time: last_scan_time,
|
|
200
|
+
directory_mtimes: directory_mtimes)
|
|
201
|
+
.save(metadata_path)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def restore_metadata
|
|
205
|
+
return unless @path
|
|
206
|
+
return unless last_scan_time.to_i.zero?
|
|
207
|
+
|
|
208
|
+
meta = SystemIndexMetadata.load(metadata_path)
|
|
209
|
+
return unless meta.last_scan_time.to_i.positive?
|
|
210
|
+
|
|
211
|
+
self.last_scan_time = meta.last_scan_time
|
|
212
|
+
self.directory_mtimes = meta.directory_mtimes
|
|
213
|
+
end
|
|
214
|
+
|
|
162
215
|
def set_path(path)
|
|
163
216
|
@path = path
|
|
164
217
|
end
|
|
@@ -172,12 +225,17 @@ module Fontist
|
|
|
172
225
|
return new.set_content(path, paths_loader) unless File.exist?(path)
|
|
173
226
|
|
|
174
227
|
from_yaml(File.read(path)).set_content(path, paths_loader)
|
|
228
|
+
rescue Lutaml::Model::Error, Psych::SyntaxError, TypeError
|
|
229
|
+
# Corrupt or unreadable index files degrade to an empty
|
|
230
|
+
# collection; the next rebuild rewrites them
|
|
231
|
+
new.set_content(path, paths_loader)
|
|
175
232
|
end
|
|
176
233
|
|
|
177
234
|
def set_content(path, paths_loader)
|
|
178
235
|
tap do |content|
|
|
179
236
|
content.set_path(path)
|
|
180
237
|
content.set_path_loader(paths_loader)
|
|
238
|
+
content.restore_metadata
|
|
181
239
|
end
|
|
182
240
|
end
|
|
183
241
|
|
|
@@ -351,7 +409,8 @@ module Fontist
|
|
|
351
409
|
|
|
352
410
|
def build(forced: false, verbose: false, stats: nil)
|
|
353
411
|
if forced
|
|
354
|
-
return rebuild_with_lock(verbose: verbose, stats: stats
|
|
412
|
+
return rebuild_with_lock(verbose: verbose, stats: stats,
|
|
413
|
+
honor_recent: false)
|
|
355
414
|
end
|
|
356
415
|
|
|
357
416
|
previous_index = load_index
|
|
@@ -372,14 +431,18 @@ module Fontist
|
|
|
372
431
|
|
|
373
432
|
private
|
|
374
433
|
|
|
375
|
-
def rebuild_with_lock(verbose: false, stats: nil)
|
|
434
|
+
def rebuild_with_lock(verbose: false, stats: nil, honor_recent: true)
|
|
376
435
|
# Use file locking to prevent concurrent rebuilds across processes
|
|
377
436
|
lock_path = index_lock_path
|
|
378
437
|
start_time = Time.now
|
|
379
438
|
|
|
380
439
|
lock(lock_path) do
|
|
381
|
-
# Re-check if another process already rebuilt while we waited
|
|
382
|
-
|
|
440
|
+
# Re-check if another process already rebuilt while we waited
|
|
441
|
+
# for lock. Forced rebuilds (add_font, explicit rebuild) carry
|
|
442
|
+
# write intent and must always rescan: honoring the recent
|
|
443
|
+
# rebuild here served the pre-write index and silently dropped
|
|
444
|
+
# the font that triggered the rebuild
|
|
445
|
+
if honor_recent && File.exist?(@path)
|
|
383
446
|
existing = self.class.from_file(path: @path,
|
|
384
447
|
paths_loader: @paths_loader)
|
|
385
448
|
|
|
@@ -407,6 +470,7 @@ module Fontist
|
|
|
407
470
|
self.last_scan_time = Time.now.to_i
|
|
408
471
|
self.directory_mtimes = scan_directory_mtimes.map { |k, v| "#{k}:#{v}" }
|
|
409
472
|
to_file(@path)
|
|
473
|
+
persist_metadata
|
|
410
474
|
|
|
411
475
|
# Show completion message for large collections
|
|
412
476
|
elapsed = Time.now - start_time
|
|
@@ -505,6 +569,7 @@ module Fontist
|
|
|
505
569
|
|
|
506
570
|
# Save to file
|
|
507
571
|
to_file(@path)
|
|
572
|
+
persist_metadata
|
|
508
573
|
end
|
|
509
574
|
|
|
510
575
|
def detect_paths(paths, verbose: false, stats: nil)
|
data/lib/fontist/version.rb
CHANGED
data/lib/fontist.rb
CHANGED
|
@@ -25,6 +25,7 @@ module Fontist
|
|
|
25
25
|
autoload :FontPath, "#{__dir__}/fontist/font_path"
|
|
26
26
|
autoload :FontStyle, "#{__dir__}/fontist/font_style"
|
|
27
27
|
autoload :Fontconfig, "#{__dir__}/fontist/fontconfig"
|
|
28
|
+
autoload :FormatSpec, "#{__dir__}/fontist/format_spec"
|
|
28
29
|
autoload :Formula, "#{__dir__}/fontist/formula"
|
|
29
30
|
autoload :FormulaCollection, "#{__dir__}/fontist/formula"
|
|
30
31
|
autoload :FormulaPicker, "#{__dir__}/fontist/formula_picker"
|