MCPcopy Create free account
hub / github.com/anus-dev/ANUS / pullImage

Function pullImage

packages/cli/src/utils/sandbox.ts:848–913  ·  view source on GitHub ↗
(sandbox: string, image: string)

Source from the content-addressed store, hash-verified

846}
847
848async function pullImage(sandbox: string, image: string): Promise<boolean> {
849 console.info(`Attempting to pull image ${image} using ${sandbox}...`);
850 return new Promise((resolve) => {
851 const args = ['pull', image];
852 const pullProcess = spawn(sandbox, args, { stdio: 'pipe' });
853
854 let stderrData = '';
855
856 const onStdoutData = (data: Buffer) => {
857 console.info(data.toString().trim()); // Show pull progress
858 };
859
860 const onStderrData = (data: Buffer) => {
861 stderrData += data.toString();
862 console.error(data.toString().trim()); // Show pull errors/info from the command itself
863 };
864
865 const onError = (err: Error) => {
866 console.warn(
867 `Failed to start '${sandbox} pull ${image}' command: ${err.message}`,
868 );
869 cleanup();
870 resolve(false);
871 };
872
873 const onClose = (code: number | null) => {
874 if (code === 0) {
875 console.info(`Successfully pulled image ${image}.`);
876 cleanup();
877 resolve(true);
878 } else {
879 console.warn(
880 `Failed to pull image ${image}. '${sandbox} pull ${image}' exited with code ${code}.`,
881 );
882 if (stderrData.trim()) {
883 // Details already printed by the stderr listener above
884 }
885 cleanup();
886 resolve(false);
887 }
888 };
889
890 const cleanup = () => {
891 if (pullProcess.stdout) {
892 pullProcess.stdout.removeListener('data', onStdoutData);
893 }
894 if (pullProcess.stderr) {
895 pullProcess.stderr.removeListener('data', onStderrData);
896 }
897 pullProcess.removeListener('error', onError);
898 pullProcess.removeListener('close', onClose);
899 if (pullProcess.connected) {
900 pullProcess.disconnect();
901 }
902 };
903
904 if (pullProcess.stdout) {
905 pullProcess.stdout.on('data', onStdoutData);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected