Skip to content

Commit

Permalink
Merge pull request #76 from elventear/copy_rm
Browse files Browse the repository at this point in the history
Handle 'EXDEV: cross-device link not permitted'
  • Loading branch information
jaxxstorm committed Jan 12, 2024
2 parents 8cd2797 + 99bf750 commit 4b164a4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
33 changes: 25 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,38 @@ function run() {
fs.mkdirSync(dest, { 'recursive': true });
const outputPath = path.join(dest, renameTo !== "" ? renameTo : path.basename(binPath));
core.info(`Created output directory ${dest}`);
var moveFailed = false;
try {
fs.renameSync(binPath, outputPath);
core.info(`Moved release asset ${asset.name} to ${outputPath}`);
if (chmodTo !== "") {
}
catch (renameErr) {
if (renameErr instanceof Error && 'code' in renameErr && renameErr.code === 'EXDEV') {
core.debug(`Falling back to copy and remove, due to: ${renameErr}`);
try {
fs.chmodSync(outputPath, chmodTo);
core.info(`chmod'd ${outputPath} to ${chmodTo}`);
fs.copyFileSync(binPath, outputPath);
fs.rmSync(binPath);
}
catch (chmodErr) {
core.setFailed(`Failed to chmod ${outputPath} to ${chmodTo}: ${chmodErr}`);
catch (copyRemoveErr) {
moveFailed = true;
core.setFailed(`Failed to copy and remove downloaded release asset ${asset.name} from ${binPath} to ${outputPath}: ${copyRemoveErr}`);
}
}
else {
moveFailed = true;
core.setFailed(`Failed to move downloaded release asset ${asset.name} from ${binPath} to ${outputPath}: ${renameErr}`);
}
}
catch (renameErr) {
core.setFailed(`Failed to move downloaded release asset ${asset.name} from ${binPath} to ${outputPath}: ${renameErr}`);
if (!moveFailed) {
core.info(`Moved release asset ${asset.name} to ${outputPath}`);
}
if ((chmodTo !== "") && !moveFailed) {
try {
fs.chmodSync(outputPath, chmodTo);
core.info(`chmod'd ${outputPath} to ${chmodTo}`);
}
catch (chmodErr) {
core.setFailed(`Failed to chmod ${outputPath} to ${chmodTo}: ${chmodErr}`);
}
}
}
catch (err) {
Expand Down
36 changes: 27 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,38 @@ async function run() {

const outputPath = path.join(dest, renameTo !== "" ? renameTo : path.basename(binPath));
core.info(`Created output directory ${dest}`);

var moveFailed = false;

try {
fs.renameSync(binPath, outputPath);
core.info(`Moved release asset ${asset.name} to ${outputPath}`);

if (chmodTo !== "") {
} catch (renameErr) {
if (renameErr instanceof Error && 'code' in renameErr && renameErr.code === 'EXDEV') {
core.debug(`Falling back to copy and remove, due to: ${renameErr}`);
try {
fs.chmodSync(outputPath, chmodTo);
core.info(`chmod'd ${outputPath} to ${chmodTo}`)
} catch (chmodErr) {
core.setFailed(`Failed to chmod ${outputPath} to ${chmodTo}: ${chmodErr}`);
fs.copyFileSync(binPath, outputPath);
fs.rmSync(binPath);
} catch (copyRemoveErr) {
moveFailed = true;
core.setFailed(`Failed to copy and remove downloaded release asset ${asset.name} from ${binPath} to ${outputPath}: ${copyRemoveErr}`);
}
} else {
moveFailed = true;
core.setFailed(`Failed to move downloaded release asset ${asset.name} from ${binPath} to ${outputPath}: ${renameErr}`);
}
}

if (!moveFailed) {
core.info(`Moved release asset ${asset.name} to ${outputPath}`);
}

if ((chmodTo !== "") && !moveFailed) {
try {
fs.chmodSync(outputPath, chmodTo);
core.info(`chmod'd ${outputPath} to ${chmodTo}`)
} catch (chmodErr) {
core.setFailed(`Failed to chmod ${outputPath} to ${chmodTo}: ${chmodErr}`);
}
} catch (renameErr) {
core.setFailed(`Failed to move downloaded release asset ${asset.name} from ${binPath} to ${outputPath}: ${renameErr}`);
}
} catch (err) {
core.setFailed(`Failed to create required output directory ${dest}`);
Expand Down

0 comments on commit 4b164a4

Please sign in to comment.