File size: 830 Bytes
4e1096a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import { AppService, FileItem } from '@/types/system';
export const copyFiles = async (appService: AppService, srcDir: string, dstDir: string) => {
let filesToCopy: FileItem[] = [];
try {
filesToCopy = await appService.readDirectory(srcDir, 'None');
} catch {
throw new Error(`Dir ${srcDir} failed to read.`);
}
for (let i = 0; i < filesToCopy.length; i++) {
const file = filesToCopy[i]!;
const srcPath = `${srcDir}/${file.path}`;
const destPath = `${dstDir}/${file.path}`;
await appService.copyFile(srcPath, destPath, 'None');
}
const filesCopied = await appService.readDirectory(dstDir, 'None');
for (const file of filesToCopy) {
if (!filesCopied.find((f) => f.path === file.path && f.size === file.size)) {
throw new Error(`File ${file.path} failed to copy.`);
}
}
};
|