Skip to content

Fix FileSystemProvider mtime caching #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
const name = item.Name;
const fullName = folder === "" ? name : csp ? folder + name : folder + "/" + name;
if (item.Type === "10" || item.Type === "9") {
parent.entries.set(name, new Directory(name, fullName));
if (!parent.entries.has(name)) {
parent.entries.set(name, new Directory(name, fullName));
}
return [name, vscode.FileType.Directory];
} else {
return [name, vscode.FileType.File];
Expand Down Expand Up @@ -131,7 +133,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
}

public async readFile(uri: vscode.Uri): Promise<Uint8Array> {
return this._lookupAsFile(uri).then((file: File) => {
// Use _lookup() instead of _lookupAsFile() so we send
// our cached mtime with the GET /doc request if we have it
return this._lookup(uri).then((file: File) => {
// Update cache entry
const uniqueId = `${workspaceFolderOfUri(uri)}:${file.fileName}`;
workspaceState.update(`${uniqueId}:mtime`, file.mtime);
Expand Down Expand Up @@ -180,7 +184,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
return;
}
const api = new AtelierAPI(uri);
return this._lookupAsFile(uri).then(
// Use _lookup() instead of _lookupAsFile() so we send
// our cached mtime with the GET /doc request if we have it
return this._lookup(uri).then(
() => {
// Weirdly, if the file exists on the server we don't actually write its content here.
// Instead we simply return as though we wrote it successfully.
Expand Down Expand Up @@ -311,7 +317,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
child = entry.entries.get(part);
// If the last element of path is dotted and is one we haven't already cached as a directory
// then it is assumed to be a file.
if (!part.includes(".") || i + 1 < parts.length) {
if ((!part.includes(".") || i + 1 < parts.length) && !child) {
const fullName = entry.name === "" ? part : entry.fullName + "/" + part;
child = new Directory(part, fullName);
entry.entries.set(part, child);
Expand Down