From af764380a61c756207588181e91bc129bb78bc16 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Fri, 3 Dec 2021 18:17:55 +0100 Subject: [PATCH] Change default `newFileMode` from library-default 0o666 to 0o664 (#214) --- CHANGELOG.md | 5 +++++ src/fileSystemConfig.ts | 2 +- src/sshFileSystem.ts | 8 +++++--- webview/src/types/fileSystemConfig.ts | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3658ca1..8733052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ ## Unreleased +### Changes +- The default `newFileMode` is now `0o664` instead defaulting to the underlying library's `0o666` (#214) + - **This changes the permission for newly created files**, defaulting to `rw-rw-r--` instead of `rw-rw-rw-` + - While `0o664` is the default umask for non-root users and `0o644` for root, **we default to `0o664` regardless** + ### Development changes - Fix/improve `map-error.js` utility (now also uses `formatId` from `webpack.plugin.js`) - Update build process diff --git a/src/fileSystemConfig.ts b/src/fileSystemConfig.ts index 7a89a4e..5a591da 100644 --- a/src/fileSystemConfig.ts +++ b/src/fileSystemConfig.ts @@ -108,7 +108,7 @@ export interface FileSystemConfig extends ConnectConfig { taskCommand?: string | string[]; /** An object with environment variables to add to the SSH connection. Affects the whole connection thus all terminals */ environment?: EnvironmentVariable[] | Record; - /** The filemode to assign to created files */ + /** The filemode to assign to new files created using VS Code, not the terminal. Similar to umask. Defaults to `rw-rw-r--` (regardless of server config, whether you are root, ...) */ newFileMode?: number | string; /** Whether this config was created from an instant connection string. Enables fuzzy matching for e.g. PuTTY, config-by-host, ... */ instantConnection?: boolean; diff --git a/src/sshFileSystem.ts b/src/sshFileSystem.ts index 8ee33c8..b905680 100644 --- a/src/sshFileSystem.ts +++ b/src/sshFileSystem.ts @@ -126,7 +126,7 @@ export class SSHFileSystem implements vscode.FileSystemProvider { } public writeFile(uri: vscode.Uri, content: Uint8Array, options: { create: boolean; overwrite: boolean; }): void | Promise { return new Promise(async (resolve, reject) => { - let mode: number | string | undefined; + let mode: number | undefined; let fileExists = false; try { const stat = await this.continuePromise(cb => this.sftp.stat(uri.path, cb)); @@ -134,13 +134,15 @@ export class SSHFileSystem implements vscode.FileSystemProvider { fileExists = true; } catch (e) { if (e.message === 'No such file') { - mode = this.config.newFileMode; + mode = this.config.newFileMode as number; + if (typeof mode === 'string') mode = Number(mode); + if (typeof mode !== 'number') mode = 0o664; + if (Number.isNaN(mode)) throw new Error(`Invalid umask '${this.config.newFileMode}'`); } else { this.handleError(uri, e); vscode.window.showWarningMessage(`Couldn't read the permissions for '${uri.path}', permissions might be overwritten`); } } - mode = mode as number | undefined; // ssh2-streams supports an octal number as string, but ssh2's typings don't reflect this const stream = this.sftp.createWriteStream(uri.path, { mode, flags: 'w' }); stream.on('error', e => this.handleError(uri, e, reject)); stream.end(content, () => { diff --git a/webview/src/types/fileSystemConfig.ts b/webview/src/types/fileSystemConfig.ts index a35f309..39dc8c8 100644 --- a/webview/src/types/fileSystemConfig.ts +++ b/webview/src/types/fileSystemConfig.ts @@ -108,7 +108,7 @@ export interface FileSystemConfig extends ConnectConfig { taskCommand?: string | string[]; /** An object with environment variables to add to the SSH connection. Affects the whole connection thus all terminals */ environment?: EnvironmentVariable[] | Record; - /** The filemode to assign to created files */ + /** The filemode to assign to new files created using VS Code, not the terminal. Similar to umask. Defaults to `rw-rw-r--` (regardless of server config, whether you are root, ...) */ newFileMode?: number | string; /** Whether this config was created from an instant connection string. Enables fuzzy matching for e.g. PuTTY, config-by-host, ... */ instantConnection?: boolean;