fix #955
This commit is contained in:
parent
a85d55f3a8
commit
935ad73d32
@ -13,6 +13,7 @@ from app.log import logger
|
|||||||
from app.modules import _ModuleBase
|
from app.modules import _ModuleBase
|
||||||
from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode
|
from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
from app.utils.string import StringUtils
|
||||||
from app.utils.system import SystemUtils
|
from app.utils.system import SystemUtils
|
||||||
|
|
||||||
lock = Lock()
|
lock = Lock()
|
||||||
@ -53,6 +54,8 @@ class FileTransferModule(_ModuleBase):
|
|||||||
return TransferInfo(success=False,
|
return TransferInfo(success=False,
|
||||||
path=path,
|
path=path,
|
||||||
message="未找到媒体库目录")
|
message="未找到媒体库目录")
|
||||||
|
else:
|
||||||
|
logger.info(f"获取转移目标路径:{target}")
|
||||||
# 转移
|
# 转移
|
||||||
return self.transfer_media(in_path=path,
|
return self.transfer_media(in_path=path,
|
||||||
in_meta=meta,
|
in_meta=meta,
|
||||||
@ -629,7 +632,8 @@ class FileTransferModule(_ModuleBase):
|
|||||||
if in_path:
|
if in_path:
|
||||||
for path in dest_paths:
|
for path in dest_paths:
|
||||||
try:
|
try:
|
||||||
relative = in_path.relative_to(path).as_posix()
|
# 计算in_path和path的公共字符串长度
|
||||||
|
relative = StringUtils.find_common_prefix(str(in_path), str(path))
|
||||||
if len(relative) > max_length:
|
if len(relative) > max_length:
|
||||||
max_length = len(relative)
|
max_length = len(relative)
|
||||||
target_path = path
|
target_path = path
|
||||||
|
@ -656,3 +656,18 @@ class StringUtils:
|
|||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def find_common_prefix(str1: str, str2: str) -> str:
|
||||||
|
if not str1 or not str2:
|
||||||
|
return ''
|
||||||
|
common_prefix = []
|
||||||
|
min_len = min(len(str1), len(str2))
|
||||||
|
|
||||||
|
for i in range(min_len):
|
||||||
|
if str1[i] == str2[i]:
|
||||||
|
common_prefix.append(str1[i])
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
return ''.join(common_prefix)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user