Skip to content

Commit

Permalink
fix: get working directory via IOM API (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
scnwwu committed Aug 27, 2024
1 parent d2ce76a commit 23f4644
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
12 changes: 1 addition & 11 deletions client/src/connection/itc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,7 @@ export class ITCSession extends Session {
};

private fetchWorkDirectory = (line: string): string | undefined => {
let foundWorkDirectory = "";
if (
!line.includes(`%put ${WORK_DIR_START_TAG};`) &&
!line.includes(`%put &workDir;`) &&
!line.includes(`%put ${WORK_DIR_END_TAG};`)
) {
foundWorkDirectory = this._workDirectoryParser.processLine(line);
} else {
// If the line is the put statement, we don't need to log that
return;
}
const foundWorkDirectory = this._workDirectoryParser.processLine(line);
// We don't want to output any of the captured lines
if (this._workDirectoryParser.isCapturingLine()) {
return;
Expand Down
32 changes: 21 additions & 11 deletions client/src/connection/itc/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ class SASRunner{
[System.__ComObject] $objSAS
[void]ResolveSystemVars(){
$code =
@'
%let workDir = %sysfunc(pathname(work));
%put ${WORK_DIR_START_TAG};
%put &workDir;
%put ${WORK_DIR_END_TAG};
%let rc = %sysfunc(dlgcdir("&workDir"));
run;
'@
$this.Run($code)
$this.FlushLogLines(4096, $false)
try {
Write-Host "${WORK_DIR_START_TAG}"
Write-Host $this.GetWorkDir()
Write-Host "${WORK_DIR_END_TAG}"
} catch {
Write-Error "${ERROR_START_TAG}Setup error: $_${ERROR_END_TAG}"
}
}
[void]Setup([string]$profileHost, [string]$username, [string]$password, [int]$port, [int]$protocol, [string]$serverName, [string]$displayLang) {
try {
Expand Down Expand Up @@ -87,6 +83,20 @@ class SASRunner{
}
}
[string]GetWorkDir() {
$fieldInclusionMask = ($false, $false, $false, $true, $false)
[ref]$engineName = [string[]]@()
[ref]$engineAttrs = New-Object 'int[,]' 0,0
[ref]$libraryAttrs = [int[]]@()
[ref]$physicalName = [string[]]::new(1)
[ref]$infoPropertyNames = New-Object 'string[,]' 0,0
[ref]$infoPropertyValues = New-Object 'string[,]' 0,0
$lib = $this.objSAS.DataService.UseLibref("work")
$lib.LevelInfo([bool[]]$fieldInclusionMask,$engineName,$engineAttrs,$libraryAttrs,
$physicalName,$infoPropertyNames,$infoPropertyValues)
return $physicalName.Value[0]
}
[void]Run([string]$code) {
try{
$this.objSAS.LanguageService.Reset()
Expand Down
9 changes: 0 additions & 9 deletions client/test/connection/itc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ describe("ITC connection", () => {
it("creates a well-formed local session", async () => {
const setupPromise = session.setup();

onDataCallback(Buffer.from(`%put ${WORK_DIR_START_TAG};`));
onDataCallback(Buffer.from(`%put &workDir;`));
onDataCallback(Buffer.from(`%put ${WORK_DIR_END_TAG};`));
onDataCallback(Buffer.from(`${WORK_DIR_START_TAG}`));
onDataCallback(Buffer.from(`/work/dir`));
onDataCallback(Buffer.from(`${WORK_DIR_END_TAG}`));
Expand Down Expand Up @@ -141,9 +138,6 @@ describe("ITC connection", () => {
beforeEach(async () => {
writeFileSync(tempHtmlPath, html5);
const setupPromise = session.setup();
onDataCallback(Buffer.from(`%put ${WORK_DIR_START_TAG};`));
onDataCallback(Buffer.from(`%put &workDir;`));
onDataCallback(Buffer.from(`%put ${WORK_DIR_END_TAG};`));
onDataCallback(Buffer.from(`${WORK_DIR_START_TAG}`));
onDataCallback(Buffer.from(`/work/dir`));
onDataCallback(Buffer.from(`${WORK_DIR_END_TAG}`));
Expand Down Expand Up @@ -195,9 +189,6 @@ $runner.FetchResultsFile($filePath, $outputFile)
describe("close", () => {
beforeEach(async () => {
const setupPromise = session.setup();
onDataCallback(Buffer.from(`%put ${WORK_DIR_START_TAG};`));
onDataCallback(Buffer.from(`%put &workDir;`));
onDataCallback(Buffer.from(`%put ${WORK_DIR_END_TAG};`));
onDataCallback(Buffer.from(`${WORK_DIR_START_TAG}`));
onDataCallback(Buffer.from(`/work/dir`));
onDataCallback(Buffer.from(`${WORK_DIR_END_TAG}`));
Expand Down

0 comments on commit 23f4644

Please sign in to comment.