mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 08:11:04 +00:00
Some checks failed
Cachix / Publish Flake (push) Has been cancelled
Check / clippy (push) Has been cancelled
Check / rustfmt (push) Has been cancelled
Check / stylua (push) Has been cancelled
Draft / build-unix (gcc-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-riscv64-linux-gnu, ubuntu-latest, riscv64gc-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-sparc64-linux-gnu, ubuntu-latest, sparc64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Draft / build-unix (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Draft / build-unix (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-windows (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Draft / build-windows (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Draft / build-musl (aarch64-unknown-linux-musl) (push) Has been cancelled
Draft / build-musl (x86_64-unknown-linux-musl) (push) Has been cancelled
Draft / build-snap (amd64, ubuntu-latest) (push) Has been cancelled
Draft / build-snap (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (macos-latest) (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
Test / test (windows-latest) (push) Has been cancelled
Draft / snap (push) Has been cancelled
Draft / draft (push) Has been cancelled
Draft / nightly (push) Has been cancelled
61 lines
1.3 KiB
Lua
61 lines
1.3 KiB
Lua
local M = {}
|
|
|
|
local function stale_cache(file)
|
|
local url = file.url
|
|
local stamp = url.spec.stamp:join(url:hash(true))
|
|
|
|
local fd = fs.access():read(true):open(Url(stamp))
|
|
if not fd then
|
|
return true
|
|
end
|
|
|
|
local sig = fd:read(26)
|
|
ya.drop(fd)
|
|
return sig ~= file.cha:hash(true)
|
|
end
|
|
|
|
function M:fetch(job)
|
|
local updates, unknown, state = {}, {}, {}
|
|
for i, file in ipairs(job.files) do
|
|
if file.cha.is_dummy then
|
|
-- Skip dummy files
|
|
elseif not file.cache then
|
|
unknown[#unknown + 1] = file
|
|
elseif not fs.cha(Url(file.cache)) then
|
|
updates[file.url], state[i] = "vfs/absent", true
|
|
elseif stale_cache(file) then
|
|
updates[file.url], state[i] = "vfs/stale", true
|
|
else
|
|
unknown[#unknown + 1] = file
|
|
end
|
|
end
|
|
|
|
if next(updates) then
|
|
ya.emit("update_mimes", { updates = updates })
|
|
end
|
|
|
|
if #unknown == 0 then
|
|
return state
|
|
else
|
|
return self.fallback_local(job, unknown, state)
|
|
end
|
|
end
|
|
|
|
function M.fallback_local(job, unknown, state)
|
|
local indices = {}
|
|
for i, f in ipairs(job.files) do
|
|
indices[f:hash()] = i
|
|
end
|
|
|
|
local result = require("mime.local"):fetch(ya.dict_merge(job, { files = unknown }))
|
|
for i, f in ipairs(unknown) do
|
|
if type(result) == "table" then
|
|
state[indices[f:hash()]] = result[i]
|
|
else
|
|
state[indices[f:hash()]] = result
|
|
end
|
|
end
|
|
return state
|
|
end
|
|
|
|
return M
|