Skip to content

Commit

Permalink
Backup one file at a time (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-rc authored Jan 27, 2025
1 parent 1334992 commit 3f9b60d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dest-already-exists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
ggt: patch
---

Attempt to fix `Error: dest already exists.` by moving files one at a time to `.gadget/backup/`.
9 changes: 3 additions & 6 deletions src/services/filesync/filesync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from "../app/edit/operation.js";
import type { Command } from "../command/command.js";
import type { Context } from "../command/context.js";
import { config } from "../config/config.js";
import { confirm } from "../output/confirm.js";
import type { Fields } from "../output/log/field.js";
import { Level } from "../output/log/level.js";
Expand Down Expand Up @@ -622,7 +621,7 @@ export class FileSync {
const changes = new Changes();
const directoriesWithDeletedFiles = new Set<string>();

await pMap(options.delete, async (pathToDelete) => {
for (const pathToDelete of options.delete.sort().reverse()) {
// add all the directories that contain this file to
// directoriesWithDeletedFiles so we can clean them up later
let dir = path.dirname(pathToDelete);
Expand Down Expand Up @@ -674,16 +673,14 @@ export class FileSync {
}
},
{
// windows tends to run into these issues way more often than
// mac/linux, so we retry more times
retries: config.windows ? 4 : 2,
retries: 5,
minTimeout: ms("100ms"),
onFailedAttempt: (error) => {
ctx.log.warn("failed to move file to backup", { error, currentPath, backupPath });
},
},
);
});
}

for (const directoryWithDeletedFile of Array.from(directoriesWithDeletedFiles.values()).sort().reverse()) {
if (options.files.some((file) => file.path === directoryWithDeletedFile)) {
Expand Down

0 comments on commit 3f9b60d

Please sign in to comment.