Skip to content

Commit aacf9da

Browse files
committed
pr feedback
1 parent 44fcb84 commit aacf9da

File tree

8 files changed

+563
-502
lines changed

8 files changed

+563
-502
lines changed

apps/zipsync/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"_phase:test": "heft run --only test -- --clean"
1919
},
2020
"dependencies": {
21-
"@rushstack/node-core-library": "workspace:*",
2221
"@rushstack/terminal": "workspace:*",
2322
"@rushstack/ts-command-line": "workspace:*",
2423
"typescript": "~5.8.2",

apps/zipsync/src/ZipSyncCommandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
IRequiredCommandLineStringListParameter,
1010
CommandLineChoiceParameter
1111
} from '@rushstack/ts-command-line/lib/index';
12-
import { InternalError } from '@rushstack/node-core-library/lib/InternalError';
1312
import type { ConsoleTerminalProvider } from '@rushstack/terminal/lib/ConsoleTerminalProvider';
1413
import type { ITerminal } from '@rushstack/terminal/lib/ITerminal';
1514

@@ -92,7 +91,8 @@ export class ZipSyncCommandLineParser extends CommandLineParser {
9291

9392
protected override async onExecuteAsync(): Promise<void> {
9493
if (this._debugParameter.value) {
95-
InternalError.breakInDebugger = true;
94+
// eslint-disable-next-line no-debugger
95+
debugger;
9696
this._terminalProvider.debugEnabled = true;
9797
this._terminalProvider.verboseEnabled = true;
9898
}

apps/zipsync/src/benchmark.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ function benchZipSyncScenario(
222222
});
223223
}
224224

225-
describe(`archive benchmarks (iterations=${ITERATIONS})`, () => {
225+
// the benchmarks are skipped by default because they require external tools (tar, zip) to be installed
226+
describe.skip(`archive benchmarks (iterations=${ITERATIONS})`, () => {
226227
it('tar', () => {
227228
if (!isTarAvailable()) {
228229
console.log('Skipping tar test because tar is not available');
@@ -467,7 +468,7 @@ afterAll(() => {
467468
const resultText = outputLines.join('\n');
468469
console.log(resultText);
469470
try {
470-
const resultFile = path.join(__dirname, '..', 'temp', `benchmark-results-${runId}.txt`);
471+
const resultFile = path.join(__dirname, '..', 'temp', `benchmark-results.txt`);
471472
fs.writeFileSync(resultFile, resultText, { encoding: 'utf-8' });
472473
console.log(`Benchmark results written to: ${resultFile}`);
473474
} catch (e) {

apps/zipsync/src/hash.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
import { closeSync, readSync, fstatSync, type Stats } from 'node:fs';
5+
import { createHash, type Hash } from 'node:crypto';
6+
7+
const buffer: Buffer = Buffer.allocUnsafeSlow(1 << 24);
8+
9+
export function computeFileHash(fd: number): string | false {
10+
try {
11+
const hash: Hash = createHash('sha256');
12+
let totalBytesRead: number = 0;
13+
let bytesRead: number;
14+
do {
15+
bytesRead = readSync(fd, buffer, 0, buffer.length, -1);
16+
if (bytesRead <= 0) {
17+
break;
18+
}
19+
totalBytesRead += bytesRead;
20+
hash.update(buffer.subarray(0, bytesRead));
21+
} while (bytesRead > 0);
22+
if (totalBytesRead === 0) {
23+
// Sometimes directories get treated as empty files
24+
const stat: Stats = fstatSync(fd);
25+
if (!stat.isFile()) {
26+
return false;
27+
}
28+
}
29+
30+
return hash.digest('hex');
31+
} catch (err) {
32+
// There is a bug in node-core-library where it doesn't handle if the operation was on a file descriptor
33+
if (err.code === 'EISDIR' || err.code === 'ENOENT' || err.code === 'ENOTDIR') {
34+
return false;
35+
}
36+
throw err;
37+
} finally {
38+
if (fd !== undefined) {
39+
closeSync(fd);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)