Add config option 'newFileMode' (umask number, or octal umask string)

pull/84/head
Kelvin Schoofs 6 years ago
parent 754ee26e8a
commit 35e3ab384c

@ -31,6 +31,7 @@ export interface FileSystemConfig extends ConnectConfig {
privateKeyPath?: string;
hop?: string;
sftpCommand?: string;
newFileMode?: number | string;
}
export enum ConfigStatus {

@ -106,17 +106,19 @@ 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 | undefined;
let mode: number | string | undefined;
try {
const stat = await this.continuePromise<ssh2s.Stats>(cb => this.sftp.stat(this.relative(uri.path), cb));
mode = stat.mode;
} catch (e) {
if (e.message !== 'No such file') {
if (e.message === 'No such file') {
mode = this.config.newFileMode;
} else {
console.log(e);
vscode.window.showWarningMessage(`Couldn't read the permissions for '${this.relative(uri.path)}', permissions might be overwritten`);
}
}
const array = new Buffer(0);
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(this.relative(uri.path), { mode, flags: 'w' });
stream.on('error', reject);
stream.end(content, resolve);

Loading…
Cancel
Save