[server][xary] -修改bug

This commit is contained in:
zeaslity
2023-03-02 14:36:14 +08:00
parent 8ca593862e
commit 790b0fbe8a

View File

@@ -44,13 +44,39 @@ public class XrayConfigPersistor {
new DefaultIndenter()
.withLinefeed("\n")
));
private static final String XrayResultPath = "xrayResult/";
private static final String XrayResultPathPrefix = "xrayResult/";
/**
* 存储生成的Xray Config的临时文件目录
*/
private static File XrayResultPath;
public static AtomicInteger cleanVersion = new AtomicInteger(0);
static {
ClassPathResource resource = new ClassPathResource(XrayResultPathPrefix);
if (resource == null) {
// SpringBoot 打了Jar包的形式
File file = new File("/octopus-server/xray");
if (!file.exists()) {
file.mkdir();
}
XrayResultPath = file;
} else {
// 本地开发的模式
try {
XrayResultPath = resource.getFile();
} catch (IOException e) {
log.error("获取XrayConfig的临时文件目录失败");
throw new MyRuntimeException(e);
}
}
}
/**
* 执行Xray生成配置文件的持久化工作,沈成伟临时文件保存至当前目录中
*
* @param isOutBoundFree
* @param xrayConfig
* @param currentVersion
* @param proxyNode
@@ -172,7 +198,7 @@ public class XrayConfigPersistor {
try {
FileUtils.cleanDirectory(
new ClassPathResource(XrayResultPath).getFile()
XrayResultPath
);
} catch (IOException e) {
log.error("清楚旧的目录失败! 请检查问题!");
@@ -190,23 +216,13 @@ public class XrayConfigPersistor {
*/
private File getResultFile(String fileName) {
ClassPathResource classPathResource = new ClassPathResource(XrayResultPath);
// 打包之后 无法获取到包内的文件 https://blog.csdn.net/u013084266/article/details/112238267
try {
// 需要创建一个文件
return new File(
classPathResource.getFile(),
fileName
);
} catch (IOException e) {
log.error(
"获取文件失败请检查! fileName is => {}",
fileName
);
throw new MyRuntimeException(e);
}
// 需要创建一个文件
return new File(
XrayResultPath,
fileName
);
}