From 201a9ad4ee4b890730b201c79d2fdeaa459a69d9 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Sun, 6 May 2018 01:18:08 +0200 Subject: [PATCH] Fix bug where saving a file resets the permissions (when owner/root at least) --- README.md | 1 + src/sshFileSystem.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5900511..e948f1c 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ This will add a Workspace folder linked to a SSH (SFTP) session: ![Workspace folder added](./media/screenshot-explorer.png) ## TO DO *(in order of most likely to implement first)* +* ~~Fix bug where saving a file resets the permissions (when owner/root at least)~~ **DONE** * Fix bug where the Explorer shows a loading bar forever * Fix bug where VSCode shows an error message about `no provider for ssh://NAME/` * An icon for the extension diff --git a/src/sshFileSystem.ts b/src/sshFileSystem.ts index 5206b01..c819098 100644 --- a/src/sshFileSystem.ts +++ b/src/sshFileSystem.ts @@ -71,9 +71,10 @@ export class SSHFileSystem implements vscode.FileSystemProvider { }); } public writeFile(uri: vscode.Uri, content: Uint8Array, options: { create: boolean; overwrite: boolean; }): void | Promise { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { + const stat = await toPromise(cb => this.sftp.stat(this.relative(uri.path), cb)); const array = new Buffer(0); - const stream = this.sftp.createWriteStream(this.relative(uri.path)); + const stream = this.sftp.createWriteStream(this.relative(uri.path), { mode: stat.mode }); stream.on('error', reject); stream.end(content, resolve); });