Fix symlink transmission

This commit is contained in:
Kovid Goyal 2021-11-05 13:18:58 +05:30
parent c4b3723372
commit 950edb1110
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 1 deletions

View File

@ -539,7 +539,7 @@ def __init__(self, ftc: FileTransmissionCommand):
self.ttype = ftc.ttype
self.waiting_for_signature = True if self.ttype is TransmissionType.rsync else False
self.transmitted = False
self.stat = os.stat(self.path)
self.stat = os.stat(self.path, follow_symlinks=False)
if stat.S_ISDIR(self.stat.st_mode):
raise TransmissionError(ErrorCode.EINVAL, msg='Cannot send a directory', file_id=self.file_id)
self.compressor: Union[ZlibCompressor, IdentityCompressor] = IdentityCompressor()

View File

@ -190,6 +190,8 @@ def test_file_get(self):
data = os.urandom(16 * 1024)
with open(src, 'wb') as f:
f.write(data)
sl = os.path.join(base, 'src.link')
os.symlink(src, sl)
for compress in ('none', 'zlib'):
ft = FileTransmission()
self.responses = []
@ -203,6 +205,10 @@ def test_file_get(self):
if compress == 'zlib':
received = ZlibDecompressor()(received, True)
self.ae(data, received)
ft.test_responses = []
ft.handle_serialized_command(serialized_cmd(action='file', file_id='sl', name=sl, compression=compress))
received = b''.join(x['data'] for x in ft.test_responses)
self.ae(received.decode('utf-8'), src)
def test_file_put(self):
# send refusal