Durable rename
Some checks failed
Check / build (pull_request) Has been cancelled
E2E tests / build (pull_request) Has been cancelled
Publish CLI / publish-docker (pull_request) Has been cancelled
Publish server Docker image / publish-docker (pull_request) Has been cancelled
Check / build (push) Has been cancelled
E2E tests / build (push) Has been cancelled
Publish CLI / publish-docker (push) Has been cancelled
Publish server Docker image / publish-docker (push) Has been cancelled
Some checks failed
Check / build (pull_request) Has been cancelled
E2E tests / build (pull_request) Has been cancelled
Publish CLI / publish-docker (pull_request) Has been cancelled
Publish server Docker image / publish-docker (pull_request) Has been cancelled
Check / build (push) Has been cancelled
E2E tests / build (push) Has been cancelled
Publish CLI / publish-docker (push) Has been cancelled
Publish server Docker image / publish-docker (push) Has been cancelled
This commit is contained in:
parent
6647a4e632
commit
d99e249fa5
1 changed files with 16 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ import { toUnixPath } from "./path-utils";
|
||||||
export const VAULTLINK_DIR = ".vaultlink";
|
export const VAULTLINK_DIR = ".vaultlink";
|
||||||
|
|
||||||
export class NodeFileSystemOperations implements FileSystemOperations {
|
export class NodeFileSystemOperations implements FileSystemOperations {
|
||||||
public constructor(private readonly basePath: string) {}
|
public constructor(private readonly basePath: string) { }
|
||||||
|
|
||||||
public async listFilesRecursively(
|
public async listFilesRecursively(
|
||||||
directory: RelativePath | undefined
|
directory: RelativePath | undefined
|
||||||
|
|
@ -150,12 +150,27 @@ export class NodeFileSystemOperations implements FileSystemOperations {
|
||||||
await fd.close();
|
await fd.close();
|
||||||
}
|
}
|
||||||
await fs.rename(tmpPath, fullPath);
|
await fs.rename(tmpPath, fullPath);
|
||||||
|
await this.syncDirectory(path.dirname(fullPath));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await fs.unlink(tmpPath).catch(() => undefined);
|
await fs.unlink(tmpPath).catch(() => undefined);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make the rename durable by fsync'ing the destination's parent directory.
|
||||||
|
// Skipped on Windows: fsync on a directory handle isn't supported there
|
||||||
|
private async syncDirectory(dir: string): Promise<void> {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fd = await fs.open(dir, "r");
|
||||||
|
try {
|
||||||
|
await fd.sync();
|
||||||
|
} finally {
|
||||||
|
await fd.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async walkDirectory(
|
private async walkDirectory(
|
||||||
relativePath: string,
|
relativePath: string,
|
||||||
files: RelativePath[]
|
files: RelativePath[]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue