MCPcopy
hub / github.com/upstash/context7 / migrateLegacyFile

Function migrateLegacyFile

packages/cli/src/utils/storage-paths.ts:74–93  ·  view source on GitHub ↗
(
  fileName: string,
  targetPath: string,
  mode?: number
)

Source from the content-addressed store, hash-verified

72}
73
74export async function migrateLegacyFile(
75 fileName: string,
76 targetPath: string,
77 mode?: number
78): Promise<void> {
79 const legacyPath = getLegacyFilePath(fileName);
80 if (legacyPath === targetPath || (await exists(targetPath)) || !(await exists(legacyPath))) {
81 return;
82 }
83
84 try {
85 await mkdir(path.dirname(targetPath), { recursive: true, mode: 0o700 });
86 await rename(legacyPath, targetPath);
87 if (mode !== undefined) {
88 await chmod(targetPath, mode);
89 }
90 } catch {
91 // Leave the legacy file in place; readers resolve to it via resolveReadPath.
92 }
93}
94
95/**
96 * Returns the path to read from: the XDG target after attempting migration,

Callers 2

resolveReadPathFunction · 0.85
writeStateFilePathFunction · 0.85

Calls 2

getLegacyFilePathFunction · 0.85
existsFunction · 0.70

Tested by

no test coverage detected