mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: prevent recursive caching - don't cache files in the cache directory
This commit is contained in:
parent
560a1bf3f9
commit
a1339aad2b
4 changed files with 21 additions and 19 deletions
|
|
@ -1,9 +1,7 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:cache() return ya.cache_file(self.file.url .. tostring(self.file.cha.modified)) end
|
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
local cache = self:cache()
|
local cache = ya.file_cache(self)
|
||||||
ya.image_show(fs.symlink_metadata(cache) and cache or self.file.url, self.area)
|
ya.image_show(fs.symlink_metadata(cache) and cache or self.file.url, self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
end
|
||||||
|
|
@ -11,7 +9,7 @@ end
|
||||||
function M:seek() end
|
function M:seek() end
|
||||||
|
|
||||||
function M:preload()
|
function M:preload()
|
||||||
local cache = self:cache()
|
local cache = ya.file_cache(self)
|
||||||
if fs.symlink_metadata(cache) then
|
if fs.symlink_metadata(cache) then
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:cache() return ya.cache_file(self.file.url .. self.skip .. tostring(self.file.cha.modified)) end
|
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
if self:preload() == 1 then
|
if self:preload() == 1 then
|
||||||
ya.image_show(self:cache(), self.area)
|
ya.image_show(ya.file_cache(self), self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -18,7 +16,7 @@ function M:seek(units)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:preload()
|
function M:preload()
|
||||||
local cache = self:cache()
|
local cache = ya.file_cache(self)
|
||||||
if fs.symlink_metadata(cache) then
|
if fs.symlink_metadata(cache) then
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:cache() return ya.cache_file(self.file.url .. self.skip .. tostring(self.file.cha.modified)) end
|
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
if self:preload() == 1 then
|
if self:preload() == 1 then
|
||||||
ya.image_show(self:cache(), self.area)
|
ya.image_show(ya.file_cache(self), self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -26,7 +24,7 @@ function M:preload()
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
|
|
||||||
local cache = self:cache()
|
local cache = ya.file_cache(self)
|
||||||
if fs.symlink_metadata(cache) then
|
if fs.symlink_metadata(cache) then
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,25 @@ use mlua::{Lua, Table};
|
||||||
use yazi_config::PREVIEW;
|
use yazi_config::PREVIEW;
|
||||||
|
|
||||||
use super::Utils;
|
use super::Utils;
|
||||||
use crate::bindings::{Cast, Url};
|
use crate::bindings::{Cast, FileRef, Url};
|
||||||
|
|
||||||
impl Utils {
|
impl Utils {
|
||||||
pub(super) fn cache(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
pub(super) fn cache(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
||||||
ya.set(
|
ya.set(
|
||||||
"cache_file",
|
"file_cache",
|
||||||
lua.create_function(|lua, data: mlua::String| {
|
lua.create_function(|lua, t: Table| {
|
||||||
Url::cast(
|
let file: FileRef = t.get("file")?;
|
||||||
lua,
|
if file.url.parent() == Some(&PREVIEW.cache_dir) {
|
||||||
PREVIEW.cache_dir.join(format!("{:x}", Md5::new_with_prefix(data).finalize())),
|
return Ok(None);
|
||||||
)
|
}
|
||||||
|
|
||||||
|
let hex = {
|
||||||
|
let mut digest = Md5::new_with_prefix(file.url.as_os_str().as_encoded_bytes());
|
||||||
|
digest.update(&format!("//{:?}//{}", file.cha.modified, t.get("skip").unwrap_or(0)));
|
||||||
|
format!("{:x}", digest.finalize())
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(Url::cast(lua, PREVIEW.cache_dir.join(hex))).transpose()
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue