Remove dead WS upload/download code
This commit is contained in:
+1
-42
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user