@@ -44,24 +44,16 @@ export async function renameItem(fs, oldPath, newPath, userIdOrInfo, userType) {
4444}
4545
4646export async function copyItem ( fs , sourcePath , targetPath , userIdOrInfo , userType , options = { } ) {
47- // 目录判断:用于决定是否走目录级 orchestrator
48- const sourceIsDirectory = isDirectoryPath ( sourcePath ) ;
49-
50- const targetIsDirectory = isDirectoryPath ( targetPath ) ;
51- let effectiveTargetPath = targetPath ;
52- if ( ! sourceIsDirectory && targetIsDirectory ) {
53- const sourceSegments = sourcePath . split ( "/" ) . filter ( Boolean ) ;
54- const sourceFileName = sourceSegments [ sourceSegments . length - 1 ] || "file" ;
55- effectiveTargetPath = `${ normalizePath ( targetPath , true ) } ${ sourceFileName } ` ;
56- }
57-
5847 // 先解析源与目标挂载与驱动,在 FS 层统一做跨存储决策
5948 const sourceCtx = await fs . mountManager . getDriverByPath ( sourcePath , userIdOrInfo , userType ) ;
60- const targetCtx = await fs . mountManager . getDriverByPath ( effectiveTargetPath , userIdOrInfo , userType ) ;
49+ const targetCtx = await fs . mountManager . getDriverByPath ( targetPath , userIdOrInfo , userType ) ;
6150
6251 const { driver : sourceDriver , mount : sourceMount , subPath : sourceSubPath } = sourceCtx ;
6352 const { driver : targetDriver , mount : targetMount , subPath : targetSubPath } = targetCtx ;
6453
54+ // 目录判断:用于决定是否走目录级 orchestrator
55+ const sourceIsDirectory = isDirectoryPath ( sourcePath ) ;
56+
6557 const sameMount = sourceMount . id === targetMount . id ;
6658
6759 // 统一目录自复制防护:同一挂载内,禁止将目录复制到自身或其子目录
@@ -97,16 +89,13 @@ export async function copyItem(fs, sourcePath, targetPath, userIdOrInfo, userTyp
9789 skipped : true ,
9890 reason : "target_exists" ,
9991 source : sourcePath ,
100- target : effectiveTargetPath ,
92+ target : targetPath ,
10193 contentLength : 0 ,
10294 } ;
10395 }
10496 } catch ( checkError ) {
10597 // exists 检查失败时继续复制(降级处理)
106- console . warn (
107- `[copyItem] skipExisting 检查失败 for ${ effectiveTargetPath } :` ,
108- checkError ?. message || checkError ,
109- ) ;
98+ console . warn ( `[copyItem] skipExisting 检查失败 for ${ targetPath } :` , checkError ?. message || checkError ) ;
11099 }
111100 // 标记已检查,下游无需重复检查
112101 options = { ...options , _skipExistingChecked : true } ;
@@ -122,7 +111,7 @@ export async function copyItem(fs, sourcePath, targetPath, userIdOrInfo, userTyp
122111 } ) ;
123112 }
124113
125- const result = await sourceDriver . copyItem ( sourcePath , effectiveTargetPath , {
114+ const result = await sourceDriver . copyItem ( sourcePath , targetPath , {
126115 mount : sourceMount ,
127116 // 保持旧字段,同时补充明确的源/目标子路径,方便驱动精确映射存储路径
128117 subPath : sourceSubPath ,
@@ -136,40 +125,27 @@ export async function copyItem(fs, sourcePath, targetPath, userIdOrInfo, userTyp
136125 ...options ,
137126 } ) ;
138127
139- fs . emitCacheInvalidation ( {
140- mount : sourceMount ,
141- paths : [ sourcePath , effectiveTargetPath ] ,
142- reason : "copy" ,
143- } ) ;
128+ fs . emitCacheInvalidation ( { mount : sourceMount , paths : [ sourcePath , targetPath ] , reason : "copy" } ) ;
144129 return result ;
145130 }
146131
147132 // 2)跨挂载:走通用 orchestrator,支持文件和目录
148133 if ( sourceIsDirectory ) {
149134 // 目录:使用目录级 orchestrator,递归复制目录下所有文件
150135 return await copyDirectoryBetweenDrivers (
151- fs ,
152- sourceCtx ,
153- targetCtx ,
154- sourcePath ,
155- effectiveTargetPath ,
156- userIdOrInfo ,
157- userType ,
158- options ,
159- ) ;
160- }
161-
162- // 文件:使用单文件 orchestrator
163- return await copyBetweenDrivers (
164136 fs ,
165137 sourceCtx ,
166138 targetCtx ,
167139 sourcePath ,
168- effectiveTargetPath ,
140+ targetPath ,
169141 userIdOrInfo ,
170142 userType ,
171143 options ,
172- ) ;
144+ ) ;
145+ }
146+
147+ // 文件:使用单文件 orchestrator
148+ return await copyBetweenDrivers ( fs , sourceCtx , targetCtx , sourcePath , targetPath , userIdOrInfo , userType , options ) ;
173149}
174150
175151export async function batchRemoveItems ( fs , paths , userIdOrInfo , userType ) {
@@ -321,7 +297,7 @@ async function copyBetweenDrivers(fs, sourceCtx, targetCtx, sourcePath, targetPa
321297 const targetSegments = targetPath . split ( "/" ) . filter ( Boolean ) ;
322298 const sourceSegments = sourcePath . split ( "/" ) . filter ( Boolean ) ;
323299 const sourceFileName =
324- sourceSegments [ sourceSegments . length - 1 ] || "file" ;
300+ sourceSegments [ sourceSegments . length - 1 ] || "file" ;
325301 const targetLeaf = targetSegments [ targetSegments . length - 1 ] || "" ;
326302 const targetIsDirectory = isDirectoryPath ( targetPath ) ;
327303
@@ -461,14 +437,14 @@ async function copyDirectoryBetweenDrivers(fs, sourceCtx, targetCtx, sourcePath,
461437 const fileTargetCtx = await fs . mountManager . getDriverByPath ( fileTargetPath , userIdOrInfo , userType ) ;
462438
463439 const fileResult = await copyBetweenDrivers (
464- fs ,
465- fileSourceCtx ,
466- fileTargetCtx ,
467- fileSourcePath ,
468- fileTargetPath ,
469- userIdOrInfo ,
470- userType ,
471- options
440+ fs ,
441+ fileSourceCtx ,
442+ fileTargetCtx ,
443+ fileSourcePath ,
444+ fileTargetPath ,
445+ userIdOrInfo ,
446+ userType ,
447+ options
472448 ) ;
473449
474450 // 处理复制结果:成功、跳过、失败
0 commit comments