Remove dead WS upload/download code

This commit is contained in:
Leo Vasanko
2026-04-25 02:52:49 +00:00
parent 5a3aa58f27
commit c71efe5c0d
4 changed files with 3 additions and 116 deletions
+1 -42
View File
@@ -1,10 +1,8 @@
import asyncio
import os
import threading
from cista import config
from cista.util import filename
from cista.util.asynclink import AsyncLink
from cista.util.lrucache import LRUCache
@@ -63,34 +61,12 @@ class File:
class FileServer:
async def start(self):
self.alink = AsyncLink()
self.worker = asyncio.get_event_loop().run_in_executor(
None,
self.worker_thread,
self.alink.to_sync,
)
self.cache = LRUCache(File, capacity=10, maxage=5.0)
self.cache_lock = threading.Lock()
self.file_locks: dict[str, threading.Lock] = {}
async def stop(self):
await self.alink.stop()
await self.worker
def worker_thread(self, slink):
try:
for req in slink:
with req as (command, *args):
if command == "upload":
req.set_result(self.upload(*args))
elif command == "upload_info":
req.set_result(self.upload_info(*args))
elif command == "download":
req.set_result(self.download(*args))
else:
raise NotImplementedError(f"Unhandled {command=} {args}")
finally:
self.cache.close()
self.cache.close()
@staticmethod
def _stat_size(path):
@@ -99,15 +75,6 @@ class FileServer:
except FileNotFoundError:
return None
def upload(self, name, pos, data, file_size):
name = filename.sanitize(name)
with self.cache_lock:
f = self.cache[name]
lock = self.file_locks.setdefault(name, threading.Lock())
with lock:
f.write(pos, data, file_size=file_size)
return len(data)
def upload_info(self, name, pos, data, file_size):
name = filename.sanitize(name)
with self.cache_lock:
@@ -123,11 +90,3 @@ class FileServer:
"size_before": size_before,
"size_after": size_after,
}
def download(self, name, start, end):
name = filename.sanitize(name)
with self.cache_lock:
f = self.cache[name]
lock = self.file_locks.setdefault(name, threading.Lock())
with lock:
return f[start:end]