remove deprecated delete_lbry_file, move file deletion to lbry_file_manager

This commit is contained in:
Jack Robison 2017-03-06 17:19:05 -05:00
parent 4f9b5c4624
commit 7ad46e70be
3 changed files with 54 additions and 64 deletions

View file

@ -17,6 +17,7 @@ at anytime.
* Change file filter `uri` to `name` and return field `lbry_uri` to `name` * Change file filter `uri` to `name` and return field `lbry_uri` to `name`
* Refactor file_list, add `full_status` argument to populate resource intensive fields * Refactor file_list, add `full_status` argument to populate resource intensive fields
* Remove deprecated file commands: `get_lbry_files`, `get_lbry_file`, and `file_get` * Remove deprecated file commands: `get_lbry_files`, `get_lbry_file`, and `file_get`
* Remove deprecated `delete_lbry_file` command
### Fixed ### Fixed
* *

View file

@ -190,13 +190,10 @@ class EncryptedFileManager(object):
file_name) file_name)
defer.returnValue(lbry_file) defer.returnValue(lbry_file)
def delete_lbry_file(self, lbry_file): @defer.inlineCallbacks
for l in self.lbry_files: def delete_lbry_file(self, lbry_file, delete_file=False):
if l == lbry_file: if lbry_file not in self.lbry_files:
lbry_file = l raise ValueError("Could not find that LBRY file")
break
else:
return defer.fail(Failure(ValueError("Could not find that LBRY file")))
def wait_for_finished(count=2): def wait_for_finished(count=2):
if count <= 0 or lbry_file.saving_status is False: if count <= 0 or lbry_file.saving_status is False:
@ -204,19 +201,29 @@ class EncryptedFileManager(object):
else: else:
return task.deferLater(reactor, 1, wait_for_finished, count=count - 1) return task.deferLater(reactor, 1, wait_for_finished, count=count - 1)
def ignore_stopped(err): full_path = os.path.join(lbry_file.download_directory, lbry_file.file_name)
err.trap(AlreadyStoppedError, CurrentlyStoppingError)
return wait_for_finished()
d = lbry_file.stop() try:
d.addErrback(ignore_stopped) yield lbry_file.stop()
except (AlreadyStoppedError, CurrentlyStoppingError):
yield wait_for_finished()
def remove_from_list(): self.lbry_files.remove(lbry_file)
self.lbry_files.remove(lbry_file)
d.addCallback(lambda _: remove_from_list()) yield self._delete_lbry_file_options(lbry_file.rowid)
d.addCallback(lambda _: self._delete_lbry_file_options(lbry_file.rowid))
return d yield lbry_file.delete_data()
stream_count = yield self.get_count_for_stream_hash(lbry_file.stream_hash)
if stream_count == 0:
yield self.stream_info_manager.delete_stream(lbry_file.stream_hash)
else:
log.warning("Can't delete stream info for %s, count is %i", lbry_file.stream_hash,
stream_count)
if delete_file and os.path.isfile(full_path):
os.remove(full_path)
defer.returnValue(True)
def toggle_lbry_file_running(self, lbry_file): def toggle_lbry_file_running(self, lbry_file):
"""Toggle whether a stream reader is currently running""" """Toggle whether a stream reader is currently running"""
@ -238,7 +245,8 @@ class EncryptedFileManager(object):
def stop(self): def stop(self):
safe_stop_looping_call(self.lbry_file_reflector) safe_stop_looping_call(self.lbry_file_reflector)
yield defer.DeferredList(list(self._stop_lbry_files())) yield defer.DeferredList(list(self._stop_lbry_files()))
yield self.sql_db.close() if self.sql_db:
yield self.sql_db.close()
self.sql_db = None self.sql_db = None
log.info("Stopped %s", self) log.info("Stopped %s", self)
defer.returnValue(True) defer.returnValue(True)

View file

@ -907,25 +907,6 @@ class Daemon(AuthJSONRPCServer):
helper = _ResolveNameHelper(self, name, force_refresh) helper = _ResolveNameHelper(self, name, force_refresh)
return helper.get_deferred() return helper.get_deferred()
@defer.inlineCallbacks
def _delete_lbry_file(self, lbry_file, delete_file=True):
stream_hash = lbry_file.stream_hash
filename = os.path.join(self.download_directory, lbry_file.file_name)
yield self.lbry_file_manager.delete_lbry_file(lbry_file)
yield lbry_file.delete_data()
stream_count = yield self.lbry_file_manager.get_count_for_stream_hash(stream_hash)
if stream_count == 0:
yield self.stream_info_manager.delete_stream(stream_hash)
else:
log.warning("Can't delete stream info for %s, count is %i", stream_hash, stream_count)
if delete_file:
if os.path.isfile(filename):
os.remove(filename)
log.info("Deleted file %s", filename)
log.info("Deleted stream %s", stream_hash)
defer.returnValue(True)
def _get_or_download_sd_blob(self, blob, sd_hash): def _get_or_download_sd_blob(self, blob, sd_hash):
if blob: if blob:
return self.session.blob_manager.get_blob(blob[0]) return self.session.blob_manager.get_blob(blob[0])
@ -1680,41 +1661,40 @@ class Daemon(AuthJSONRPCServer):
defer.returnValue(response) defer.returnValue(response)
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_delete_lbry_file(self, **kwargs): @defer.inlineCallbacks
"""
DEPRECATED. Use `file_delete` instead
"""
return self.jsonrpc_file_delete(**kwargs)
@AuthJSONRPCServer.auth_required
def jsonrpc_file_delete(self, delete_target_file=True, **kwargs): def jsonrpc_file_delete(self, delete_target_file=True, **kwargs):
""" """
Delete a lbry file Delete a lbry file
Args: Args:
'file_name': downloaded file name, string 'name' (optional): delete files by lbry name,
'sd_hash' (optional): delete files by sd hash,
'file_name' (optional): delete files by the name in the downloads folder,
'stream_hash' (optional): delete files by stream hash,
'claim_id' (optional): delete files by claim id,
'outpoint' (optional): delete files by claim outpoint,
'rowid': (optional): delete file by rowid in the file manager
'delete_target_file' (optional): delete file from downloads folder, defaults to True
if False only the blobs and db entries will be deleted
Returns: Returns:
confirmation message True if deletion was successful, otherwise False
""" """
def _delete_file(f): searchtype, value = get_lbry_file_search_value(kwargs)
if not f: lbry_file = yield self._get_lbry_file(searchtype, value, return_json=False)
return False if not lbry_file:
file_name = f.file_name log.warning("There is no file to delete for '%s'", value)
d = self._delete_lbry_file(f, delete_file=delete_target_file) result = False
d.addCallback(lambda _: "Deleted file: " + file_name)
return d
try:
searchtype, value = get_lbry_file_search_value(kwargs)
except NoValidSearch:
d = defer.fail()
else: else:
d = self._get_lbry_file(searchtype, value, return_json=False) file_name, stream_hash = lbry_file.file_name, lbry_file.stream_hash
d.addCallback(_delete_file) if lbry_file.claim_id in self.streams:
del self.streams[lbry_file.claim_id]
d.addCallback(lambda r: self._render_response(r)) yield self.lbry_file_manager.delete_lbry_file(lbry_file,
return d delete_file=delete_target_file)
log.info("Deleted %s (%s)", file_name, utils.short_hash(stream_hash))
result = True
response = yield self._render_response(result)
defer.returnValue(response)
def jsonrpc_get_est_cost(self, **kwargs): def jsonrpc_get_est_cost(self, **kwargs):
""" """
@ -2577,7 +2557,8 @@ class _DownloadNameHelper(object):
log.warning("lbry://%s timed out, removing from streams", self.name) log.warning("lbry://%s timed out, removing from streams", self.name)
self.remove_from_wait("Timed out") self.remove_from_wait("Timed out")
if self.daemon.streams[self.name].downloader is not None: if self.daemon.streams[self.name].downloader is not None:
yield self.daemon._delete_lbry_file(self.daemon.streams[self.name].downloader) yield self.daemon.lbry_file_manager.delete_lbry_file(
self.daemon.streams[self.name].downloader)
del self.daemon.streams[self.name] del self.daemon.streams[self.name]
raise err raise err