mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add remove file action
This commit is contained in:
parent
e3f6c88d2c
commit
04f6473f38
@ -19,6 +19,7 @@ from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||
lock = Lock()
|
||||
worker = None
|
||||
RMTREE_ACTION = 'rmtree'
|
||||
UNLINK_ACTION = 'unlink'
|
||||
|
||||
|
||||
def thread_safe(f):
|
||||
@ -35,6 +36,18 @@ def remove_folder(path: str) -> None:
|
||||
_send_command(RMTREE_ACTION, os.path.abspath(path))
|
||||
|
||||
|
||||
@thread_safe
|
||||
def remove_file(path: str) -> None:
|
||||
_send_command(UNLINK_ACTION, os.path.abspath(path))
|
||||
|
||||
|
||||
def unlink(path):
|
||||
with suppress(Exception):
|
||||
import os as oss
|
||||
if oss.path.exists(path):
|
||||
oss.remove(path)
|
||||
|
||||
|
||||
def ensure_worker():
|
||||
global worker
|
||||
if worker is None:
|
||||
@ -79,12 +92,12 @@ else:
|
||||
|
||||
|
||||
def main():
|
||||
ac_map = {RMTREE_ACTION: remove_dir, UNLINK_ACTION: unlink}
|
||||
for line in sys.stdin.buffer:
|
||||
if line:
|
||||
try:
|
||||
cmd = json.loads(line)
|
||||
if cmd['action'] == RMTREE_ACTION:
|
||||
atexit.register(remove_dir, cmd['payload'])
|
||||
atexit.register(ac_map[cmd['action']], cmd['payload'])
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
Loading…
x
Reference in New Issue
Block a user