Skip to content

Commit

Permalink
refactor: move checks into stat
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Sep 5, 2024
1 parent 10ea4d3 commit d36a62e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 48 deletions.
50 changes: 26 additions & 24 deletions packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
*/
public async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
ZoweLogger.trace(`[DatasetFSProvider] stat called with ${uri.toString()}`);
let entry: DsEntry | DirEntry;
let isFetching = false;
if (uri.query) {
const queryParams = new URLSearchParams(uri.query);
Expand All @@ -102,11 +103,33 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
}

const uriInfo = FsAbstractUtils.getInfoForUri(uri, Profiles.getInstance());
const entry = isFetching ? await this.remoteLookupForResource(uri) : this.lookup(uri, false);
// Do not perform remote lookup for profile or directory URIs; the code below is for change detection on PS or PDS members only
if (isFetching) {
entry = await this.remoteLookupForResource(uri);
} else {
try {
entry = this.lookup(uri, false) as DsEntry | DirEntry;
} catch (err) {
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
throw err;

Check warning on line 113 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#L113

Added line #L113 was not covered by tests
}

if (!uriInfo.isRoot) {
// we need to look up the resource since the parent folder doesn't exist
// (either user clicked on URI or it was left open in editor)
entry = await this.remoteLookupForResource(uri);
} else {
throw err;

Check warning on line 121 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#L119-L121

Added lines #L119 - L121 were not covered by tests
}
}
}

// Do not perform remote lookup for profile or directory URIs; the code below is for change detection on file entries only
if (uriInfo.isRoot || FsAbstractUtils.isDirectoryEntry(entry)) {
return entry;
}
if (entry == null) {
throw vscode.FileSystemError.FileNotFound(uri);

Check warning on line 131 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#L131

Added line #L131 was not covered by tests
}

ZoweLogger.trace(`[DatasetFSProvider] stat is locating resource ${uri.toString()}`);

Expand Down Expand Up @@ -382,28 +405,7 @@ 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> {
let ds: DsEntry | DirEntry;
try {
ds = this._lookupAsFile(uri) as DsEntry;
} catch (err) {
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
throw err;
}

// check if parent directory exists; if not, do a remote lookup
const parent = this._lookupParentDirectory(uri, true);
if (parent == null) {
ds = await this.remoteLookupForResource(uri);
}
}

if (ds == null) {
throw vscode.FileSystemError.FileNotFound(uri);
}
if (FsAbstractUtils.isDirectoryEntry(ds)) {
throw vscode.FileSystemError.FileIsADirectory(uri);
}

const ds = this._lookupAsFile(uri);
const profInfo = this._getInfoFromUri(uri);

if (profInfo.profile == null) {
Expand Down
50 changes: 26 additions & 24 deletions packages/zowe-explorer/src/trees/uss/UssFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
*/
public async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
ZoweLogger.trace(`[UssFSProvider] stat called with ${uri.toString()}`);
let entry: UssFile | UssDirectory;
let isFetching = false;
if (uri.query) {
const queryParams = new URLSearchParams(uri.query);
Expand All @@ -73,12 +74,34 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
isFetching = queryParams.has("fetch") && queryParams.get("fetch") === "true";
}

const entry = isFetching ? await this.remoteLookupForResource(uri) : this.lookup(uri, false);
const uriInfo = FsAbstractUtils.getInfoForUri(uri, Profiles.getInstance());
// Do not perform remote lookup for profile or directory URIs; the code below is for change detection on USS files only
if (isFetching) {
entry = await this.remoteLookupForResource(uri);

Check warning on line 79 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#L79

Added line #L79 was not covered by tests
} else {
try {
entry = this.lookup(uri, false) as UssFile | UssDirectory;
} catch (err) {
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
throw err;

Check warning on line 85 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#L85

Added line #L85 was not covered by tests
}

if (!uriInfo.isRoot) {
// we need to look up the resource since the parent folder doesn't exist
// (either user clicked on URI or it was left open in editor)
entry = await this.remoteLookupForResource(uri);
} else {
throw err;

Check warning on line 93 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#L91-L93

Added lines #L91 - L93 were not covered by tests
}
}
}

// Do not perform remote lookup for profile or directory URIs; the code below is for change detection on file entries only
if (uriInfo.isRoot || FsAbstractUtils.isDirectoryEntry(entry)) {
return entry;
}
if (entry == null) {
throw vscode.FileSystemError.FileNotFound(uri);

Check warning on line 103 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#L103

Added line #L103 was not covered by tests
}

ZoweLogger.trace(`[UssFSProvider] stat is locating resource ${uri.toString()}`);

Expand Down Expand Up @@ -306,28 +329,7 @@ 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> {
let file: UssFile | UssDirectory;
try {
file = this._lookupAsFile(uri) as UssFile;
} catch (err) {
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
throw err;
}

// check if parent directory exists; if not, do a remote lookup
const parent = this._lookupParentDirectory(uri, true);
if (parent == null) {
file = await this.remoteLookupForResource(uri);
}
}

if (file == null) {
throw vscode.FileSystemError.FileNotFound(uri);
}
if (FsAbstractUtils.isDirectoryEntry(file)) {
throw vscode.FileSystemError.FileIsADirectory(uri);
}

const file = this._lookupAsFile(uri, { silent: false });
const profInfo = this._getInfoFromUri(uri);

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

0 comments on commit d36a62e

Please sign in to comment.