feat: support create symlink

This commit is contained in:
kPherox 2026-08-21 14:15:50 +09:00
parent 7490e78855
commit e2740782bb
No known key found for this signature in database
GPG key ID: C04751C2BFA2F62D
3 changed files with 28 additions and 0 deletions

View file

@ -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

View file

@ -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:

View 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()