Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'create remote folder' and 'create remote file' commands. #18

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,923 changes: 8,923 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

44 changes: 36 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@
"title": "Delete",
"category": "SFTP"
},
{
"command": "sftp.create.folder",
"title": "Create Folder",
"category": "SFTP"
},
{
"command": "sftp.create.file",
"title": "Create File",
"category": "SFTP"
},
{
"command": "sftp.revealInExplorer",
"title": "Reveal in Explorer",
Expand Down Expand Up @@ -338,6 +348,14 @@
"command": "sftp.delete.remote",
"when": "false"
},
{
"command": "sftp.create.folder",
"when": "false"
},
{
"command": "sftp.create.file",
"when": "false"
},
{
"command": "sftp.revealInExplorer",
"when": "false"
Expand Down Expand Up @@ -474,6 +492,16 @@
"command": "sftp.delete.remote",
"group": "7_modification",
"when": "view == remoteExplorer && viewItem != root"
},
{
"command": "sftp.create.folder",
"group": "7_modification",
"when": "view == remoteExplorer && viewItem != file"
},
{
"command": "sftp.create.file",
"group": "7_modification",
"when": "view == remoteExplorer && viewItem != file"
}
],
"scm/title": [
Expand Down Expand Up @@ -535,30 +563,30 @@
"@types/fs-extra": "^5.0.4",
"@types/jest": "^23.3.5",
"@types/lru-cache": "^4.1.1",
"@types/node": "^8.10.25",
"@types/node": "^8.10.51",
"@types/webpack-env": "^1.13.6",
"jest": "^20.0.4",
"memfs": "^2.15.5",
"rimraf": "^2.6.2",
"rimraf": "^2.7.1",
"ts-loader": "^5.3.0",
"tslint": "^5.11.0",
"typescript": "3.1.6",
"typescript-tslint-plugin": "^0.0.6",
"vscode": "^1.1.17",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"
"vscode": "^1.1.36",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7"
},
"dependencies": {
"async": "^2.6.0",
"async": "^2.6.3",
"fs-extra": "^5.0.0",
"ftp": "^0.3.10",
"ignore": "^5.0.2",
"ignore": "^5.1.4",
"joi": "^10.6.0",
"lodash.debounce": "^4.0.8",
"lru-cache": "^4.1.3",
"p-queue": "2.4.2",
"ssh-config": "^1.1.3",
"ssh2": "^0.8.2",
"ssh2": "^0.8.5",
"tmp": "^0.0.33",
"upath": "^1.0.0"
},
Expand Down
Binary file added sftp-1.12.7.vsix
Binary file not shown.
Binary file added sftp-1.12.8.vsix
Binary file not shown.
49 changes: 49 additions & 0 deletions src/commands/fileCommandCreateFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { COMMAND_CREATE_FILE } from '../constants';
import { createRemoteFile } from '../fileHandlers';
// import { showConfirmMessage } from '../host';
import { checkFileCommand } from './abstract/createCommand';
import { uriFromExplorerContextOrEditorContext } from './shared';
import { window, Uri } from 'vscode';

export default checkFileCommand({
id: COMMAND_CREATE_FILE,
async getFileTarget(item, items) {
const targets = await uriFromExplorerContextOrEditorContext(item, items);

if (!targets) {
return;
}
/* const filename = Array.isArray(targets)
? targets.map(t => upath.basename(t.fsPath)).join(',')
: upath.basename(targets.fsPath);
*/
const result = await window.showInputBox({
value: '',
prompt: 'Please input file name',
});


if (result !== undefined) {
// window.showInformationMessage(targets.toString() + '%252F' + result);

return Uri.parse(targets.toString() + '/' + result);
}


return undefined;

/*
const filename = Array.isArray(targets)
? targets.map(t => upath.basename(t.fsPath)).join(',')
: upath.basename(targets.fsPath);
const result = await showConfirmMessage(
`Are you sure you want to delete '${filename}'?`,
'Delete',
'Cancel'
);

return result ? targets : undefined;*/
},

handleFile: createRemoteFile,
});
49 changes: 49 additions & 0 deletions src/commands/fileCommandCreateFolder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { COMMAND_CREATE_FOLDER } from '../constants';
import { createRemoteFolder } from '../fileHandlers';
// import { showConfirmMessage } from '../host';
import { checkFileCommand } from './abstract/createCommand';
import { uriFromExplorerContextOrEditorContext } from './shared';
import { window, Uri } from 'vscode';

export default checkFileCommand({
id: COMMAND_CREATE_FOLDER,
async getFileTarget(item, items) {
const targets = await uriFromExplorerContextOrEditorContext(item, items);

if (!targets) {
return;
}
/* const filename = Array.isArray(targets)
? targets.map(t => upath.basename(t.fsPath)).join(',')
: upath.basename(targets.fsPath);
*/
const result = await window.showInputBox({
value: '',
prompt: 'Please input folder name',
});


if (result !== undefined) {
// window.showInformationMessage(targets.toString() + '%252F' + result);

return Uri.parse(targets.toString() + '/' + result);
}


return undefined;

/*
const filename = Array.isArray(targets)
? targets.map(t => upath.basename(t.fsPath)).join(',')
: upath.basename(targets.fsPath);
const result = await showConfirmMessage(
`Are you sure you want to delete '${filename}'?`,
'Delete',
'Cancel'
);

return result ? targets : undefined;*/
},

handleFile: createRemoteFolder,
});
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ export const COMMAND_REVEAL_IN_REMOTE_EXPLORER = 'sftp.revealInRemoteExplorer';
export const COMMAND_REMOTEEXPLORER_REFRESH = 'sftp.remoteExplorer.refresh';
export const COMMAND_REMOTEEXPLORER_EDITINLOCAL = 'sftp.remoteExplorer.editInLocal';
export const COMMAND_REMOTEEXPLORER_VIEW_CONTENT = 'sftp.viewContent';

export const COMMAND_CREATE_FOLDER = 'sftp.create.folder';
export const COMMAND_CREATE_FILE = 'sftp.create.file';
24 changes: 24 additions & 0 deletions src/core/fileBaseOperations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { FileSystem } from './fs';
import { window } from 'vscode';
import { Readable } from 'stream';
import logger from '../logger';

interface FileOption {
mode?: number;
Expand Down Expand Up @@ -44,3 +47,24 @@ export function removeDir(path: string, fs: FileSystem, option): Promise<void> {
export function rename(srcPath: string, destPath: string, fs: FileSystem): Promise<void> {
return fs.rename(srcPath, destPath);
}

export function createDir(path: string, fs: FileSystem, option): Promise<void> {
return fs.mkdir(path);
}

export async function createFile(path: string, fs: FileSystem, option): Promise<void> {
try {
await fs.lstat(path);
logger.warn(`Can't create file becase file already exist`);
window.showErrorMessage(`Can't create file becase file already exist`);
return;
} catch (error) {

}

const targetFd = await fs.open(path, 'w');
const s = new Readable();
s._read = () => { };
s.push(null);
return fs.put(s, path, { fd: targetFd });
}
86 changes: 86 additions & 0 deletions src/fileHandlers/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { refreshRemoteExplorer } from './shared';
import { fileOperations } from '../core';
import createFileHandler from './createFileHandler';
import { FileHandleOption } from './option';

export const createRemoteFile = createFileHandler<FileHandleOption & { skipDir?: boolean }>({
name: 'createRemoteFile',
async handle(option) {
const remoteFs = await this.fileService.getRemoteFileSystem(this.config);
const { remoteFsPath } = this.target;

let promise;
promise = fileOperations.createFile(remoteFsPath, remoteFs, {});

/*

const stat = await remoteFs.lstat(remoteFsPath);

switch (stat.type) {
case FileType.Directory:
if (option.skipDir) {
return;
}
promise = fileOperations.createDir(remoteFsPath, remoteFs, {});
// promise = fileOperations.removeDir(remoteFsPath, remoteFs, {});
break;
case FileType.File:
case FileType.SymbolicLink:
// promise = fileOperations.removeFile(remoteFsPath, remoteFs, {});
break;
default:
throw new Error(`Unsupported file type (type = ${stat.type})`);
}*/
await promise;
},
transformOption() {
const config = this.config;
return {
ignore: config.ignore,
};
},
afterHandle() {
refreshRemoteExplorer(this.target, true);
},
});

export const createRemoteFolder = createFileHandler<FileHandleOption & { skipDir?: boolean }>({
name: 'createRemoteFolder',
async handle(option) {
const remoteFs = await this.fileService.getRemoteFileSystem(this.config);
const { remoteFsPath } = this.target;

let promise;
promise = fileOperations.createDir(remoteFsPath, remoteFs, {});

/*

const stat = await remoteFs.lstat(remoteFsPath);

switch (stat.type) {
case FileType.Directory:
if (option.skipDir) {
return;
}
promise = fileOperations.createDir(remoteFsPath, remoteFs, {});
// promise = fileOperations.removeDir(remoteFsPath, remoteFs, {});
break;
case FileType.File:
case FileType.SymbolicLink:
// promise = fileOperations.removeFile(remoteFsPath, remoteFs, {});
break;
default:
throw new Error(`Unsupported file type (type = ${stat.type})`);
}*/
await promise;
},
transformOption() {
const config = this.config;
return {
ignore: config.ignore,
};
},
afterHandle() {
refreshRemoteExplorer(this.target, true);
},
});
1 change: 1 addition & 0 deletions src/fileHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './transfer';
export * from './remove';
export * from './diff';
export * from './rename';
export * from './create';
export { handleCtxFromUri, FileHandlerContext } from './createFileHandler';