MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / runPendingDataDirMigration

Function runPendingDataDirMigration

packages/node-runtime/src/data-dir-switch.ts:204–257  ·  view source on GitHub ↗
(
  pending: PendingDataDirMigration,
  deps: RunPendingDataDirMigrationDeps
)

Source from the content-addressed store, hash-verified

202}
203
204export function runPendingDataDirMigration(
205 pending: PendingDataDirMigration,
206 deps: RunPendingDataDirMigrationDeps
207): RunPendingDataDirMigrationResult {
208 const copy = deps.copyDirMerge ?? copyDirMerge
209 const mkdir = deps.ensureDir ?? ensureDir
210
211 let stats: CopyStats = { copied: 0, skipped: 0, errors: [] }
212 if (pending.migrate && path.resolve(pending.from) !== path.resolve(pending.to)) {
213 if (!fs.existsSync(pending.from)) {
214 return {
215 success: false,
216 from: pending.from,
217 to: pending.to,
218 copied: 0,
219 skipped: 0,
220 errors: [`源数据目录不存在: ${pending.from}`],
221 }
222 }
223
224 stats = copy(pending.from, pending.to, mkdir)
225 deps.log?.(
226 `数据目录迁移完成: 从 ${pending.from} 到 ${pending.to},复制 ${stats.copied} 项,跳过 ${stats.skipped} 项,错误 ${stats.errors.length} 项`
227 )
228 if (stats.errors.length > 0) {
229 return {
230 success: false,
231 from: pending.from,
232 to: pending.to,
233 copied: stats.copied,
234 skipped: stats.skipped,
235 errors: stats.errors,
236 }
237 }
238 } else {
239 mkdir(pending.to)
240 }
241
242 deps.writeUserDataDir(pending.to)
243 deps.clearPendingMigration()
244
245 if (pending.deleteSourceOnSuccess && path.resolve(pending.from) !== path.resolve(pending.to)) {
246 deps.markPendingDeleteDir?.(pending.from)
247 }
248
249 return {
250 success: true,
251 from: pending.from,
252 to: pending.to,
253 copied: stats.copied,
254 skipped: stats.skipped,
255 errors: [],
256 }
257}
258
259function getPendingMigrationPath(systemDir: string): string {
260 return path.join(systemDir, 'settings', PENDING_MIGRATION_FILE)

Calls

no outgoing calls

Tested by

no test coverage detected