This commit is contained in:
bwcx_jzy 2022-06-12 23:18:35 +08:00
parent a6894a78fb
commit b81f0f4c69
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
6 changed files with 12 additions and 18 deletions

View File

@ -366,7 +366,7 @@ public class ReleaseManage implements Runnable {
logRecorder.info("发布目录为空");
} else {
logRecorder.info("{} {} start ftp upload", DateUtil.now(), item.getName());
try (Sftp sftp = new Sftp(session, item.getCharsetT(), item.timeout())) {
try (Sftp sftp = new Sftp(session, item.charset(), item.timeout())) {
String prefix = "";
if (!StrUtil.startWith(releasePath, StrUtil.SLASH)) {
prefix = sftp.pwd();

View File

@ -198,7 +198,7 @@ public class SshFileController extends BaseServerController {
Sftp sftp = null;
try {
Session session = SshService.getSessionByModel(sshModel);
sftp = new Sftp(session, sshModel.getCharsetT(), sshModel.timeout());
sftp = new Sftp(session, sshModel.charset(), sshModel.timeout());
String normalize = FileUtil.normalize(path + StrUtil.SLASH + name);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
sftp.download(normalize, byteArrayOutputStream);
@ -221,7 +221,7 @@ public class SshFileController extends BaseServerController {
Sftp sftp = null;
try {
Session session = SshService.getSessionByModel(sshModel);
sftp = new Sftp(session, sshModel.getCharsetT(), sshModel.timeout());
sftp = new Sftp(session, sshModel.charset(), sshModel.timeout());
String normalize = FileUtil.normalize(path + StrUtil.SLASH + name);
sftp.upload(normalize, file);
} finally {
@ -367,7 +367,7 @@ public class SshFileController extends BaseServerController {
//
String normalize = FileUtil.normalize(path + StrUtil.SLASH + name);
session = SshService.getSessionByModel(sshModel);
sftp = new Sftp(session, sshModel.getCharsetT(), sshModel.timeout());
sftp = new Sftp(session, sshModel.charset(), sshModel.timeout());
// 尝试删除
boolean dirOrFile = this.tryDelDirOrFile(sftp, normalize);
if (dirOrFile) {
@ -513,7 +513,7 @@ public class SshFileController extends BaseServerController {
// 验证合法性防止越权
FileUtil.file(path, name);
String remotePath = FileUtil.normalize(path + StrUtil.SLASH + name);
try (Sftp sftp = new Sftp(session, sshModel.getCharsetT(), sshModel.timeout())) {
try (Sftp sftp = new Sftp(session, sshModel.charset(), sshModel.timeout())) {
if (sftp.exist(remotePath)) {
return JsonMessage.getString(400, "文件夹或者文件已存在");
}

View File

@ -135,14 +135,8 @@ public class SshModel extends BaseWorkspaceModel {
return (int) TimeUnit.SECONDS.toMillis(Math.max(1, this.timeout));
}
public Charset getCharsetT() {
Charset charset;
try {
charset = Charset.forName(this.getCharset());
} catch (Exception e) {
charset = CharsetUtil.CHARSET_UTF_8;
}
return charset;
public Charset charset() {
return CharsetUtil.parse(this.getCharset(), CharsetUtil.CHARSET_UTF_8);
}
public List<String> allowEditSuffix() {

View File

@ -257,7 +257,7 @@ public class CommandService extends BaseWorkspaceService<CommandModel> implement
//
workspaceEnvVarService.formatCommand(commandModel.getWorkspaceId(), commands);
//
Charset charset = sshModel.getCharsetT();
Charset charset = sshModel.charset();
sshService.exec(sshModel, (s, session) -> {
final ChannelExec channel = (ChannelExec) JschUtil.createChannel(session, ChannelType.EXEC);

View File

@ -202,7 +202,7 @@ public class SshService extends BaseWorkspaceService<SshModel> {
* @throws IOException io
*/
public String exec(SshModel sshModel, String... command) throws IOException {
Charset charset = sshModel.getCharsetT();
Charset charset = sshModel.charset();
return this.exec(sshModel, (s, session) -> {
// 执行命令
String exec, error;
@ -248,7 +248,7 @@ public class SshService extends BaseWorkspaceService<SshModel> {
for (String s : command) {
stringBuilder.append(s).append(StrUtil.LF);
}
Charset charset = sshModel.getCharsetT();
Charset charset = sshModel.charset();
FileUtil.writeString(stringBuilder.toString(), buildSsh, charset);
//
session = getSessionByModel(sshModel);
@ -353,7 +353,7 @@ public class SshService extends BaseWorkspaceService<SshModel> {
try {
session = getSessionByModel(sshModel);
channel = (ChannelSftp) JschUtil.openChannel(session, ChannelType.SFTP);
try (Sftp sftp = new Sftp(channel, sshModel.getCharsetT(), sshModel.timeout())) {
try (Sftp sftp = new Sftp(channel, sshModel.charset(), sshModel.timeout())) {
sftp.syncUpload(desc, remotePath);
}
//uploadDir(channel, remotePath, desc, sshModel.getCharsetT());

View File

@ -271,7 +271,7 @@ public class SshHandler extends BaseTerminalHandler {
int i;
//如果没有数据来线程会一直阻塞在这个地方等待数据
while ((i = inputStream.read(buffer)) != -1) {
sendBinary(session, new String(Arrays.copyOfRange(buffer, 0, i), sshItem.getCharsetT()));
sendBinary(session, new String(Arrays.copyOfRange(buffer, 0, i), sshItem.charset()));
}
} catch (Exception e) {
if (!this.openSession.isConnected()) {