[#2785] [Extractor] Fix successful claimed extract leaving empty folder
* The main fix here is adding os.environ to the command call otherwise in some configurations the extraction would fail. Was unable to reproduce locally but users confirm this fix works. * Refactored the code to properly report errors if the extract command fails along with actual command output. * Bump version to 0.5.
This commit is contained in:
parent
7e229ceb2f
commit
2d5dce4954
|
@ -11,10 +11,11 @@
|
|||
# See LICENSE for more details.
|
||||
#
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
|
||||
from twisted.internet.utils import getProcessValue
|
||||
from twisted.internet.utils import getProcessOutputAndValue
|
||||
from twisted.python.procutils import which
|
||||
|
||||
import deluge.component as component
|
||||
|
@ -120,40 +121,33 @@ class Core(CorePluginBase):
|
|||
if file_ext_sec and file_ext_sec + file_ext in EXTRACT_COMMANDS:
|
||||
file_ext = file_ext_sec + file_ext
|
||||
elif file_ext not in EXTRACT_COMMANDS or file_ext_sec == '.tar':
|
||||
log.warning("Can't extract file with unknown file type: %s", f["path"])
|
||||
log.debug("Can't extract file with unknown file type: %s", f["path"])
|
||||
continue
|
||||
|
||||
cmd = EXTRACT_COMMANDS[file_ext]
|
||||
|
||||
# Now that we have the cmd, lets run it to extract the files
|
||||
fpath = os.path.join(tid_status["download_location"], os.path.normpath(f["path"]))
|
||||
|
||||
# Get the destination path
|
||||
dest = os.path.normpath(self.config["extract_path"])
|
||||
if self.config["use_name_folder"]:
|
||||
name = tid_status["name"]
|
||||
dest = os.path.join(dest, name)
|
||||
dest = os.path.join(dest, tid_status["name"])
|
||||
|
||||
# Create the destination folder if it doesn't exist
|
||||
if not os.path.exists(dest):
|
||||
try:
|
||||
os.makedirs(dest)
|
||||
except OSError as ex:
|
||||
if not (ex.errno == errno.EEXIST and os.path.isdir(dest)):
|
||||
log.error("Error creating destination folder: %s", ex)
|
||||
return
|
||||
break
|
||||
|
||||
def on_extract_success(result, torrent_id, fpath):
|
||||
# XXX: Emit an event
|
||||
def on_extract(result, torrent_id, fpath):
|
||||
# Check command exit code.
|
||||
if not result[2]:
|
||||
log.info("Extract successful: %s (%s)", fpath, torrent_id)
|
||||
else:
|
||||
log.error("Extract failed: %s (%s) %s", fpath, torrent_id, result[1])
|
||||
|
||||
def on_extract_failed(result, torrent_id, fpath):
|
||||
# XXX: Emit an event
|
||||
log.error("Extract failed: %s (%s)", fpath, torrent_id)
|
||||
|
||||
# Run the command and add some callbacks
|
||||
log.debug("Extracting %s with %s %s to %s", fpath, cmd[0], cmd[1], dest)
|
||||
d = getProcessValue(cmd[0], cmd[1].split() + [str(fpath)], {}, str(dest))
|
||||
d.addCallback(on_extract_success, torrent_id, fpath)
|
||||
d.addErrback(on_extract_failed, torrent_id, fpath)
|
||||
# Run the command and add callback.
|
||||
log.debug("Extracting %s from %s with %s %s to %s", fpath, torrent_id, cmd[0], cmd[1], dest)
|
||||
d = getProcessOutputAndValue(cmd[0], cmd[1].split() + [str(fpath)], os.environ, str(dest))
|
||||
d.addCallback(on_extract, torrent_id, fpath)
|
||||
|
||||
@export
|
||||
def set_config(self, config):
|
||||
|
|
|
@ -16,7 +16,7 @@ from setuptools import find_packages, setup
|
|||
__plugin_name__ = "Extractor"
|
||||
__author__ = "Andrew Resch"
|
||||
__author_email__ = "andrewresch@gmail.com"
|
||||
__version__ = "0.3"
|
||||
__version__ = "0.5"
|
||||
__url__ = "http://deluge-torrent.org"
|
||||
__license__ = "GPLv3"
|
||||
__description__ = "Extract files upon torrent completion"
|
||||
|
|
Loading…
Reference in New Issue