refactor wait_on_write stopping condition
This commit is contained in:
parent
acef10e848
commit
e69de47daf
1 changed files with 11 additions and 3 deletions
|
@ -2417,13 +2417,17 @@ class _DownloadNameHelper(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _wait_for_write(self):
|
def _wait_for_write(self):
|
||||||
file_name = self.daemon.streams[self.name].downloader.file_name
|
|
||||||
written_bytes = self.get_written_bytes(file_name)
|
|
||||||
d = defer.succeed(None)
|
d = defer.succeed(None)
|
||||||
if not written_bytes:
|
if not self.has_downloader_wrote():
|
||||||
d.addCallback(lambda _: reactor.callLater(1, self._wait_for_write))
|
d.addCallback(lambda _: reactor.callLater(1, self._wait_for_write))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def has_downloader_wrote(self):
|
||||||
|
downloader = self.daemon.streams[self.name].downloader
|
||||||
|
if not downloader:
|
||||||
|
return False
|
||||||
|
return self.get_written_bytes(downloader.file_name)
|
||||||
|
|
||||||
def _wait_on_lbry_file(self, f):
|
def _wait_on_lbry_file(self, f):
|
||||||
written_bytes = self.get_written_bytes(f.file_name)
|
written_bytes = self.get_written_bytes(f.file_name)
|
||||||
if written_bytes:
|
if written_bytes:
|
||||||
|
@ -2433,6 +2437,10 @@ class _DownloadNameHelper(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def get_written_bytes(self, file_name):
|
def get_written_bytes(self, file_name):
|
||||||
|
"""Returns the number of bytes written to `file_name`.
|
||||||
|
|
||||||
|
Returns False if there were issues reading `file_name`.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
file_path = os.path.join(self.download_directory, file_name)
|
file_path = os.path.join(self.download_directory, file_name)
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
|
|
Loading…
Add table
Reference in a new issue