( args: DownloadTeamStorageAssetsArgs, deps: DownloadTeamStorageAssetsDeps, )
| 53 | } |
| 54 | |
| 55 | async 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 | |
| 111 | type WriteAssetSnapshotArgs = { |
| 112 | assetsAbs: string; |
no test coverage detected