diff --git a/tests/e2e/Services/Proxy/ProxyHelpers.php b/tests/e2e/Services/Proxy/ProxyHelpers.php index 6f15abdad8..028e607546 100644 --- a/tests/e2e/Services/Proxy/ProxyHelpers.php +++ b/tests/e2e/Services/Proxy/ProxyHelpers.php @@ -263,15 +263,27 @@ trait ProxyHelpers $stderr = ''; $folderPath = realpath(__DIR__ . '/../../../resources/sites') . "/$site"; - $tarPath = "$folderPath/code.tar.gz"; + // Parallel tests must not truncate an archive another upload is reading. + $tarPath = \sys_get_temp_dir() . '/appwrite-site-' . $site . '-' . \getmypid() . '-' . \uniqid('', true) . '.tar.gz'; - Console::execute("cd $folderPath && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $stdout, $stderr); + Console::execute( + 'tar --exclude code.tar.gz --exclude node_modules -czf ' . \escapeshellarg($tarPath) . ' -C ' . \escapeshellarg($folderPath) . ' .', + '', + $stdout, + $stderr + ); if (filesize($tarPath) > 1024 * 1024 * 5) { throw new \Exception('Code package is too large. Use the chunked upload method instead.'); } - return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + register_shutdown_function(static function () use ($tarPath) { + if (\is_file($tarPath)) { + @\unlink($tarPath); + } + }); + + return new CURLFile($tarPath, 'application/x-gzip', 'code.tar.gz'); } private function packageFunction(string $function): CURLFile @@ -280,14 +292,26 @@ trait ProxyHelpers $stderr = ''; $folderPath = realpath(__DIR__ . '/../../../resources/functions') . "/$function"; - $tarPath = "$folderPath/code.tar.gz"; + // Parallel tests must not truncate an archive another upload is reading. + $tarPath = \sys_get_temp_dir() . '/appwrite-function-' . $function . '-' . \getmypid() . '-' . \uniqid('', true) . '.tar.gz'; - Console::execute("cd $folderPath && tar --exclude code.tar.gz --exclude node_modules -czf code.tar.gz .", '', $stdout, $stderr); + Console::execute( + 'tar --exclude code.tar.gz --exclude node_modules -czf ' . \escapeshellarg($tarPath) . ' -C ' . \escapeshellarg($folderPath) . ' .', + '', + $stdout, + $stderr + ); if (filesize($tarPath) > 1024 * 1024 * 5) { throw new \Exception('Code package is too large. Use the chunked upload method instead.'); } - return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath)); + register_shutdown_function(static function () use ($tarPath) { + if (\is_file($tarPath)) { + @\unlink($tarPath); + } + }); + + return new CURLFile($tarPath, 'application/x-gzip', 'code.tar.gz'); } }