mirror of
https://github.com/9001/copyparty.git
synced 2026-01-12 15:52:39 -07:00
delete thumbnail-cache if settings change
This commit is contained in:
parent
a1cbac0252
commit
ca6c4deaac
|
|
@ -358,6 +358,7 @@ class ThumbSrv(object):
|
||||||
if not bos.path.exists(inf_path):
|
if not bos.path.exists(inf_path):
|
||||||
with open(inf_path, "wb") as f:
|
with open(inf_path, "wb") as f:
|
||||||
f.write(afsenc(os.path.dirname(abspath)))
|
f.write(afsenc(os.path.dirname(abspath)))
|
||||||
|
self.writevolcfg(histpath)
|
||||||
|
|
||||||
self.busy[tpath] = [cond]
|
self.busy[tpath] = [cond]
|
||||||
do_conv = True
|
do_conv = True
|
||||||
|
|
@ -401,6 +402,47 @@ class ThumbSrv(object):
|
||||||
"ffa": self.fmt_ffa,
|
"ffa": self.fmt_ffa,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def volcfgi(self, vn: VFS) -> str:
|
||||||
|
ret = []
|
||||||
|
zs = "th_dec th_no_webp th_no_jpg"
|
||||||
|
for zs in zs.split(" "):
|
||||||
|
ret.append("%s(%s)\n" % (zs, getattr(self.args, zs)))
|
||||||
|
zs = "th_qv thsize th_spec_p convt"
|
||||||
|
for zs in zs.split(" "):
|
||||||
|
ret.append("%s(%s)\n" % (zs, vn.flags.get(zs)))
|
||||||
|
return "".join(ret)
|
||||||
|
|
||||||
|
def volcfga(self, vn: VFS) -> str:
|
||||||
|
ret = []
|
||||||
|
zs = "q_opus q_mp3"
|
||||||
|
for zs in zs.split(" "):
|
||||||
|
ret.append("%s(%s)\n" % (zs, getattr(self.args, zs)))
|
||||||
|
zs = "aconvt"
|
||||||
|
for zs in zs.split(" "):
|
||||||
|
ret.append("%s(%s)\n" % (zs, vn.flags.get(zs)))
|
||||||
|
return "".join(ret)
|
||||||
|
|
||||||
|
def writevolcfg(self, histpath: str) -> None:
|
||||||
|
try:
|
||||||
|
bos.stat(os.path.join(histpath, "th", "cfg.txt"))
|
||||||
|
bos.stat(os.path.join(histpath, "ac", "cfg.txt"))
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
cfgi = cfga = ""
|
||||||
|
for vn in self.asrv.vfs.all_vols.values():
|
||||||
|
if vn.histpath == histpath:
|
||||||
|
cfgi = self.volcfgi(vn)
|
||||||
|
cfga = self.volcfga(vn)
|
||||||
|
break
|
||||||
|
t = "writing thumbnailer-config %d,%d to %s"
|
||||||
|
self.log(t % (len(cfgi), len(cfga), histpath))
|
||||||
|
chmod = bos.MKD_700 if self.args.free_umask else bos.MKD_755
|
||||||
|
for cfg, cat in ((cfgi, "th"), (cfga, "ac")):
|
||||||
|
bos.makedirs(os.path.join(histpath, cat), vf=chmod)
|
||||||
|
with open(os.path.join(histpath, cat, "cfg.txt"), "wb") as f:
|
||||||
|
f.write(cfg.encode("utf-8"))
|
||||||
|
|
||||||
def wait4ram(self, need: float, ttpath: str) -> None:
|
def wait4ram(self, need: float, ttpath: str) -> None:
|
||||||
ram = self.args.th_ram_max
|
ram = self.args.th_ram_max
|
||||||
if need > ram * 0.99:
|
if need > ram * 0.99:
|
||||||
|
|
@ -1241,6 +1283,28 @@ class ThumbSrv(object):
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
def clean(self, histpath: str) -> int:
|
def clean(self, histpath: str) -> int:
|
||||||
|
cfgi = cfga = ""
|
||||||
|
for vn in self.asrv.vfs.all_vols.values():
|
||||||
|
if vn.histpath == histpath:
|
||||||
|
cfgi = self.volcfgi(vn)
|
||||||
|
cfga = self.volcfga(vn)
|
||||||
|
break
|
||||||
|
for cfg, cat in ((cfgi, "th"), (cfga, "ac")):
|
||||||
|
if not cfg:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
with open(os.path.join(histpath, cat, "cfg.txt"), "rb") as f:
|
||||||
|
oldcfg = f.read().decode("utf-8")
|
||||||
|
except:
|
||||||
|
oldcfg = ""
|
||||||
|
if cfg == oldcfg:
|
||||||
|
continue
|
||||||
|
zs = os.path.join(histpath, cat)
|
||||||
|
if not os.path.exists(zs):
|
||||||
|
continue
|
||||||
|
self.log("thumbnailer-config changed; deleting %s" % (zs,), 3)
|
||||||
|
shutil.rmtree(zs)
|
||||||
|
|
||||||
ret = 0
|
ret = 0
|
||||||
for cat in ["th", "ac"]:
|
for cat in ["th", "ac"]:
|
||||||
top = os.path.join(histpath, cat)
|
top = os.path.join(histpath, cat)
|
||||||
|
|
@ -1299,7 +1363,7 @@ class ThumbSrv(object):
|
||||||
if len(b64) != 24 or len(ts) != 8 or ext not in exts:
|
if len(b64) != 24 or len(ts) != 8 or ext not in exts:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
except:
|
except:
|
||||||
if f != "dir.txt":
|
if f != "dir.txt" and f != "cfg.txt":
|
||||||
self.log("foreign file in thumbs dir: [{}]".format(fp), 1)
|
self.log("foreign file in thumbs dir: [{}]".format(fp), 1)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue