rufio 1.6.0 → 2.0.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/CHANGELOG.md +49 -0
- data/README.md +17 -10
- data/README_ja.md +17 -9
- data/SECURITY.md +14 -6
- data/docs/csv_cell_preview_design_ja.md +682 -0
- data/docs/guide.md +109 -47
- data/docs/guide_ja.md +110 -48
- data/docs/image_preview_design_ja.md +335 -0
- data/docs/native_fuzzy_search_design_ja.md +2 -2
- data/examples/config.rb +23 -0
- data/info/help.md +32 -27
- data/info/keybindings.md +42 -12
- data/info/welcome.md +4 -6
- data/lib/rufio/background_status.rb +7 -0
- data/lib/rufio/bookmark_controller.rb +0 -45
- data/lib/rufio/clipboard.rb +162 -0
- data/lib/rufio/command_locator.rb +49 -0
- data/lib/rufio/config.rb +7 -2
- data/lib/rufio/config_loader.rb +56 -21
- data/lib/rufio/csv_table_source.rb +125 -0
- data/lib/rufio/encoding_detector.rb +152 -0
- data/lib/rufio/file_operation_controller.rb +41 -0
- data/lib/rufio/file_preview.rb +92 -19
- data/lib/rufio/graphics_layer.rb +223 -0
- data/lib/rufio/health_checker.rb +27 -10
- data/lib/rufio/help_menu.rb +16 -11
- data/lib/rufio/image_preview_view.rb +421 -0
- data/lib/rufio/image_source.rb +158 -0
- data/lib/rufio/keybind_handler.rb +21 -35
- data/lib/rufio/kitty_graphics.rb +128 -0
- data/lib/rufio/native/aarch64-linux-gnu/librufio_zig.so +0 -0
- data/lib/rufio/native/aarch64-linux-musl/librufio_zig.so +0 -0
- data/lib/rufio/native/aarch64-macos/librufio_zig.dylib +0 -0
- data/lib/rufio/native/aarch64-windows/rufio_zig.dll +0 -0
- data/lib/rufio/native/x86_64-linux-gnu/librufio_zig.so +0 -0
- data/lib/rufio/native/x86_64-linux-musl/librufio_zig.so +0 -0
- data/lib/rufio/native/x86_64-macos/librufio_zig.dylib +0 -0
- data/lib/rufio/native/x86_64-windows/rufio_zig.dll +0 -0
- data/lib/rufio/native_content_search.rb +1 -1
- data/lib/rufio/native_image.rb +177 -0
- data/lib/rufio/native_scanner_zig.rb +22 -0
- data/lib/rufio/navigation_controller.rb +47 -16
- data/lib/rufio/preview_registry.rb +86 -0
- data/lib/rufio/preview_view.rb +363 -0
- data/lib/rufio/renderer.rb +8 -8
- data/lib/rufio/screen.rb +33 -0
- data/lib/rufio/search_prompt.rb +50 -0
- data/lib/rufio/{global_search.rb → search_screen.rb} +41 -14
- data/lib/rufio/sheet_picker.rb +87 -0
- data/lib/rufio/sqlite_table_source.rb +205 -0
- data/lib/rufio/tab_mode_manager.rb +1 -3
- data/lib/rufio/table_cursor.rb +117 -0
- data/lib/rufio/table_document.rb +261 -0
- data/lib/rufio/table_layout.rb +231 -0
- data/lib/rufio/table_preview_view.rb +376 -0
- data/lib/rufio/table_query.rb +240 -0
- data/lib/rufio/table_source.rb +46 -0
- data/lib/rufio/terminal_graphics.rb +168 -0
- data/lib/rufio/terminal_ui.rb +63 -111
- data/lib/rufio/text_utils.rb +27 -0
- data/lib/rufio/ui_renderer.rb +379 -16
- data/lib/rufio/version.rb +1 -1
- data/lib/rufio/xlsx_table_source.rb +112 -0
- data/lib/rufio.rb +19 -5
- data/lib_zig/rufio_native/Makefile +6 -4
- data/lib_zig/rufio_native/build.zig +10 -0
- data/lib_zig/rufio_native/src/image.zig +525 -0
- data/lib_zig/rufio_native/src/image_bmp.zig +111 -0
- data/lib_zig/rufio_native/src/image_jpeg.zig +878 -0
- data/lib_zig/rufio_native/src/image_png.zig +561 -0
- data/lib_zig/rufio_native/src/image_resize.zig +170 -0
- data/lib_zig/rufio_native/src/image_test.zig +401 -0
- data/lib_zig/rufio_native/src/main.zig +1 -0
- data/lib_zig/rufio_native/src/search.zig +38 -19
- data/lib_zig/rufio_native/src/search_test.zig +35 -0
- data/lib_zig/rufio_native/src/testdata/alpha.png +0 -0
- data/lib_zig/rufio_native/src/testdata/gradient.bmp +0 -0
- data/lib_zig/rufio_native/src/testdata/gradient.jpg +0 -0
- data/lib_zig/rufio_native/src/testdata/gradient.png +0 -0
- data/retag.sh +4 -4
- metadata +37 -9
- data/lib/rufio/fuzzy_candidate_cache.rb +0 -258
- data/lib/rufio/fuzzy_finder.rb +0 -313
- data/lib/rufio/fuzzy_preview_loader.rb +0 -107
- data/lib/rufio/rga_result_source.rb +0 -89
- data/lib/rufio/search_controller.rb +0 -94
- data/lib_zig/rufio_native/src/main.zig.sync +0 -205
|
@@ -86,3 +86,38 @@ test "extension helpers follow Ruby semantics" {
|
|
|
86
86
|
try std.testing.expectEqualStrings("", search.extname("Makefile"));
|
|
87
87
|
try std.testing.expectEqualStrings(".gz", search.extname("a.tar.gz"));
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
test "counts newlines across large chunks without overflow" {
|
|
91
|
+
const buf = try std.testing.allocator.alloc(u8, 300 * 1024);
|
|
92
|
+
defer std.testing.allocator.free(buf);
|
|
93
|
+
@memset(buf, '\n');
|
|
94
|
+
try std.testing.expectEqual(@as(usize, 300 * 1024), search.countNewlines(buf));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
test "Job.initIn writes the sentinel before taking a sentinel slice" {
|
|
98
|
+
// 未初期化のメモリ(0xAA)に組み立てる。終端 NUL を書く前に path() の
|
|
99
|
+
// [:0] スライスを作っていると、安全チェック付きビルドで sentinel mismatch になる
|
|
100
|
+
const parent = "/tmp/rufio-dir";
|
|
101
|
+
const name = "entry.txt";
|
|
102
|
+
const bytes = search.Job.sizeFor(parent, name);
|
|
103
|
+
const mem = try std.testing.allocator.alignedAlloc(u8, .of(search.Job), bytes);
|
|
104
|
+
defer std.testing.allocator.free(mem);
|
|
105
|
+
@memset(mem, 0xAA);
|
|
106
|
+
|
|
107
|
+
const job = search.Job.initIn(mem.ptr, 3, parent, name);
|
|
108
|
+
try std.testing.expectEqualStrings(parent ++ "/" ++ name, job.path());
|
|
109
|
+
try std.testing.expectEqual(@as(u8, 0), job.path().ptr[job.len]);
|
|
110
|
+
try std.testing.expectEqual(@as(u32, 3), job.root);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
test "Job.initIn handles an empty name" {
|
|
114
|
+
const parent = "/tmp/rufio-root";
|
|
115
|
+
const bytes = search.Job.sizeFor(parent, "");
|
|
116
|
+
const mem = try std.testing.allocator.alignedAlloc(u8, .of(search.Job), bytes);
|
|
117
|
+
defer std.testing.allocator.free(mem);
|
|
118
|
+
@memset(mem, 0xAA);
|
|
119
|
+
|
|
120
|
+
const job = search.Job.initIn(mem.ptr, 0, parent, "");
|
|
121
|
+
try std.testing.expectEqualStrings(parent, job.path());
|
|
122
|
+
try std.testing.expectEqual(@as(u8, 0), job.path().ptr[job.len]);
|
|
123
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/retag.sh
CHANGED
|
@@ -17,7 +17,7 @@ echo ""
|
|
|
17
17
|
|
|
18
18
|
# 1. ローカルのタグを削除
|
|
19
19
|
echo "1. ローカルタグを削除中..."
|
|
20
|
-
if git tag -d $TAG_NAME; then
|
|
20
|
+
if git tag -d "$TAG_NAME"; then
|
|
21
21
|
echo "✓ ローカルタグを削除しました"
|
|
22
22
|
else
|
|
23
23
|
echo "⚠ ローカルタグが存在しないか、削除に失敗しました"
|
|
@@ -26,7 +26,7 @@ echo ""
|
|
|
26
26
|
|
|
27
27
|
# 2. リモートのタグを削除
|
|
28
28
|
echo "2. リモートタグを削除中..."
|
|
29
|
-
if git push origin :refs/tags/$TAG_NAME; then
|
|
29
|
+
if git push origin ":refs/tags/$TAG_NAME"; then
|
|
30
30
|
echo "✓ リモートタグを削除しました"
|
|
31
31
|
else
|
|
32
32
|
echo "⚠ リモートタグの削除に失敗しました(存在しない可能性があります)"
|
|
@@ -35,7 +35,7 @@ echo ""
|
|
|
35
35
|
|
|
36
36
|
# 3. タグを再作成
|
|
37
37
|
echo "3. タグを再作成中..."
|
|
38
|
-
if git tag $TAG_NAME; then
|
|
38
|
+
if git tag "$TAG_NAME"; then
|
|
39
39
|
echo "✓ タグを再作成しました"
|
|
40
40
|
else
|
|
41
41
|
echo "✗ タグの再作成に失敗しました"
|
|
@@ -45,7 +45,7 @@ echo ""
|
|
|
45
45
|
|
|
46
46
|
# 4. タグをプッシュ
|
|
47
47
|
echo "4. タグをプッシュ中..."
|
|
48
|
-
if git push origin
|
|
48
|
+
if git push origin "refs/tags/$TAG_NAME"; then
|
|
49
49
|
echo "✓ タグをプッシュしました"
|
|
50
50
|
echo ""
|
|
51
51
|
echo "🎉 完了!GitHub Actionsが実行されます。"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rufio
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- masisz
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: io-console
|
|
@@ -237,9 +237,11 @@ files:
|
|
|
237
237
|
- docs/CHANGELOG_v0.80.0.md
|
|
238
238
|
- docs/CHANGELOG_v0.9.0.md
|
|
239
239
|
- docs/architecture_concurrency_ja_v0.82.1.md
|
|
240
|
+
- docs/csv_cell_preview_design_ja.md
|
|
240
241
|
- docs/fast_zip_design_ja.md
|
|
241
242
|
- docs/guide.md
|
|
242
243
|
- docs/guide_ja.md
|
|
244
|
+
- docs/image_preview_design_ja.md
|
|
243
245
|
- docs/native_fuzzy_search_design_ja.md
|
|
244
246
|
- examples/bookmarks.yml
|
|
245
247
|
- examples/config.rb
|
|
@@ -260,41 +262,45 @@ files:
|
|
|
260
262
|
- lib/rufio/bookmark_manager.rb
|
|
261
263
|
- lib/rufio/bookmark_storage.rb
|
|
262
264
|
- lib/rufio/builtin_commands.rb
|
|
265
|
+
- lib/rufio/clipboard.rb
|
|
263
266
|
- lib/rufio/color_helper.rb
|
|
264
267
|
- lib/rufio/command_completion.rb
|
|
265
268
|
- lib/rufio/command_history.rb
|
|
269
|
+
- lib/rufio/command_locator.rb
|
|
266
270
|
- lib/rufio/command_logger.rb
|
|
267
271
|
- lib/rufio/command_mode.rb
|
|
268
272
|
- lib/rufio/command_mode_ui.rb
|
|
269
273
|
- lib/rufio/config.rb
|
|
270
274
|
- lib/rufio/config_loader.rb
|
|
275
|
+
- lib/rufio/csv_table_source.rb
|
|
271
276
|
- lib/rufio/dialog_renderer.rb
|
|
272
277
|
- lib/rufio/dialog_support.rb
|
|
273
278
|
- lib/rufio/directory_listing.rb
|
|
274
279
|
- lib/rufio/document_text_extractor.rb
|
|
275
280
|
- lib/rufio/dsl_command.rb
|
|
276
281
|
- lib/rufio/dsl_command_loader.rb
|
|
282
|
+
- lib/rufio/encoding_detector.rb
|
|
277
283
|
- lib/rufio/file_opener.rb
|
|
278
284
|
- lib/rufio/file_operation_controller.rb
|
|
279
285
|
- lib/rufio/file_operations.rb
|
|
280
286
|
- lib/rufio/file_preview.rb
|
|
281
287
|
- lib/rufio/filter_manager.rb
|
|
282
288
|
- lib/rufio/fuzzy_candidate_block.rb
|
|
283
|
-
- lib/rufio/fuzzy_candidate_cache.rb
|
|
284
289
|
- lib/rufio/fuzzy_file_source.rb
|
|
285
|
-
- lib/rufio/fuzzy_finder.rb
|
|
286
|
-
- lib/rufio/fuzzy_preview_loader.rb
|
|
287
290
|
- lib/rufio/fuzzy_search.rb
|
|
288
291
|
- lib/rufio/fuzzy_search_session.rb
|
|
289
|
-
- lib/rufio/
|
|
292
|
+
- lib/rufio/graphics_layer.rb
|
|
290
293
|
- lib/rufio/health_checker.rb
|
|
291
294
|
- lib/rufio/help_menu.rb
|
|
295
|
+
- lib/rufio/image_preview_view.rb
|
|
296
|
+
- lib/rufio/image_source.rb
|
|
292
297
|
- lib/rufio/info_notice.rb
|
|
293
298
|
- lib/rufio/interpreter_resolver.rb
|
|
294
299
|
- lib/rufio/job_manager.rb
|
|
295
300
|
- lib/rufio/job_mode.rb
|
|
296
301
|
- lib/rufio/key_input.rb
|
|
297
302
|
- lib/rufio/keybind_handler.rb
|
|
303
|
+
- lib/rufio/kitty_graphics.rb
|
|
298
304
|
- lib/rufio/local_script_scanner.rb
|
|
299
305
|
- lib/rufio/logger.rb
|
|
300
306
|
- lib/rufio/multibyte_input_reader.rb
|
|
@@ -307,6 +313,7 @@ files:
|
|
|
307
313
|
- lib/rufio/native/x86_64-macos/librufio_zig.dylib
|
|
308
314
|
- lib/rufio/native/x86_64-windows/rufio_zig.dll
|
|
309
315
|
- lib/rufio/native_content_search.rb
|
|
316
|
+
- lib/rufio/native_image.rb
|
|
310
317
|
- lib/rufio/native_scanner.rb
|
|
311
318
|
- lib/rufio/native_scanner_zig.rb
|
|
312
319
|
- lib/rufio/native_zip.rb
|
|
@@ -314,26 +321,38 @@ files:
|
|
|
314
321
|
- lib/rufio/notification_manager.rb
|
|
315
322
|
- lib/rufio/parallel_scanner.rb
|
|
316
323
|
- lib/rufio/path_jump.rb
|
|
324
|
+
- lib/rufio/preview_registry.rb
|
|
325
|
+
- lib/rufio/preview_view.rb
|
|
317
326
|
- lib/rufio/rakefile_parser.rb
|
|
318
327
|
- lib/rufio/renderer.rb
|
|
319
|
-
- lib/rufio/rga_result_source.rb
|
|
320
328
|
- lib/rufio/screen.rb
|
|
321
329
|
- lib/rufio/script_config_loader.rb
|
|
322
330
|
- lib/rufio/script_executor.rb
|
|
323
331
|
- lib/rufio/script_file.rb
|
|
324
332
|
- lib/rufio/script_path_manager.rb
|
|
325
333
|
- lib/rufio/script_runner.rb
|
|
326
|
-
- lib/rufio/
|
|
334
|
+
- lib/rufio/search_prompt.rb
|
|
335
|
+
- lib/rufio/search_screen.rb
|
|
327
336
|
- lib/rufio/selection_manager.rb
|
|
337
|
+
- lib/rufio/sheet_picker.rb
|
|
328
338
|
- lib/rufio/shell_command_completion.rb
|
|
329
339
|
- lib/rufio/shell_init.rb
|
|
340
|
+
- lib/rufio/sqlite_table_source.rb
|
|
330
341
|
- lib/rufio/syntax_highlighter.rb
|
|
331
342
|
- lib/rufio/tab_mode_manager.rb
|
|
343
|
+
- lib/rufio/table_cursor.rb
|
|
344
|
+
- lib/rufio/table_document.rb
|
|
345
|
+
- lib/rufio/table_layout.rb
|
|
346
|
+
- lib/rufio/table_preview_view.rb
|
|
347
|
+
- lib/rufio/table_query.rb
|
|
348
|
+
- lib/rufio/table_source.rb
|
|
332
349
|
- lib/rufio/task_status.rb
|
|
350
|
+
- lib/rufio/terminal_graphics.rb
|
|
333
351
|
- lib/rufio/terminal_ui.rb
|
|
334
352
|
- lib/rufio/text_utils.rb
|
|
335
353
|
- lib/rufio/ui_renderer.rb
|
|
336
354
|
- lib/rufio/version.rb
|
|
355
|
+
- lib/rufio/xlsx_table_source.rb
|
|
337
356
|
- lib/rufio/zip_archive.rb
|
|
338
357
|
- lib/rufio/zip_extractor.rb
|
|
339
358
|
- lib/rufio/zip_writer.rb
|
|
@@ -344,11 +363,20 @@ files:
|
|
|
344
363
|
- lib_zig/rufio_native/src/cli.zig
|
|
345
364
|
- lib_zig/rufio_native/src/fuzzy.zig
|
|
346
365
|
- lib_zig/rufio_native/src/fuzzy_test.zig
|
|
366
|
+
- lib_zig/rufio_native/src/image.zig
|
|
367
|
+
- lib_zig/rufio_native/src/image_bmp.zig
|
|
368
|
+
- lib_zig/rufio_native/src/image_jpeg.zig
|
|
369
|
+
- lib_zig/rufio_native/src/image_png.zig
|
|
370
|
+
- lib_zig/rufio_native/src/image_resize.zig
|
|
371
|
+
- lib_zig/rufio_native/src/image_test.zig
|
|
347
372
|
- lib_zig/rufio_native/src/main.zig
|
|
348
|
-
- lib_zig/rufio_native/src/main.zig.sync
|
|
349
373
|
- lib_zig/rufio_native/src/os.zig
|
|
350
374
|
- lib_zig/rufio_native/src/search.zig
|
|
351
375
|
- lib_zig/rufio_native/src/search_test.zig
|
|
376
|
+
- lib_zig/rufio_native/src/testdata/alpha.png
|
|
377
|
+
- lib_zig/rufio_native/src/testdata/gradient.bmp
|
|
378
|
+
- lib_zig/rufio_native/src/testdata/gradient.jpg
|
|
379
|
+
- lib_zig/rufio_native/src/testdata/gradient.png
|
|
352
380
|
- lib_zig/rufio_native/src/zip.zig
|
|
353
381
|
- retag.sh
|
|
354
382
|
homepage: https://github.com/masisz/rufio
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'thread'
|
|
4
|
-
require_relative 'fuzzy_file_source'
|
|
5
|
-
require_relative 'fuzzy_candidate_block'
|
|
6
|
-
|
|
7
|
-
module Rufio
|
|
8
|
-
# s / / を同じディレクトリで開き直したとき、走査済みの候補一覧を再利用する。
|
|
9
|
-
# 容量(合計候補数・ディレクトリ数)と有効期限で制限し、最近使ったものから残す。
|
|
10
|
-
# 検索インデックスは各セッションのワーカー専有のまま、候補だけを流し直して作り直す。
|
|
11
|
-
# 候補は FuzzyCandidateBlock(表示名を NUL で終端して連結したバイト列)で保持する(1 件 1 Hash より大幅に小さい)。
|
|
12
|
-
# パスが「ルート/表示名」と同じバイト列なら持たず、行を作るときに組み立て直す。
|
|
13
|
-
# 走査がブロックを出した場合はそれをそのまま保存し、再表示するセッションにも同じブロックを渡す(コピーしない)。
|
|
14
|
-
class FuzzyCandidateCache
|
|
15
|
-
# 既定値。利用者は config.rb の FUZZY_SEARCH_CACHE で変更できる(ConfigLoader.fuzzy_search_cache)
|
|
16
|
-
DEFAULT_MAX_ENTRIES = 200_000
|
|
17
|
-
DEFAULT_MAX_ROOTS = 4
|
|
18
|
-
DEFAULT_TTL = 300
|
|
19
|
-
BLOCK_SIZE = 4096
|
|
20
|
-
SEPARATOR = "\0"
|
|
21
|
-
EMPTY = [].freeze
|
|
22
|
-
|
|
23
|
-
# 保存済みの一覧。候補は FuzzyCandidateBlock のまま持ち、再表示するセッションと共有する
|
|
24
|
-
class Entry
|
|
25
|
-
attr_reader :blocks, :errors, :stored_at, :size
|
|
26
|
-
|
|
27
|
-
def initialize(blocks:, errors:, stored_at:)
|
|
28
|
-
@blocks = blocks.freeze
|
|
29
|
-
@size = blocks.sum(&:size)
|
|
30
|
-
@errors = errors
|
|
31
|
-
@stored_at = stored_at
|
|
32
|
-
freeze
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# 全件を行に展開する(展開結果は保持しない)。再表示では使わない
|
|
36
|
-
def rows
|
|
37
|
-
@blocks.flat_map(&:to_a).freeze
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# 候補を詰める。上限を超えたら以降は捨てて nil を返す
|
|
42
|
-
class Packer
|
|
43
|
-
def initialize(root, max_entries)
|
|
44
|
-
@prefix = (root.end_with?(File::SEPARATOR) ? root : root + File::SEPARATOR).b.freeze
|
|
45
|
-
@max_entries = max_entries
|
|
46
|
-
@blocks = []
|
|
47
|
-
@size = 0
|
|
48
|
-
reset
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def overflow?
|
|
52
|
-
@blocks.nil?
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# text と path を持つ行を 1 件詰める
|
|
56
|
-
def add(row)
|
|
57
|
-
return false if overflow?
|
|
58
|
-
|
|
59
|
-
text = row.is_a?(Hash) ? row[:text] : nil
|
|
60
|
-
path = row.is_a?(Hash) ? row[:path] : nil
|
|
61
|
-
return overflow! unless text.is_a?(String) && path.is_a?(String) && @size < @max_entries
|
|
62
|
-
|
|
63
|
-
text = text.dup.force_encoding(Encoding::UTF_8)
|
|
64
|
-
text = text.scrub unless text.valid_encoding?
|
|
65
|
-
bytes = path.b
|
|
66
|
-
if text.include?(SEPARATOR) || bytes.include?(SEPARATOR) || text.bytesize > FuzzyCandidateBlock::MAX_TEXT_BYTES
|
|
67
|
-
return overflow!
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
@encoding ||= path.encoding
|
|
71
|
-
index = @builder.add(text)
|
|
72
|
-
unless path.encoding == @encoding && bytes == @prefix + text.b
|
|
73
|
-
(@exceptions ||= {})[index] = path.frozen? ? path : path.dup.freeze
|
|
74
|
-
end
|
|
75
|
-
@size += 1
|
|
76
|
-
flush if @builder.size >= BLOCK_SIZE
|
|
77
|
-
true
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# 走査が出したブロックは作り直さず、そのまま保存する
|
|
81
|
-
def add_block(block)
|
|
82
|
-
return false if overflow?
|
|
83
|
-
return overflow! if @size + block.size > @max_entries
|
|
84
|
-
|
|
85
|
-
flush
|
|
86
|
-
@blocks << block
|
|
87
|
-
@size += block.size
|
|
88
|
-
true
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def add_batch(batch)
|
|
92
|
-
return add_block(batch) if batch.is_a?(FuzzyCandidateBlock)
|
|
93
|
-
|
|
94
|
-
batch.each { |row| break unless add(row) }
|
|
95
|
-
!overflow?
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def entry(errors, stored_at)
|
|
99
|
-
return nil if overflow?
|
|
100
|
-
|
|
101
|
-
flush
|
|
102
|
-
Entry.new(blocks: @blocks, errors: errors.map { |message| message.to_s.dup.freeze }.freeze, stored_at: stored_at)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
private
|
|
106
|
-
|
|
107
|
-
def overflow!
|
|
108
|
-
@blocks = nil
|
|
109
|
-
@builder = nil
|
|
110
|
-
false
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def flush
|
|
114
|
-
return if @builder.empty?
|
|
115
|
-
|
|
116
|
-
@blocks << @builder.build(FuzzyCandidateBlock::PathRows.new(@prefix, @encoding, @exceptions&.freeze))
|
|
117
|
-
reset
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def reset
|
|
121
|
-
@builder = FuzzyCandidateBlock::Builder.new
|
|
122
|
-
@exceptions = nil
|
|
123
|
-
@encoding = nil
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def initialize(max_entries: DEFAULT_MAX_ENTRIES, max_roots: DEFAULT_MAX_ROOTS, ttl: DEFAULT_TTL, clock: nil)
|
|
128
|
-
@max_entries = max_entries
|
|
129
|
-
@max_roots = max_roots
|
|
130
|
-
@ttl = ttl
|
|
131
|
-
@clock = clock || -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
|
|
132
|
-
@mutex = Mutex.new
|
|
133
|
-
@entries = {} # 挿入順 = 使用順(先頭が最も古い)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def fetch(root)
|
|
137
|
-
key = normalize(root)
|
|
138
|
-
@mutex.synchronize do
|
|
139
|
-
entry = @entries.delete(key)
|
|
140
|
-
return nil unless entry
|
|
141
|
-
return nil if expired?(entry)
|
|
142
|
-
|
|
143
|
-
@entries[key] = entry
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# rows は :text と :path を持つ候補。上限を超える一覧は保存しない
|
|
148
|
-
def store(root, rows, errors: [])
|
|
149
|
-
return false if rows.length > @max_entries
|
|
150
|
-
|
|
151
|
-
key = normalize(root)
|
|
152
|
-
packer = Packer.new(key, @max_entries)
|
|
153
|
-
rows.each { |row| break unless packer.add(row) }
|
|
154
|
-
store_entry(key, packer.entry(errors, @clock.call))
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# RecordingSource が詰め終えた一覧を保存する
|
|
158
|
-
def store_entry(root, entry)
|
|
159
|
-
return false unless entry
|
|
160
|
-
|
|
161
|
-
key = normalize(root)
|
|
162
|
-
@mutex.synchronize do
|
|
163
|
-
@entries.delete(key)
|
|
164
|
-
@entries[key] = entry
|
|
165
|
-
@entries.shift while @entries.length > @max_roots || total_entries > @max_entries
|
|
166
|
-
end
|
|
167
|
-
true
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def delete(root)
|
|
171
|
-
key = normalize(root)
|
|
172
|
-
@mutex.synchronize { @entries.delete(key) }
|
|
173
|
-
nil
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def clear
|
|
177
|
-
@mutex.synchronize { @entries.clear }
|
|
178
|
-
nil
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def size
|
|
182
|
-
@mutex.synchronize do
|
|
183
|
-
@entries.delete_if { |_, entry| expired?(entry) }
|
|
184
|
-
@entries.length
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
# 保存時刻と有効期限の判定に使う時刻(monotonic)
|
|
189
|
-
def now
|
|
190
|
-
@clock.call
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def entry_count
|
|
194
|
-
@mutex.synchronize { total_entries }
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# キャッシュがあれば [再生用ソース, 保存時刻]、なければ [記録付きの走査ソース, nil] を返す。
|
|
198
|
-
# ブロックで走査ソースを差し替えられる(既定は FuzzyFileSource)。
|
|
199
|
-
def source_for(root, native: true)
|
|
200
|
-
entry = fetch(root)
|
|
201
|
-
return [CachedSource.new(entry), entry.stored_at] if entry
|
|
202
|
-
|
|
203
|
-
scan = block_given? ? yield : FuzzyFileSource.new(root, native: native)
|
|
204
|
-
[RecordingSource.new(scan, self, root, @max_entries), nil]
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
private
|
|
208
|
-
|
|
209
|
-
def normalize(root)
|
|
210
|
-
File.expand_path(root.to_s)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def expired?(entry)
|
|
214
|
-
@clock.call - entry.stored_at > @ttl
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def total_entries
|
|
218
|
-
@entries.each_value.sum(&:size)
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
# 保存済みのブロックを順に流し、走査時のエラーも再現する
|
|
222
|
-
class CachedSource
|
|
223
|
-
def initialize(entry)
|
|
224
|
-
@entry = entry
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
def each_batch(cancelled:, on_error:)
|
|
228
|
-
@entry.errors.each { |message| on_error.call(message) }
|
|
229
|
-
@entry.blocks.each do |block|
|
|
230
|
-
break if cancelled.call
|
|
231
|
-
|
|
232
|
-
yield block
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
# 走査結果をそのまま流しつつ記録し、最後まで走査できたときだけ保存する
|
|
238
|
-
class RecordingSource
|
|
239
|
-
def initialize(scan, cache, root, max_entries)
|
|
240
|
-
@scan = scan
|
|
241
|
-
@cache = cache
|
|
242
|
-
@root = root
|
|
243
|
-
@max_entries = max_entries
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
def each_batch(cancelled:, on_error:)
|
|
247
|
-
packer = Packer.new(File.expand_path(@root.to_s), @max_entries)
|
|
248
|
-
errors = []
|
|
249
|
-
recording = ->(message) { errors << message; on_error.call(message) }
|
|
250
|
-
@scan.each_batch(cancelled: cancelled, on_error: recording) do |batch|
|
|
251
|
-
packer.add_batch(batch) unless packer.overflow?
|
|
252
|
-
yield batch
|
|
253
|
-
end
|
|
254
|
-
@cache.store_entry(@root, packer.entry(errors, @cache.now)) unless cancelled.call
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
end
|