Skip to content

Commit

Permalink
Merge pull request #7 from zowe/fix/ssh-sample-fsp
Browse files Browse the repository at this point in the history
Fix SSH sample ext to work with FileSystemProvider
  • Loading branch information
t1m0thyj authored Jan 7, 2025
2 parents a5e20d8 + 8df7b9a commit aeb6923
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions vscode-extension-samples/uss-profile-sample/src/SshUssApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ export class SshUssApi implements MainframeInteraction.IUss {
public async fileList(ussFilePath: string): Promise<zosfiles.IZosFilesResponse> {
return this.withClient(this.getSession(), async (client) => {
const response = [];
for (const fileInfo of await client.list(ussFilePath)) {
response.push({
name: fileInfo.name,
mode: fileInfo.type + fileInfo.owner + fileInfo.group + fileInfo.rights.other,
size: fileInfo.size,
uid: fileInfo.owner,
gid: fileInfo.group,
mtime: fileInfo.modifyTime.toString(),
});
if ((await client.stat(ussFilePath)).isDirectory) {
for (const fileInfo of await client.list(ussFilePath)) {
const permString = Object.values(fileInfo.rights).reduce((all, perm) => all.concat(perm), fileInfo.type);
response.push({
name: fileInfo.name,
mode: permString,
size: fileInfo.size,
uid: fileInfo.owner,
gid: fileInfo.group,
mtime: fileInfo.modifyTime,
});
}
}
return this.buildZosFilesResponse({ items: response });
});
Expand All @@ -50,12 +53,16 @@ export class SshUssApi implements MainframeInteraction.IUss {
return Promise.resolve(false);
}

public async getContents(ussFilePath: string, options: zosfiles.IDownloadOptions): Promise<zosfiles.IZosFilesResponse> {
public async getContents(ussFilePath: string, options: zosfiles.IDownloadSingleOptions): Promise<zosfiles.IZosFilesResponse> {
return this.withClient(this.getSession(), async (client) => {
const localPath = options.file as string;
imperative.IO.createDirsSyncFromFilePath(localPath);
const response = await client.fastGet(ussFilePath, localPath);
return this.buildZosFilesResponse(response);
if (options.file != null) {
imperative.IO.createDirsSyncFromFilePath(options.file);
await client.fastGet(ussFilePath, options.file);
} else if (options.stream != null) {
options.stream.write(await client.get(ussFilePath));
options.stream.end();
}
return this.buildZosFilesResponse({ etag: ussFilePath });
});
}

Expand All @@ -66,7 +73,7 @@ export class SshUssApi implements MainframeInteraction.IUss {
});
}

public async putContent(inputFilePath: string, ussFilePath: string): Promise<zosfiles.IZosFilesResponse> {
public async putContent(inputFilePath: string, ussFilePath: string, _options?: zosfiles.IUploadOptions): Promise<zosfiles.IZosFilesResponse> {
return this.withClient(this.getSession(), async (client) => {
const response = await client.fastPut(inputFilePath, ussFilePath);
return this.buildZosFilesResponse(response);
Expand Down Expand Up @@ -119,6 +126,9 @@ export class SshUssApi implements MainframeInteraction.IUss {
password: session.ISession.password,
});
return await callback(client);
} catch (err) {
console.error(err);
return Promise.reject<T>(err);
} finally {
await client.end();
}
Expand Down

0 comments on commit aeb6923

Please sign in to comment.