Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/src/commands/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {buildContext} from '../services/context.services';
import {setController} from '../services/controller.services';
import {collectIdentities} from '../services/identity.services';
import {transfer} from '../services/ledger.services';
import {touchWatchedFile} from '../services/touch.services';
import type {CliContext} from '../types/context';
import {nextArg} from '../utils/args.utils';

Expand Down Expand Up @@ -92,6 +93,11 @@ const buildServer = ({context}: {context: CliContext}): Server =>
res.end(JSON.stringify(identities));
return;
}
case 'touch': {
await touchWatchedFile({searchParams});
done();
return;
}
}

error404();
Expand Down
41 changes: 41 additions & 0 deletions cli/src/services/touch.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {isEmptyString} from '@dfinity/utils';
import kleur from 'kleur';
import {existsSync} from 'node:fs';
import {utimes} from 'node:fs/promises';
import {join} from 'node:path';
import {DEV_DEPLOY_FOLDER} from '../constants/dev.constants';

const {yellow, red} = kleur;

/**
* Workaround Podman and Apple container issues on macOS:
* - https://github.com/containers/podman/issues/22343
* - https://github.com/apple/container/issues/141
*/
export const touchWatchedFile = async ({searchParams}: {searchParams: URLSearchParams}) => {
const file = searchParams.get('file');

if (isEmptyString(file)) {
console.log(`ℹ️ Skipped touching file: no file provided.`);
return;
}

const filename = decodeURIComponent(file);
const filepath = join(DEV_DEPLOY_FOLDER, filename);

if (!existsSync(filepath)) {
console.log(`ℹ️ Skipped touching file: ${yellow(filepath)} does not exist.`);
return;
}

try {
await touch(filepath);
} catch (err: unknown) {
console.log(red(`️‼️ Unexpected error while touching ${filepath}`), err);
}
};

const touch = async (filePath: string) => {
const now = new Date();
await utimes(filePath, now, now);
};