Change default `newFileMode` from library-default 0o666 to 0o664 (#214)

pull/373/head
Kelvin Schoofs 3 years ago
parent 10cfa31484
commit af764380a6

@ -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

@ -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<string, string>;
/** 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;

@ -126,7 +126,7 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
}
public writeFile(uri: vscode.Uri, content: Uint8Array, options: { create: boolean; overwrite: boolean; }): void | Promise<void> {
return new Promise(async (resolve, reject) => {
let mode: number | string | undefined;
let mode: number | undefined;
let fileExists = false;
try {
const stat = await this.continuePromise<ssh2s.Stats>(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, () => {

@ -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<string, string>;
/** 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;

Loading…
Cancel
Save