msoulier / tftpy

Pure Python TFTP library
http://tftpy.sf.net
MIT License
170 stars 120 forks source link

'TftpFileNotFoundError' is not processed correctly in TftpContexts.py->TftpContextClientDownload->start() #134

Open LeoWeiLeoWei opened 2 years ago

LeoWeiLeoWei commented 2 years ago
except TftpFileNotFoundError as err:
       # If we received file not found, then we should not save the open
       # output file or we'll be left with a size zero file. Delete it,
       # if it exists.
       log.error("Received File not found error")
       if self.fileobj is not None and not self.filelike_fileobj:
           if os.path.exists(self.fileobj.name):
                log.debug("unlinking output file of %s", self.fileobj.name)
                os.unlink(self.fileobj.name)

       raise

When downloading a file that not exists on TFTP-Server. The local file object has been opened in init(), but not closed yet here. So, when calling os.unlink(), it will raise another exception 'PermissionError'. Please confirm and fix it. Thanks very much.