Skip to content

Commit

Permalink
feat: support fetching at activation for saved files in-editor
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Sep 6, 2024
1 parent ba17684 commit bf910c5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
44 changes: 36 additions & 8 deletions packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,13 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem

const entryExists = entry != null;
let entryIsDir = entry != null ? entry.type === vscode.FileType.Directory : false;
const uriPath = uri.path.substring(uriInfo.slashAfterProfilePos + 1).split("/");
const pdsMember = uriPath.length === 2;
if (!entryExists) {
const resp = await ZoweExplorerApiRegister.getMvsApi(uriInfo.profile).dataSet(path.posix.basename(uri.path), { attributes: true });
const resp = await ZoweExplorerApiRegister.getMvsApi(uriInfo.profile).dataSet(uriPath[0], { attributes: true });
if (resp.success) {
const dsorg: string = resp.apiResponse?.items?.[0]?.dsorg;
entryIsDir = dsorg?.startsWith("PO") ?? false;
entryIsDir = pdsMember ? false : dsorg?.startsWith("PO") ?? false;
} else {
throw vscode.FileSystemError.FileNotFound(uri);
}
Expand All @@ -237,8 +239,13 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
}
await this.fetchEntriesForDataset(entry as PdsEntry, uri, uriInfo);
} else if (!entryExists) {
await this.writeFile(uri, new Uint8Array(), { create: true, overwrite: false });
entry = this._lookupAsFile(uri) as DsEntry;
this.createDirectory(uri.with({ path: path.posix.join(uri.path, "..") }));
const parentDir = this._lookupParentDirectory(uri);
const dsname = uriPath[Number(pdsMember)];
const ds = new DsEntry(dsname, pdsMember);
ds.metadata = new DsEntryMetadata({ path: path.posix.join(parentDir.metadata.path, dsname), profile: parentDir.metadata.profile });
parentDir.entries.set(dsname, ds);
entry = parentDir.entries.get(dsname) as DsEntry;
}

return entry;
Expand Down Expand Up @@ -382,7 +389,28 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
* @returns The data set's contents as an array of bytes
*/
public async readFile(uri: vscode.Uri): Promise<Uint8Array> {
const file = this._lookupAsFile(uri);
let ds: DsEntry | DirEntry;
try {
ds = this._lookupAsFile(uri) as DsEntry;
} catch (err) {
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
throw err;

Check warning on line 397 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L397

Added line #L397 was not covered by tests
}

// check if parent directory exists; if not, do a remote lookup
const parent = this._lookupParentDirectory(uri, true);

Check warning on line 401 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L401

Added line #L401 was not covered by tests
if (parent == null) {
ds = await this.remoteLookupForResource(uri);

Check warning on line 403 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L403

Added line #L403 was not covered by tests
}
}

if (ds == null) {
throw vscode.FileSystemError.FileNotFound(uri);

Check warning on line 408 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L408

Added line #L408 was not covered by tests
}
if (FsAbstractUtils.isDirectoryEntry(ds)) {
throw vscode.FileSystemError.FileIsADirectory(uri);

Check warning on line 411 in packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts#L411

Added line #L411 was not covered by tests
}

const profInfo = this._getInfoFromUri(uri);

if (profInfo.profile == null) {
Expand All @@ -393,14 +421,14 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
const isConflict = urlQuery.has("conflict");

// we need to fetch the contents from the mainframe if the file hasn't been accessed yet
if ((!file.wasAccessed && !urlQuery.has("inDiff")) || isConflict) {
if ((!ds.wasAccessed && !urlQuery.has("inDiff")) || isConflict) {
await this.fetchDatasetAtUri(uri, { isConflict });
if (!isConflict) {
file.wasAccessed = true;
ds.wasAccessed = true;
}
}

return isConflict ? file.conflictData.contents : file.data;
return isConflict ? ds.conflictData.contents : ds.data;
}

public makeEmptyDsWithEncoding(uri: vscode.Uri, encoding: ZosEncoding, isMember?: boolean): void {
Expand Down
23 changes: 22 additions & 1 deletion packages/zowe-explorer/src/trees/uss/UssFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,28 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
* @returns The file's contents as an array of bytes
*/
public async readFile(uri: vscode.Uri): Promise<Uint8Array> {
const file = this._lookupAsFile(uri, { silent: false });
let file: UssFile | UssDirectory;
try {
file = this._lookupAsFile(uri) as UssFile;
} catch (err) {
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
throw err;

Check warning on line 314 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L314

Added line #L314 was not covered by tests
}

// check if parent directory exists; if not, do a remote lookup
const parent = this._lookupParentDirectory(uri, true);

Check warning on line 318 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L318

Added line #L318 was not covered by tests
if (parent == null) {
file = await this.remoteLookupForResource(uri);

Check warning on line 320 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L320

Added line #L320 was not covered by tests
}
}

if (file == null) {
throw vscode.FileSystemError.FileNotFound(uri);

Check warning on line 325 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L325

Added line #L325 was not covered by tests
}
if (FsAbstractUtils.isDirectoryEntry(file)) {
throw vscode.FileSystemError.FileIsADirectory(uri);

Check warning on line 328 in packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts#L328

Added line #L328 was not covered by tests
}

const profInfo = this._getInfoFromUri(uri);

if (profInfo.profile == null) {
Expand Down

0 comments on commit bf910c5

Please sign in to comment.