From 6306aab99f4467b5e05b215f55aef24bb9b2ea69 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 15 Jun 2023 13:45:27 +0200 Subject: [PATCH] If `fs.renameSync` fails (e.g. because source and destination files are on different partitions), try `fs.copySync` and `fs.unlinkSync` instead. --- CHANGELOG.md | 4 ++++ src/functions.ts | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f82d64..0db7217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## Changed + +- If `fs.renameSync` fails (e.g. because source and destination files are on different partitions), try `fs.copySync` and `fs.unlinkSync` instead. + ## [1.3.0] - 2023-05-19 ## Changed diff --git a/src/functions.ts b/src/functions.ts index 6685bf0..4f0fbda 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -106,7 +106,13 @@ export async function install_nextflow( const temp_install_dir = fs.mkdtempSync(`nxf-${version}`) const nf_path = `${temp_install_dir}/nextflow` - fs.renameSync(nf_dl_path, nf_path) + try { + fs.renameSync(nf_dl_path, nf_path) + } catch (err: unknown) { + core.debug(`Failed to rename file: ${err}`) + fs.copyFileSync(nf_dl_path, nf_path) + fs.unlinkSync(nf_dl_path) + } fs.chmodSync(nf_path, "0711") return temp_install_dir