From 652143e0459f03a8f38e2300af823f9e62e7cb50 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Wed, 6 May 2026 11:50:21 +0800 Subject: [PATCH 1/2] try to fix file upload race condition --- packages/dockerApi/src/api/copyFileTo.ts | 25 ++---------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/packages/dockerApi/src/api/copyFileTo.ts b/packages/dockerApi/src/api/copyFileTo.ts index 86db7e3a95..98dbf1a9c7 100644 --- a/packages/dockerApi/src/api/copyFileTo.ts +++ b/packages/dockerApi/src/api/copyFileTo.ts @@ -4,13 +4,11 @@ import fs from "fs"; import dataUriToBuffer from "data-uri-to-buffer"; import { params } from "@dappnode/params"; import { shell } from "@dappnode/utils"; -import { dockerContainerInspect, dockerContainerStart, dockerContainerStop } from "./container.js"; -import { logs } from "@dappnode/logger"; const tempTransferDir = params.TEMP_TRANSFER_DIR; /** - * Copy file to a DNP container, starting it if necessary: + * Copy file to a DNP container: * * @param containerName Name of a docker container * @param dataUri = "data:application/zip;base64,UEsDBBQAAAg..." @@ -66,32 +64,13 @@ export async function copyFileToDockerContainer({ // Remove existing file if it exists if (fs.existsSync(fromPath)) fs.rmSync(fromPath, { recursive: true, force: true }); - /** - * Convert dataUri to local file - * - * In this conversion direction MIME types don't matter - * The extension is what decides the type and it's the user's - * responsability to specify it correctly on the UI. The code will - * not cause problems if the types are not setup corretly - */ dataUriToFile(dataUri, fromPath); - // Container needs to be running to copy files - const containerInspect = await dockerContainerInspect(containerName); - const isInitiallyRunning = containerInspect.State.Running; - - if (!isInitiallyRunning) await dockerContainerStart(containerName); - - // Copy file from local file system to container + // docker cp works on containers in any state (created, running, stopped) await dockerCopyFileTo(containerName, fromPath, toPath); // Clean intermediate file if (fs.existsSync(fromPath)) fs.rmSync(fromPath, { recursive: true, force: true }); - - if (!isInitiallyRunning) - dockerContainerStop(containerName).catch((err) => - logs.error(`Error stopping container ${containerName} after copying a file to it: ${err}`) - ); } function dockerCopyFileTo(id: string, fromPath: string, toPath: string): Promise { From 564816cb026731dd158fe1aad2e392b5d25eace9 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Wed, 6 May 2026 15:56:29 +0800 Subject: [PATCH 2/2] revise comments --- packages/dockerApi/src/api/copyFileTo.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dockerApi/src/api/copyFileTo.ts b/packages/dockerApi/src/api/copyFileTo.ts index 98dbf1a9c7..150843bcb9 100644 --- a/packages/dockerApi/src/api/copyFileTo.ts +++ b/packages/dockerApi/src/api/copyFileTo.ts @@ -8,7 +8,7 @@ import { shell } from "@dappnode/utils"; const tempTransferDir = params.TEMP_TRANSFER_DIR; /** - * Copy file to a DNP container: + * Copy file to a DNP container, starting it if necessary: * * @param containerName Name of a docker container * @param dataUri = "data:application/zip;base64,UEsDBBQAAAg..." @@ -66,7 +66,7 @@ export async function copyFileToDockerContainer({ dataUriToFile(dataUri, fromPath); - // docker cp works on containers in any state (created, running, stopped) + // Copy file from local file system to container await dockerCopyFileTo(containerName, fromPath, toPath); // Clean intermediate file