Skip to content

Commit cde43f0

Browse files
committed
fix:parse structure log output for work dir
1 parent 2195eb9 commit cde43f0

File tree

4 files changed

+36
-45
lines changed

4 files changed

+36
-45
lines changed
File renamed without changes.

client/src/connection/itc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import {
1818
getSecretStorage,
1919
} from "../../components/ExtensionContext";
2020
import { updateStatusBarItem } from "../../components/StatusBarItem";
21-
import { LineParser } from "../LineParser";
2221
import { Session } from "../session";
2322
import { extractOutputHtmlFileName } from "../util";
23+
import { LineParser } from "./LineParser";
2424
import {
2525
ERROR_END_TAG,
2626
ERROR_START_TAG,

client/src/connection/ssh/const.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const MINUTE = 60 * SECOND;
66
export const KEEPALIVE_INTERVAL = 60 * SECOND; //How often (in milliseconds) to send SSH-level keepalive packets to the server. Set to 0 to disable.
77
export const KEEPALIVE_UNANSWERED_THRESHOLD =
88
(15 * MINUTE) / KEEPALIVE_INTERVAL; //How many consecutive, unanswered SSH-level keepalive packets that can be sent to the server before disconnection.
9-
export const WORK_DIR_START_TAG = "<WorkDirectory>";
10-
export const WORK_DIR_END_TAG = "</WorkDirectory>";
9+
export const WORK_DIR_START_TAG = "WORKDIR";
10+
export const WORK_DIR_END_TAG = "WORKDIREND";
1111
export const CONNECT_READY_TIMEOUT = 5 * MINUTE; //allow extra time due to possible prompting

client/src/connection/ssh/index.ts

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717

1818
import { BaseConfig, RunResult } from "..";
1919
import { updateStatusBarItem } from "../../components/StatusBarItem";
20-
import { LineParser } from "../LineParser";
2120
import { Session } from "../session";
2221
import { extractOutputHtmlFileName } from "../util";
2322
import { AuthHandler } from "./auth";
@@ -56,7 +55,6 @@ export class SSHSession extends Session {
5655
private _sessionReady: boolean;
5756
private _authHandler: AuthHandler;
5857
private _workDirectory: string;
59-
private _workDirectoryParser: LineParser;
6058
private _authsLeft: AuthenticationType[];
6159

6260
constructor(c?: Config, client?: Client) {
@@ -65,11 +63,6 @@ export class SSHSession extends Session {
6563
this._conn = client;
6664
this._sessionReady = false;
6765
this._authHandler = new AuthHandler();
68-
this._workDirectoryParser = new LineParser(
69-
WORK_DIR_START_TAG,
70-
WORK_DIR_END_TAG,
71-
false,
72-
);
7366
this._authsLeft = [];
7467
}
7568

@@ -181,19 +174,23 @@ export class SSHSession extends Session {
181174

182175
s.on("data", (data) => {
183176
fileContents += data.toString();
184-
}).on("close", (code) => {
185-
const rc: number = code;
186-
187-
if (rc === 0) {
188-
//Make sure that the html has a valid body
189-
//TODO #185: should this be refactored into a shared location?
190-
if (fileContents.search('<*id="IDX*.+">') !== -1) {
191-
runResult.html5 = fileContents;
192-
runResult.title = l10n.t("Result");
177+
})
178+
.on("close", (code) => {
179+
const rc: number = code;
180+
181+
if (rc === 0) {
182+
//Make sure that the html has a valid body
183+
//TODO #185: should this be refactored into a shared location?
184+
if (fileContents.search('<*id="IDX*.+">') !== -1) {
185+
runResult.html5 = fileContents;
186+
runResult.title = l10n.t("Result");
187+
}
193188
}
194-
}
195-
this._resolve?.(runResult);
196-
});
189+
this._resolve?.(runResult);
190+
})
191+
.on("error", (err) => {
192+
console.log(err);
193+
});
197194
},
198195
);
199196
};
@@ -203,22 +200,15 @@ export class SSHSession extends Session {
203200
updateStatusBarItem(false);
204201
};
205202

206-
private fetchWorkDirectory = (line: string): string => {
207-
const foundWorkDirectory = this._workDirectoryParser.processLine(line);
208-
// We don't want to output any of the captured lines
209-
if (this._workDirectoryParser.isCapturingLine()) {
210-
return;
211-
}
212-
213-
return foundWorkDirectory || "";
214-
};
215-
216203
private resolveSystemVars = (): void => {
217-
const code = `%let workDir = %sysfunc(pathname(work));
218-
%put ${WORK_DIR_START_TAG}&workDir${WORK_DIR_END_TAG};
219-
%let rc = %sysfunc(dlgcdir("&workDir"));
220-
run;
221-
`;
204+
const code = `%let wd = %sysfunc(pathname(work));
205+
%let rc = %sysfunc(dlgcdir("&wd"));
206+
data _null_; length x $ 4096;
207+
file STDERR;
208+
x = resolve('&wd'); put '${WORK_DIR_START_TAG}' x '${WORK_DIR_END_TAG}';
209+
run;
210+
211+
`;
222212
this._stream.write(code);
223213
};
224214

@@ -233,6 +223,15 @@ export class SSHSession extends Session {
233223
return;
234224
}
235225

226+
if (this._sessionReady && !this._workDirectory) {
227+
const match = output.match(
228+
`${WORK_DIR_START_TAG}(/[\\s\\S]*?)${WORK_DIR_END_TAG}`,
229+
);
230+
if (match && match.length > 1) {
231+
this._workDirectory = match[1].trimEnd().replace(/(\r\n|\n|\r)/gm, "");
232+
}
233+
}
234+
236235
const outputLines = output.split(/\n|\r\n/);
237236
outputLines.forEach((line) => {
238237
if (!line) {
@@ -250,14 +249,6 @@ export class SSHSession extends Session {
250249
);
251250
this._onExecutionLogFn?.([{ type: "normal", line }]);
252251
}
253-
254-
if (this._sessionReady && !this._workDirectory) {
255-
const foundWorkDir = this.fetchWorkDirectory(line);
256-
if (foundWorkDir) {
257-
const match = foundWorkDir.match(/\/[^\s\r]+/);
258-
this._workDirectory = match ? match[0] : "";
259-
}
260-
}
261252
});
262253
};
263254

0 commit comments

Comments
 (0)