Fix rclone path name incase it include special characters

fix #1632

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2023-12-11 01:22:21 +02:00
parent 77ba13073b
commit df6b175b31
5 changed files with 32 additions and 104 deletions

View File

@ -346,7 +346,7 @@ UPSTREAM_BRANCH = environ.get("UPSTREAM_BRANCH", "")
if len(UPSTREAM_BRANCH) == 0:
UPSTREAM_BRANCH = "master"
RCLONE_SERVE_URL = environ.get("RCLONE_SERVE_URL", "")
RCLONE_SERVE_URL = environ.get("RCLONE_SERVE_URL", "").rstrip("/")
if len(RCLONE_SERVE_URL) == 0:
RCLONE_SERVE_URL = ""

View File

@ -22,27 +22,9 @@ async def add_rclone_download(listener, path):
remote, listener.link = listener.link.split(":", 1)
listener.link = escape(listener.link.strip("/"))
cmd1 = [
"rclone",
"lsjson",
"--fast-list",
"--stat",
"--no-mimetype",
"--no-modtime",
"--config",
config_path,
f"{remote}:{listener.link}",
]
cmd2 = [
"rclone",
"size",
"--fast-list",
"--json",
"--config",
config_path,
f"{remote}:{listener.link}",
]
res1, res2 = await gather(cmd_exec(cmd1), cmd_exec(cmd2))
cmd1 = f'rclone lsjson --fast-list --stat --no-mimetype --no-modtime --config {config_path} "{remote}:{listener.link}"'
cmd2 = f'rclone size --fast-list --json --config {config_path} "{remote}:{listener.link}"'
res1, res2 = await gather(cmd_exec(cmd1, shell=True), cmd_exec(cmd2, shell=True))
if res1[2] != res2[2] != 0:
if res1[2] != -9:
err = res1[1] or res2[1]

View File

@ -217,20 +217,10 @@ class RcloneList:
self.item_type == itype
elif self.list_status == "rcu":
self.item_type == "--dirs-only"
cmd = [
"rclone",
"lsjson",
self.item_type,
"--fast-list",
"--no-mimetype",
"--no-modtime",
"--config",
self.config_path,
f"{self.remote}{self.path}",
]
cmd = f'rclone lsjson {self.item_type} --fast-list --no-mimetype --no-modtime --config {self.config_path} "{self.remote}{self.path}"'
if self.is_cancelled:
return
res, err, code = await cmd_exec(cmd)
res, err, code = await cmd_exec(cmd, shell=True)
if code not in [0, -9]:
LOGGER.error(
f"While rclone listing. Path: {self.remote}{self.path}. Stderr: {err}"

View File

@ -1,4 +1,4 @@
from asyncio import create_subprocess_exec
from asyncio import create_subprocess_shell
from aiofiles.os import path as aiopath
from aiofiles import open as aiopen
from configparser import ConfigParser
@ -34,28 +34,13 @@ async def rclone_serve_booter():
RcloneServe.clear()
except:
pass
cmd = [
"rclone",
"serve",
"http",
"--config",
"rclone.conf",
"--no-modtime",
"combine:",
"--addr",
f":{config_dict['RCLONE_SERVE_PORT']}",
"--vfs-cache-mode",
"full",
"--vfs-cache-max-age",
"1m0s",
"--buffer-size",
"64M",
]
cmd = f"rclone serve http --config rclone.conf --no-modtime combine: --addr :{config_dict['RCLONE_SERVE_PORT']}"
cmd += " --vfs-cache-mode full --vfs-cache-max-age 1m0s --buffer-size 64M"
if (user := config_dict["RCLONE_SERVE_USER"]) and (
pswd := config_dict["RCLONE_SERVE_PASS"]
):
cmd.extend(("--user", user, "--pass", pswd))
rcs = await create_subprocess_exec(*cmd)
cmd += f' --user "{user}" --pass "{pswd}"'
rcs = await create_subprocess_shell(cmd)
RcloneServe.append(rcs)

View File

@ -1,4 +1,4 @@
from asyncio import create_subprocess_exec, gather
from asyncio import create_subprocess_shell, gather
from asyncio.subprocess import PIPE
from re import findall as re_findall
from json import loads
@ -117,7 +117,7 @@ class RcloneTransferHelper:
return sa_conf_file
async def _start_download(self, cmd, remote_type):
self._proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
self._proc = await create_subprocess_shell(cmd, stdout=PIPE, stderr=PIPE)
_, return_code = await gather(self._progress(), self._proc.wait())
if self._is_cancelled:
@ -187,9 +187,9 @@ class RcloneTransferHelper:
and not config_dict["RCLONE_FLAGS"]
and not self._listener.rcFlags
):
cmd.append("--drive-acknowledge-abuse")
cmd += " --drive-acknowledge-abuse"
elif remote_type != "drive":
cmd.extend(("--retries-sleep", "3s"))
cmd += " --retries-sleep 3s"
await self._start_download(cmd, remote_type)
@ -205,17 +205,8 @@ class RcloneTransferHelper:
epath = f"{remote}:{rc_path}{self._listener.name}"
destination = epath
cmd = [
"rclone",
"lsjson",
"--fast-list",
"--no-mimetype",
"--no-modtime",
"--config",
config_path,
epath,
]
res, err, code = await cmd_exec(cmd)
cmd = f'rclone lsjson --fast-list --no-mimetype --no-modtime --config {config_path} "{epath}"'
res, err, code = await cmd_exec(cmd, shell=True)
if code == 0:
result = loads(res)
@ -235,7 +226,7 @@ class RcloneTransferHelper:
return link, destination
async def _start_upload(self, cmd, remote_type):
self._proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
self._proc = await create_subprocess_shell(cmd, stdout=PIPE, stderr=PIPE)
_, return_code = await gather(self._progress(), self._proc.wait())
if self._is_cancelled:
@ -333,9 +324,9 @@ class RcloneTransferHelper:
and not config_dict["RCLONE_FLAGS"]
and not self._listener.rcFlags
):
cmd.extend(("--drive-chunk-size", "64M", "--drive-upload-cutoff", "32M"))
cmd += " --drive-chunk-size 64M --drive-upload-cutoff 32M"
elif remote_type != "drive":
cmd.extend(("--retries-sleep", "3s"))
cmd += " --retries-sleep 3s"
result = await self._start_upload(cmd, remote_type)
if not result:
@ -353,8 +344,8 @@ class RcloneTransferHelper:
else:
destination = f"{oremote}:{self._listener.name}"
cmd = ["rclone", "link", "--config", oconfig_path, destination]
res, err, code = await cmd_exec(cmd)
cmd = f'rclone link --config {oconfig_path} "{destination}"'
res, err, code = await cmd_exec(cmd, shell=True)
if code == 0:
link = res
@ -391,15 +382,13 @@ class RcloneTransferHelper:
)
if not self._listener.rcFlags and not config_dict["RCLONE_FLAGS"]:
if src_remote_type == "drive" and dst_remote_type != "drive":
cmd.append("--drive-acknowledge-abuse")
cmd += " --drive-acknowledge-abuse"
elif dst_remote_type == "drive" and src_remote_type != "drive":
cmd.extend(
("--drive-chunk-size", "64M", "--drive-upload-cutoff", "32M")
)
cmd += " --drive-chunk-size 64M --drive-upload-cutoff 32M"
elif src_remote_type == "drive":
cmd.extend(("--tpslimit", "3", "--transfers", "3"))
cmd += " --tpslimit 3 --transfers 3"
self._proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
self._proc = await create_subprocess_shell(cmd, stdout=PIPE, stderr=PIPE)
_, return_code = await gather(self._progress(), self._proc.wait())
if self._is_cancelled:
@ -424,8 +413,8 @@ class RcloneTransferHelper:
f"/{self._listener.name}" if dst_path else self._listener.name
)
cmd = ["rclone", "link", "--config", config_path, destination]
res, err, code = await cmd_exec(cmd)
cmd = f'rclone link --config {config_path} "{destination}"'
res, err, code = await cmd_exec(cmd, shell=True)
if self._is_cancelled:
return None, None
@ -441,34 +430,16 @@ class RcloneTransferHelper:
def _getUpdatedCommand(self, config_path, source, destination, method):
ext = "*.{" + ",".join(self.extension_filter) + "}"
cmd = [
"rclone",
method,
"--fast-list",
"--config",
config_path,
"-P",
source,
destination,
"--exclude",
ext,
"--ignore-case",
"--low-level-retries",
"1",
"-M",
"--log-file",
"rlog.txt",
"--log-level",
"DEBUG",
]
cmd = f'rclone {method} --fast-list --config {config_path} -P "{source}" "{destination}" --exclude "{ext}"'
cmd += " --ignore-case --low-level-retries 1 -M --log-file rlog.txt --log-level DEBUG"
if rcflags := self._listener.rcFlags or config_dict["RCLONE_FLAGS"]:
rcflags = rcflags.split("|")
for flag in rcflags:
if ":" in flag:
key, value = map(str.strip, flag.split(":", 1))
cmd.extend((key, value))
cmd += f' {key} "{value}"'
elif len(flag) > 0:
cmd.append(flag.strip())
cmd += f" {flag.strip()}"
return cmd
@staticmethod