Skip to content

Commit 115b6a5

Browse files
authored
Add support for syncing files with spaces (#450)
1 parent 2a343b9 commit 115b6a5

File tree

3 files changed

+27
-48
lines changed

3 files changed

+27
-48
lines changed

packages/databricks-vscode/src/cli/BricksSyncParser.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ describe("tests for BricksSycnParser", () => {
3535
assert.equal(syncState, "IN_PROGRESS");
3636
});
3737

38+
it("should handle files with spaces in their names", () => {
39+
assert.equal(syncState, "STOPPED");
40+
bricksSycnParser.process(
41+
"Action: PUT: hello world.txt, hello.py, world hello.py"
42+
);
43+
assert.equal(syncState, "IN_PROGRESS");
44+
bricksSycnParser.process("Uploaded hello world.txt");
45+
bricksSycnParser.process("Uploaded hello.py");
46+
bricksSycnParser.process("Uploaded world hello.py");
47+
bricksSycnParser.process("[INFO] Initial Sync Complete");
48+
assert.equal(syncState, "WATCHING_FOR_CHANGES");
49+
});
50+
3851
it("test bricksSycnParser.process correctly keeps track of state of inflight requests", () => {
3952
// recieving some random logs from bricks sync
4053
assert.equal(syncState, "STOPPED");

packages/databricks-vscode/src/cli/BricksSyncParser.ts

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,26 @@ export class BricksSyncParser {
2525
// const s1 = "Action: PUT: g, .gitignore, DELETE: f"
2626
// A hacky way to solve this, lets move to structed logs from bricks later
2727
private parseForActionsInitiated(line: string) {
28-
const indexOfAction = line.indexOf("Action:");
29-
// The log line is not relevant for actions
30-
if (indexOfAction === -1) {
28+
const match = line.match(/Action:( PUT: (.*?))?( DELETE: (.*?))?$/);
29+
if (!match) {
3130
return;
3231
}
3332

34-
const tokenizedLine = line.substring(indexOfAction).split(" ");
35-
let isPut = false;
36-
let isDelete = false;
37-
for (let i = 1; i < tokenizedLine.length; i++) {
38-
switch (tokenizedLine[i]) {
39-
case "PUT:": {
40-
isPut = true;
41-
isDelete = false;
42-
break;
43-
}
44-
case "DELETE:": {
45-
isDelete = true;
46-
isPut = false;
47-
break;
48-
}
49-
default: {
50-
// trim the trailing , if it exists
51-
const filePath = tokenizedLine[i].replace(/,$/, "");
52-
if (isPut) {
53-
this.filesBeingUploaded.add(filePath);
54-
} else if (isDelete) {
55-
this.filesBeingDeleted.add(filePath);
56-
} else {
57-
throw new Error(
58-
"[BricksSyncParser] unexpected logs recieved"
59-
);
60-
}
61-
}
62-
}
63-
}
33+
const toAdd = match[2]?.split(", ");
34+
const toDelete = match[4]?.split(", ");
35+
36+
toAdd?.forEach((f) => this.filesBeingUploaded.add(f));
37+
toDelete?.forEach((f) => this.filesBeingDeleted.add(f));
6438
}
6539

6640
// We expect a single line of logs for all files being put/delete
6741
private parseForUploadCompleted(line: string) {
68-
const indexOfUploaded = line.indexOf("Uploaded");
69-
if (indexOfUploaded === -1) {
42+
const match = line.match(/Uploaded (.*)/);
43+
if (!match) {
7044
return;
7145
}
7246

73-
const tokenizedLine = line.substring(indexOfUploaded).split(" ");
74-
if (tokenizedLine.length !== 2) {
75-
throw new Error("[BricksSyncParser] unexpected logs recieved");
76-
}
77-
const filePath = tokenizedLine[1];
47+
const filePath = match[1];
7848
if (!this.filesBeingUploaded.has(filePath)) {
7949
throw new Error(
8050
"[BricksSyncParser] untracked file uploaded. All upload complete " +
@@ -89,16 +59,12 @@ export class BricksSyncParser {
8959
}
9060

9161
private parseForDeleteCompleted(line: string) {
92-
const indexOfDeleted = line.indexOf("Deleted");
93-
if (indexOfDeleted === -1) {
62+
const match = line.match(/Deleted (.*)/);
63+
if (!match) {
9464
return;
9565
}
9666

97-
const tokenizedLine = line.substring(indexOfDeleted).split(" ");
98-
if (tokenizedLine.length !== 2) {
99-
throw new Error("[BricksSyncParser] unexpected logs recieved");
100-
}
101-
const filePath = tokenizedLine[1];
67+
const filePath = match[1];
10268
if (!this.filesBeingDeleted.has(filePath)) {
10369
throw new Error(
10470
"[BricksSyncParser] untracked file deleted. All delete complete " +

packages/databricks-vscode/src/cli/BricksTasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class CustomSyncTerminal implements Pseudoterminal {
165165
/**
166166
* Wrapper around the CustomSyncTerminal class that lazily evaluates the process
167167
* and args properties. This is necessary because the process and args properties
168-
* re not known up front can only be computed dynamically at runtime.
168+
* are not known up front and can only be computed dynamically at runtime.
169169
*
170170
* A Custom implmentation of the terminal is needed to run bricks sync as a CustomExecution
171171
* vscode task, which allows us to parse the stdout/stderr bricks sync logs and compute

0 commit comments

Comments
 (0)