mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Run test-release in a temporary folder
This commit is contained in:
@@ -3,14 +3,11 @@
|
||||
|
||||
import { createHash } from 'node:crypto';
|
||||
import { createReadStream } from 'node:fs';
|
||||
import { rename, rm } from 'node:fs/promises';
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
|
||||
import type { LoggerType } from '../types/Logging.std.js';
|
||||
import * as Errors from '../types/errors.std.js';
|
||||
import { SECOND, MINUTE, HOUR } from '../util/durations/index.std.js';
|
||||
import { sleep } from '../util/sleep.std.js';
|
||||
import { isOlderThan } from '../util/timestamp.std.js';
|
||||
import { MINUTE, HOUR } from '../util/durations/index.std.js';
|
||||
|
||||
export type CheckIntegrityResultType = Readonly<
|
||||
| {
|
||||
@@ -48,97 +45,6 @@ export async function checkIntegrity(
|
||||
}
|
||||
}
|
||||
|
||||
async function doGracefulFSOperation<Args extends ReadonlyArray<unknown>>({
|
||||
name,
|
||||
operation,
|
||||
args,
|
||||
logger,
|
||||
startedAt,
|
||||
retryCount,
|
||||
retryAfter = 5 * SECOND,
|
||||
timeout = 5 * MINUTE,
|
||||
}: {
|
||||
name: string;
|
||||
operation: (...args: Args) => Promise<void>;
|
||||
args: Args;
|
||||
logger: LoggerType;
|
||||
startedAt: number;
|
||||
retryCount: number;
|
||||
retryAfter?: number;
|
||||
timeout?: number;
|
||||
}): Promise<void> {
|
||||
const logId = `gracefulFS(${name})`;
|
||||
try {
|
||||
await operation(...args);
|
||||
|
||||
if (retryCount !== 0) {
|
||||
logger.info(
|
||||
`${logId}: succeeded after ${retryCount} retries, ${args.join(', ')}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code !== 'EACCES' && error.code !== 'EPERM') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (isOlderThan(startedAt, timeout)) {
|
||||
logger.warn(`${logId}: timed out, ${args.join(', ')}`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
`${logId}: got ${error.code} when running on ${args.join(', ')}; ` +
|
||||
`retrying in one second. (retryCount=${retryCount})`
|
||||
);
|
||||
|
||||
await sleep(retryAfter);
|
||||
|
||||
return doGracefulFSOperation({
|
||||
name,
|
||||
operation,
|
||||
args,
|
||||
logger,
|
||||
startedAt,
|
||||
retryCount: retryCount + 1,
|
||||
retryAfter,
|
||||
timeout,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function gracefulRename(
|
||||
logger: LoggerType,
|
||||
fromPath: string,
|
||||
toPath: string
|
||||
): Promise<void> {
|
||||
return doGracefulFSOperation({
|
||||
name: 'rename',
|
||||
operation: rename,
|
||||
args: [fromPath, toPath],
|
||||
logger,
|
||||
startedAt: Date.now(),
|
||||
retryCount: 0,
|
||||
});
|
||||
}
|
||||
|
||||
function rmRecursive(path: string): Promise<void> {
|
||||
return rm(path, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
export async function gracefulRmRecursive(
|
||||
logger: LoggerType,
|
||||
path: string
|
||||
): Promise<void> {
|
||||
return doGracefulFSOperation({
|
||||
name: 'rmRecursive',
|
||||
operation: rmRecursive,
|
||||
args: [path],
|
||||
logger,
|
||||
startedAt: Date.now(),
|
||||
retryCount: 0,
|
||||
});
|
||||
}
|
||||
|
||||
const MAX_UPDATE_DELAY = 6 * HOUR;
|
||||
|
||||
export function isTimeToUpdate({
|
||||
|
||||
Reference in New Issue
Block a user