MCPcopy
hub / github.com/qawolf/cli / writeTeamStorageAssets

Function writeTeamStorageAssets

src/shell/platform/teamStorageAssets.ts:55–109  ·  view source on GitHub ↗
(
  args: DownloadTeamStorageAssetsArgs,
  deps: DownloadTeamStorageAssetsDeps,
)

Source from the content-addressed store, hash-verified

53}
54
55async function writeTeamStorageAssets(
56 args: DownloadTeamStorageAssetsArgs,
57 deps: DownloadTeamStorageAssetsDeps,
58): Promise<SyncTeamStorageAssetsResult> {
59 const fs = deps.fs ?? makeDefaultFs();
60 const tmpAssets = mintAssetSnapshotPath(args.assetsAbs, "pull");
61 const manifest = await readAssetManifest(args.assetsAbs, fs);
62 const safeFiles: ReusableAssetFile[] = [];
63 for (const file of args.files) {
64 const relativePath = safeAssetPath(file.path);
65 if (relativePath !== undefined) safeFiles.push({ file, relativePath });
66 }
67 const skippedCount = args.files.length - safeFiles.length;
68 const reusable = await reusableAssetPaths(
69 args.assetsAbs,
70 safeFiles,
71 manifest,
72 fs,
73 );
74 const reusedCount = reusable.size;
75
76 if (
77 reusedCount === safeFiles.length &&
78 (await hasExactAssetSnapshot(
79 args.assetsAbs,
80 safeFiles.map((file) => file.relativePath),
81 fs,
82 ))
83 ) {
84 return { downloadedCount: 0, reusedCount, skippedCount };
85 }
86
87 try {
88 const downloadedCount = await writeAssetSnapshot({
89 assetsAbs: args.assetsAbs,
90 deps: { fetch: deps.fetch, fs },
91 reusable,
92 safeFiles,
93 tmpAssets,
94 });
95 await replaceAssetsDir(args.assetsAbs, tmpAssets, fs);
96 await writeAssetManifest(
97 args.assetsAbs,
98 safeFiles.map(({ file, relativePath }) => ({
99 ...file,
100 path: relativePath,
101 })),
102 fs,
103 );
104 return { downloadedCount, reusedCount, skippedCount };
105 } catch (error: unknown) {
106 await cleanupAssetSnapshot(tmpAssets, fs);
107 throw error;
108 }
109}
110
111type WriteAssetSnapshotArgs = {
112 assetsAbs: string;

Callers 1

Calls 10

makeDefaultFsFunction · 0.85
mintAssetSnapshotPathFunction · 0.85
readAssetManifestFunction · 0.85
safeAssetPathFunction · 0.85
reusableAssetPathsFunction · 0.85
hasExactAssetSnapshotFunction · 0.85
writeAssetSnapshotFunction · 0.85
replaceAssetsDirFunction · 0.85
writeAssetManifestFunction · 0.85
cleanupAssetSnapshotFunction · 0.85

Tested by

no test coverage detected