Skip to content

Commit

Permalink
fix(copyFile): With network storage shell.cp faster than copyFileSync
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe authored and 3y3 committed Oct 30, 2023
1 parent 31405ad commit b6a1a6b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/cmd/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ function preparingTemporaryFolders(userOutputFolder: string) {
// Create temporary input/output folders
shell.rm('-rf', args.input, args.output);
shell.mkdir(args.input, args.output);
shell.chmod('-R', 'u+w', args.input);

copyFiles(
args.rootInput,
Expand All @@ -315,4 +314,6 @@ function preparingTemporaryFolders(userOutputFolder: string) {
ignore: ['node_modules/**', '*/node_modules/**'],
}),
);

shell.chmod('-R', 'u+w', args.input);
}
4 changes: 2 additions & 2 deletions src/services/tocs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {dirname, extname, join, normalize, parse, relative, resolve, sep} from 'path';
import {copyFileSync, existsSync, readFileSync, writeFileSync} from 'fs';
import {existsSync, readFileSync, writeFileSync} from 'fs';
import {dump, load} from 'js-yaml';
import shell from 'shelljs';
import walkSync from 'walk-sync';
Expand Down Expand Up @@ -205,7 +205,7 @@ function _copyTocDir(tocPath: string, destDir: string) {

writeFileSync(to, updatedFileContent);
} else {
copyFileSync(from, to);
shell.cp(from, to);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/steps/processPages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {DocInnerProps} from '@diplodoc/client';
import {basename, dirname, extname, join, relative, resolve} from 'path';
import shell from 'shelljs';
import {copyFileSync, readFileSync, writeFileSync} from 'fs';
import {readFileSync, writeFileSync} from 'fs';
import {bold} from 'chalk';
import {dump, load} from 'js-yaml';
import {asyncify, mapLimit} from 'async';
Expand Down Expand Up @@ -312,7 +312,7 @@ function copyFileWithoutChanges(
const from = resolvedPathToFile;
const to = resolve(outputDir, filename);

copyFileSync(from, to);
shell.cp(from, to);
}

async function processingFileToMd(path: PathData, metaDataOptions: MetaDataOptions): Promise<void> {
Expand Down
17 changes: 11 additions & 6 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import {dirname, resolve} from 'path';
import shell from 'shelljs';
import {copyFileSync} from 'fs';
import {logger} from './logger';

export function copyFiles(
inputFolderPath: string,
outputFolderPath: string,
files: string[],
): void {
for (const pathToAsset of files) {
const outputDir: string = resolve(outputFolderPath, dirname(pathToAsset));
const dirs = new Set<string>();

files.forEach((pathToAsset) => {
const outputDir = resolve(outputFolderPath, dirname(pathToAsset));
const from = resolve(inputFolderPath, pathToAsset);
const to = resolve(outputFolderPath, pathToAsset);

shell.mkdir('-p', outputDir);
copyFileSync(from, to);
if (!dirs.has(outputDir)) {
dirs.add(outputDir);
shell.mkdir('-p', outputDir);
}

shell.cp(from, to);

logger.copy(pathToAsset);
}
});
}

0 comments on commit b6a1a6b

Please sign in to comment.