mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 09:35:38 -05:00
Replace URL and use vscode.URI on local paths (#11624)
* Use vscode.URI for local paths * Use vscode.uri file method to set the name for remotebookfull path compressed file * Add await on extract tar function * Replace remote paths too * Use vscode.uri.file instead of parse for local paths
This commit is contained in:
@@ -15,14 +15,14 @@ import { IAsset } from './remoteBookController';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
export class GitHubRemoteBook extends RemoteBook {
|
||||
constructor(public remotePath: URL, public outputChannel: vscode.OutputChannel, protected _asset: IAsset) {
|
||||
constructor(public remotePath: vscode.Uri, public outputChannel: vscode.OutputChannel, protected _asset: IAsset) {
|
||||
super(remotePath, outputChannel, _asset);
|
||||
}
|
||||
|
||||
public async createLocalCopy(): Promise<void> {
|
||||
this.outputChannel.show(true);
|
||||
this.setLocalPath();
|
||||
this.outputChannel.appendLine(loc.msgDownloadLocation(this._localPath.href));
|
||||
this.outputChannel.appendLine(loc.msgDownloadLocation(this._localPath.fsPath));
|
||||
this.outputChannel.appendLine(loc.msgRemoteBookDownloadProgress);
|
||||
this.createDirectory();
|
||||
let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
@@ -35,7 +35,7 @@ export class GitHubRemoteBook extends RemoteBook {
|
||||
'timeout': downloadTimeout
|
||||
}
|
||||
};
|
||||
let downloadRequest = request.get(this._asset.browserDownloadUrl.href, options)
|
||||
let downloadRequest = request.get(this._asset.browserDownloadUrl.toString(false), options)
|
||||
.on('error', (error) => {
|
||||
this.outputChannel.appendLine(loc.msgRemoteBookDownloadError);
|
||||
this.outputChannel.appendLine(error.message);
|
||||
@@ -47,8 +47,8 @@ export class GitHubRemoteBook extends RemoteBook {
|
||||
return reject(new Error(loc.httpRequestError(response.statusCode, response.statusMessage)));
|
||||
}
|
||||
});
|
||||
let remoteBookFullPath = new URL(this._localPath.href.concat('.zip'));
|
||||
downloadRequest.pipe(fs.createWriteStream(remoteBookFullPath.href))
|
||||
let remoteBookFullPath = vscode.Uri.file(this._localPath.fsPath.concat('.', this._asset.format));
|
||||
downloadRequest.pipe(fs.createWriteStream(remoteBookFullPath.fsPath))
|
||||
.on('close', async () => {
|
||||
resolve(this.extractFiles(remoteBookFullPath));
|
||||
})
|
||||
@@ -62,34 +62,32 @@ export class GitHubRemoteBook extends RemoteBook {
|
||||
}
|
||||
public async createDirectory(): Promise<void> {
|
||||
let fileName = this._asset.book.concat('-').concat(this._asset.version).concat('-').concat(this._asset.language);
|
||||
this._localPath = new URL(path.join(this._localPath.href, fileName));
|
||||
this._localPath = vscode.Uri.file(path.join(this._localPath.fsPath, fileName));
|
||||
try {
|
||||
let exists = await fs.pathExists(this._localPath.href);
|
||||
let exists = await fs.pathExists(this._localPath.fsPath);
|
||||
if (exists) {
|
||||
await fs.remove(this._localPath.href);
|
||||
await fs.remove(this._localPath.fsPath);
|
||||
}
|
||||
await fs.promises.mkdir(this._localPath.href);
|
||||
await fs.promises.mkdir(this._localPath.fsPath);
|
||||
} catch (error) {
|
||||
this.outputChannel.appendLine(loc.msgRemoteBookDirectoryError);
|
||||
this.outputChannel.appendLine(error.message);
|
||||
}
|
||||
}
|
||||
public async extractFiles(remoteBookFullPath: URL): Promise<void> {
|
||||
public async extractFiles(remoteBookFullPath: vscode.Uri): Promise<void> {
|
||||
try {
|
||||
if (utils.getOSPlatform() === utils.Platform.Windows || utils.getOSPlatform() === utils.Platform.Mac) {
|
||||
let zippedFile = new zip(remoteBookFullPath.href);
|
||||
zippedFile.extractAllTo(this._localPath.href);
|
||||
let zippedFile = new zip(remoteBookFullPath.fsPath);
|
||||
zippedFile.extractAllTo(this._localPath.fsPath);
|
||||
} else {
|
||||
tar.extract({ file: remoteBookFullPath.href, cwd: this._localPath.href }).catch(error => {
|
||||
this.outputChannel.appendLine(loc.msgRemoteBookUnpackingError);
|
||||
this.outputChannel.appendLine(error.message);
|
||||
});
|
||||
await tar.extract({ file: remoteBookFullPath.fsPath, cwd: this._localPath.fsPath });
|
||||
}
|
||||
await fs.promises.unlink(remoteBookFullPath.href);
|
||||
await fs.promises.unlink(remoteBookFullPath.fsPath);
|
||||
this.outputChannel.appendLine(loc.msgRemoteBookDownloadComplete);
|
||||
vscode.commands.executeCommand('notebook.command.openNotebookFolder', this._localPath.href, undefined, true);
|
||||
vscode.commands.executeCommand('notebook.command.openNotebookFolder', this._localPath.fsPath, undefined, true);
|
||||
}
|
||||
catch (err) {
|
||||
this.outputChannel.appendLine(loc.msgRemoteBookUnpackingError);
|
||||
this.outputChannel.appendLine(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user