mirror of
https://github.com/derrod/legendary.git
synced 2026-08-22 16:34:52 +00:00
feat: support create symlink
This commit is contained in:
parent
7490e78855
commit
e2740782bb
|
|
@ -344,6 +344,10 @@ class DLManager(Process):
|
|||
# skip unchanged and empty files
|
||||
if current_file.filename in mc.unchanged:
|
||||
continue
|
||||
elif current_file.symlink_target:
|
||||
self.tasks.append(FileTask(current_file.filename, old_file=current_file.symlink_target,
|
||||
flags=TaskFlags.CREATE_SYMLINK))
|
||||
continue
|
||||
elif not current_file.chunk_parts:
|
||||
self.tasks.append(FileTask(current_file.filename, flags=TaskFlags.CREATE_EMPTY_FILE))
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -205,6 +205,29 @@ class FileWorker(Process):
|
|||
|
||||
if j.flags & TaskFlags.CREATE_EMPTY_FILE: # just create an empty file
|
||||
open(full_path, 'a').close()
|
||||
self.o_q.put(WriterTaskResult(success=True, **j.__dict__))
|
||||
continue
|
||||
if j.flags & TaskFlags.CREATE_SYMLINK:
|
||||
if current_file:
|
||||
logger.warning('Trying to create symlink without closing first!')
|
||||
current_file.close()
|
||||
current_file = None
|
||||
|
||||
try:
|
||||
os.symlink(j.old_file, full_path)
|
||||
except FileExistsError:
|
||||
try:
|
||||
os.remove(full_path)
|
||||
os.symlink(j.old_file, full_path)
|
||||
except OSError as e:
|
||||
logger.error(f'Creating symlink failed: {e!r}')
|
||||
self.o_q.put(WriterTaskResult(success=False, **j.__dict__))
|
||||
continue
|
||||
except OSError as e:
|
||||
logger.error(f'Creating symlink failed: {e!r}')
|
||||
self.o_q.put(WriterTaskResult(success=False, **j.__dict__))
|
||||
continue
|
||||
|
||||
self.o_q.put(WriterTaskResult(success=True, **j.__dict__))
|
||||
continue
|
||||
elif j.flags & TaskFlags.OPEN_FILE:
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ class TaskFlags(Flag):
|
|||
CLOSE_FILE = auto()
|
||||
DELETE_FILE = auto()
|
||||
CREATE_EMPTY_FILE = auto()
|
||||
CREATE_SYMLINK = auto()
|
||||
RENAME_FILE = auto()
|
||||
RELEASE_MEMORY = auto()
|
||||
MAKE_EXECUTABLE = auto()
|
||||
|
|
|
|||
Loading…
Reference in a new issue