Improve diff
This commit is contained in:
parent
792f57dc7e
commit
e5373ab2bb
23 changed files with 312 additions and 220 deletions
|
|
@ -85,7 +85,7 @@ describe("File operations", () => {
|
|||
const result = await ops.create("a", new Uint8Array());
|
||||
|
||||
assertSetContainsExactly(fs.names, "a");
|
||||
assert.equal(result.actualPath, "a");
|
||||
assert.equal(result, "a");
|
||||
});
|
||||
|
||||
it("create throws FileAlreadyExistsError when the path is occupied", async () => {
|
||||
|
|
@ -109,7 +109,7 @@ describe("File operations", () => {
|
|||
|
||||
const result = await ops.move("a", "b");
|
||||
assertSetContainsExactly(fs.names, "b");
|
||||
assert.equal(result.actualPath, "b");
|
||||
assert.equal(result, "b");
|
||||
});
|
||||
|
||||
it("move with same source and target is a no-op", async () => {
|
||||
|
|
@ -119,7 +119,7 @@ describe("File operations", () => {
|
|||
const result = await ops.move("a", "a");
|
||||
|
||||
assertSetContainsExactly(fs.names, "a");
|
||||
assert.equal(result.actualPath, "a");
|
||||
assert.equal(result, "a");
|
||||
});
|
||||
|
||||
it("move throws FileAlreadyExistsError when the target is occupied", async () => {
|
||||
|
|
|
|||
|
|
@ -11,16 +11,6 @@ import { FileNotFoundError } from "../errors/file-not-found-error";
|
|||
import { FileAlreadyExistsError } from "../errors/file-already-exists-error";
|
||||
import type { ExpectedFsEvents } from "../sync-operations/expected-fs-events";
|
||||
|
||||
/**
|
||||
* Outcome of a `move`/`create`. `actualPath` is where the file ended up;
|
||||
* with the conflict-path machinery removed it is always equal to the
|
||||
* requested path. The shape is preserved so callers don't all need to
|
||||
* change.
|
||||
*/
|
||||
export interface FileOpResult {
|
||||
actualPath: RelativePath;
|
||||
}
|
||||
|
||||
export class FileOperations {
|
||||
private readonly fs: SafeFileSystemOperations;
|
||||
|
||||
|
|
@ -68,7 +58,7 @@ export class FileOperations {
|
|||
public async create(
|
||||
path: RelativePath,
|
||||
newContent: Uint8Array
|
||||
): Promise<FileOpResult> {
|
||||
): Promise<RelativePath> {
|
||||
if (await this.fs.exists(path)) {
|
||||
throw new FileAlreadyExistsError(
|
||||
`Refusing to create '${path}': file already exists`,
|
||||
|
|
@ -84,7 +74,7 @@ export class FileOperations {
|
|||
this.expectedFsEvents.unexpectCreate(path);
|
||||
throw e;
|
||||
}
|
||||
return { actualPath: path };
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -220,9 +210,9 @@ export class FileOperations {
|
|||
public async move(
|
||||
oldPath: RelativePath,
|
||||
newPath: RelativePath
|
||||
): Promise<FileOpResult> {
|
||||
): Promise<RelativePath> {
|
||||
if (oldPath === newPath) {
|
||||
return { actualPath: oldPath };
|
||||
return oldPath;
|
||||
}
|
||||
|
||||
if (await this.fs.exists(newPath)) {
|
||||
|
|
@ -241,7 +231,7 @@ export class FileOperations {
|
|||
throw e;
|
||||
}
|
||||
await this.deletingEmptyParentDirectoriesOfDeletedFile(oldPath);
|
||||
return { actualPath: newPath };
|
||||
return newPath;
|
||||
}
|
||||
|
||||
private async deletingEmptyParentDirectoriesOfDeletedFile(
|
||||
|
|
|
|||
|
|
@ -1103,7 +1103,7 @@ export class Syncer {
|
|||
remoteHash,
|
||||
localPath: target
|
||||
});
|
||||
const result = await this.operations.create(
|
||||
const createdPath = await this.operations.create(
|
||||
target,
|
||||
remoteContent
|
||||
);
|
||||
|
|
@ -1112,7 +1112,7 @@ export class Syncer {
|
|||
);
|
||||
localPath =
|
||||
liveRecord === undefined
|
||||
? result.actualPath
|
||||
? createdPath
|
||||
: liveRecord.localPath;
|
||||
await this.updateCache(
|
||||
remoteVersion.vaultUpdateId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue