Skip to content

Commit

Permalink
handle cross-device linking problem
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnrushefsky committed Sep 24, 2024
1 parent 0758234 commit 24fd4f8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,22 @@ async function main() {
for (let syncConfig of work.sync.after) {
const newDir = `${path.resolve(syncConfig.local_path)}-${work.id}`;
log.info(`Moving ${syncConfig.local_path} to ${newDir} for upload`);
await fs.rename(syncConfig.local_path, newDir);
await fs.mkdir(syncConfig.local_path, { recursive: true });
try {
await fs.rename(syncConfig.local_path, newDir);
} catch (e: any) {
if (e.code && e.code === "EXDEV") {
log.warn(
`Cannot move ${syncConfig.local_path} to ${newDir} due to cross-device link, copying instead`
);
await fs.cp(syncConfig.local_path, newDir, { recursive: true });
await fs.rm(syncConfig.local_path, { recursive: true });
} else {
throw e;
}
} finally {
await fs.mkdir(syncConfig.local_path, { recursive: true });
}

modifiedOutputs.push({
...syncConfig,
local_path: newDir,
Expand Down

0 comments on commit 24fd4f8

Please sign in to comment.