Skip to content

[Bug?]: ZipFS extension broken on VSCode 1.66 #4322

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions packages/vscode-zipfs/sources/ZipFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {ZipOpenFS, VirtualFS, PosixFS, npath} from '@yarnpkg/fslib';
import {getLibzipSync} from '@yarnpkg/libzip';
import * as vscode from 'vscode';

import {parseUri} from './index';

export class ZipFSProvider implements vscode.FileSystemProvider {
private readonly fs = new PosixFS(
new VirtualFS({
Expand All @@ -14,11 +16,11 @@ export class ZipFSProvider implements vscode.FileSystemProvider {
);

stat(uri: vscode.Uri): vscode.FileStat {
const stat: any = this.fs.statSync(uri.fsPath);
const stat: any = this.fs.statSync(parseUri(uri));

switch (true) {
case stat.isDirectory():
case npath.extname(uri.fsPath) === `.zip`: {
case npath.extname(parseUri(uri)) === `.zip`: {
stat.type = vscode.FileType.Directory;
} break;

Expand All @@ -39,7 +41,7 @@ export class ZipFSProvider implements vscode.FileSystemProvider {
}

readDirectory(uri: vscode.Uri): Array<[string, vscode.FileType]> {
const listing = this.fs.readdirSync(uri.fsPath);
const listing = this.fs.readdirSync(parseUri(uri));

return listing.map(entry => {
const {type} = this.stat(vscode.Uri.joinPath(uri, entry));
Expand All @@ -48,28 +50,28 @@ export class ZipFSProvider implements vscode.FileSystemProvider {
}

readFile(uri: vscode.Uri): Uint8Array {
return this.fs.readFileSync(uri.fsPath);
return this.fs.readFileSync(parseUri(uri));
}

writeFile(uri: vscode.Uri, content: Uint8Array, options: {create: boolean, overwrite: boolean}): void {
if (!options.create && !this.fs.existsSync(uri.fsPath))
if (!options.create && !this.fs.existsSync(parseUri(uri)))
throw vscode.FileSystemError.FileNotFound(uri);
if (options.create && !options.overwrite && this.fs.existsSync(uri.fsPath))
if (options.create && !options.overwrite && this.fs.existsSync(parseUri(uri)))
throw vscode.FileSystemError.FileExists(uri);

this.fs.writeFileSync(uri.fsPath, Buffer.from(content));
this.fs.writeFileSync(parseUri(uri), Buffer.from(content));
}

rename(oldUri: vscode.Uri, newUri: vscode.Uri, options: { overwrite: boolean }): void {
throw new Error(`Not supported`);
}

delete(uri: vscode.Uri, options: {recursive: boolean}): void {
this.fs.removeSync(uri.fsPath, options);
this.fs.removeSync(parseUri(uri), options);
}

createDirectory(uri: vscode.Uri): void {
this.fs.mkdirSync(uri.fsPath);
this.fs.mkdirSync(parseUri(uri));
}

private _emitter = new vscode.EventEmitter<Array<vscode.FileChangeEvent>>();
Expand Down
12 changes: 10 additions & 2 deletions packages/vscode-zipfs/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import {npath} from '@yarnpkg/fslib';
import {npath, NativePath} from '@yarnpkg/fslib';
import path from 'path';
import * as vscode from 'vscode';

import {registerTerminalLinkProvider} from './TerminalLinkProvider';
import {ZipFSProvider} from './ZipFSProvider';


export function parseUri(uri: vscode.Uri): NativePath {
const p = `${path.sep}${uri.authority}${path.sep}${uri.fsPath}` as NativePath;

return p;
}

function mount(uri: vscode.Uri) {
const zipUri = vscode.Uri.parse(`zip:${uri.fsPath}`);
const zipUri = vscode.Uri.parse(`zip:${parseUri(uri)}`);

if (vscode.workspace.getWorkspaceFolder(zipUri) === undefined) {
vscode.workspace.updateWorkspaceFolders(vscode.workspace.workspaceFolders!.length, 0, {
Expand Down