🐛 windows 移动文件失败.
This commit is contained in:
@@ -100,7 +100,7 @@ public abstract class AbstractTerminalHandler<T extends TerminalBasePayload> imp
|
|||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (ex instanceof InvalidArgumentException) {
|
if (ex instanceof InvalidArgumentException || ex instanceof IllegalArgumentException) {
|
||||||
return ex.getMessage();
|
return ex.getMessage();
|
||||||
}
|
}
|
||||||
return ErrorMessage.OPERATE_ERROR;
|
return ErrorMessage.OPERATE_ERROR;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.orion.visor.framework.common.constant.Const;
|
|||||||
import com.orion.visor.framework.common.utils.Valid;
|
import com.orion.visor.framework.common.utils.Valid;
|
||||||
import com.orion.visor.module.asset.handler.host.terminal.model.TerminalConfig;
|
import com.orion.visor.module.asset.handler.host.terminal.model.TerminalConfig;
|
||||||
import com.orion.visor.module.asset.handler.host.terminal.model.response.SftpFileVO;
|
import com.orion.visor.module.asset.handler.host.terminal.model.response.SftpFileVO;
|
||||||
|
import com.orion.visor.module.asset.utils.SftpUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.socket.WebSocketSession;
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
|
||||||
@@ -82,7 +83,10 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
|||||||
@Override
|
@Override
|
||||||
public void move(String source, String target) {
|
public void move(String source, String target) {
|
||||||
source = Valid.checkNormalize(source);
|
source = Valid.checkNormalize(source);
|
||||||
executor.move(source, target);
|
// 移动
|
||||||
|
SftpUtils.move(executor, source, target);
|
||||||
|
// FIXME kit
|
||||||
|
// executor.move(source, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class TransferUtils {
|
|||||||
public static String getErrorMessage(Exception ex) {
|
public static String getErrorMessage(Exception ex) {
|
||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
return null;
|
return null;
|
||||||
} else if (ex instanceof InvalidArgumentException) {
|
} else if (ex instanceof InvalidArgumentException || ex instanceof IllegalArgumentException) {
|
||||||
String message = ex.getMessage();
|
String message = ex.getMessage();
|
||||||
if (Strings.isBlank(message)) {
|
if (Strings.isBlank(message)) {
|
||||||
return ErrorMessage.OPERATE_ERROR;
|
return ErrorMessage.OPERATE_ERROR;
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
|||||||
.sourceId(request.getSourceId())
|
.sourceId(request.getSourceId())
|
||||||
.execSeq(request.getExecSeq())
|
.execSeq(request.getExecSeq())
|
||||||
.description(Strings.ifBlank(request.getDescription(), () -> {
|
.description(Strings.ifBlank(request.getDescription(), () -> {
|
||||||
if (command.length() < DESC_OMIT + 3) {
|
if (command.length() < DESC_OMIT + Const.OMIT.length()) {
|
||||||
return command;
|
return command;
|
||||||
} else {
|
} else {
|
||||||
return command.substring(0, DESC_OMIT) + Const.OMIT;
|
return command.substring(0, DESC_OMIT) + Const.OMIT;
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ public class ExecLogServiceImpl implements ExecLogService {
|
|||||||
log.error("ExecLogService.downloadLogFile error id: {}", id, e);
|
log.error("ExecLogService.downloadLogFile error id: {}", id, e);
|
||||||
Streams.close(in);
|
Streams.close(in);
|
||||||
String errorMessage = ErrorMessage.FILE_READ_ERROR_CLEAR;
|
String errorMessage = ErrorMessage.FILE_READ_ERROR_CLEAR;
|
||||||
if (e instanceof InvalidArgumentException) {
|
if (e instanceof InvalidArgumentException || e instanceof IllegalArgumentException) {
|
||||||
errorMessage = e.getMessage();
|
errorMessage = e.getMessage();
|
||||||
}
|
}
|
||||||
// 响应错误信息
|
// 响应错误信息
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.orion.visor.module.asset.utils;
|
package com.orion.visor.module.asset.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.jcraft.jsch.SftpException;
|
|
||||||
import com.orion.lang.utils.Booleans;
|
import com.orion.lang.utils.Booleans;
|
||||||
|
import com.orion.lang.utils.Exceptions;
|
||||||
import com.orion.lang.utils.Strings;
|
import com.orion.lang.utils.Strings;
|
||||||
import com.orion.lang.utils.io.Files1;
|
import com.orion.lang.utils.io.Files1;
|
||||||
import com.orion.net.host.sftp.SftpExecutor;
|
import com.orion.net.host.sftp.SftpExecutor;
|
||||||
@@ -41,13 +41,49 @@ public class SftpUtils {
|
|||||||
SftpFileBackupParams backupParams = new SftpFileBackupParams(file.getName(), System.currentTimeMillis());
|
SftpFileBackupParams backupParams = new SftpFileBackupParams(file.getName(), System.currentTimeMillis());
|
||||||
String target = Strings.format(config.getBackupFileName(), JSON.parseObject(JSON.toJSONString(backupParams)));
|
String target = Strings.format(config.getBackupFileName(), JSON.parseObject(JSON.toJSONString(backupParams)));
|
||||||
// 移动
|
// 移动
|
||||||
try {
|
|
||||||
executor.getChannel().rename(path, Files1.getPath(Files1.normalize(Files1.getPath(path + "/../" + target))));
|
|
||||||
} catch (SftpException ignored) {
|
|
||||||
}
|
|
||||||
// FIXME kit
|
// FIXME kit
|
||||||
|
move(executor, path, target);
|
||||||
// executor.move(path, target);
|
// executor.move(path, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动文件
|
||||||
|
* FIXME kit DELETE
|
||||||
|
*
|
||||||
|
* @param executor executor
|
||||||
|
* @param source source
|
||||||
|
* @param target target
|
||||||
|
*/
|
||||||
|
public static void move(SftpExecutor executor, String source, String target) {
|
||||||
|
try {
|
||||||
|
source = Files1.getPath(source);
|
||||||
|
target = Files1.getPath(target);
|
||||||
|
if (target.charAt(0) == '/') {
|
||||||
|
// 检查是否需要创建目标文件目录
|
||||||
|
if (!isSameParentPath(source, target)) {
|
||||||
|
executor.makeDirectories(Files1.getParentPath(target));
|
||||||
|
}
|
||||||
|
// 绝对路径
|
||||||
|
executor.getChannel().rename(source, Files1.getPath(Files1.normalize(target)));
|
||||||
|
} else {
|
||||||
|
// 相对路径
|
||||||
|
executor.getChannel().rename(source, Files1.getPath(Files1.normalize(Files1.getPath(source + "/../" + target))));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw Exceptions.sftp(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME kit DELETE
|
||||||
|
*
|
||||||
|
* @param source source
|
||||||
|
* @param target target
|
||||||
|
* @return res
|
||||||
|
*/
|
||||||
|
private static boolean isSameParentPath(String source, String target) {
|
||||||
|
return Files1.getParentPath(source).equals(Files1.getParentPath(target));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user