[server][xary] -修改bug
This commit is contained in:
@@ -44,13 +44,39 @@ public class XrayConfigPersistor {
|
|||||||
new DefaultIndenter()
|
new DefaultIndenter()
|
||||||
.withLinefeed("\n")
|
.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);
|
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生成配置文件的持久化工作,沈成伟临时文件保存至当前目录中
|
* 执行Xray生成配置文件的持久化工作,沈成伟临时文件保存至当前目录中
|
||||||
*
|
*
|
||||||
* @param isOutBoundFree
|
|
||||||
* @param xrayConfig
|
* @param xrayConfig
|
||||||
* @param currentVersion
|
* @param currentVersion
|
||||||
* @param proxyNode
|
* @param proxyNode
|
||||||
@@ -172,7 +198,7 @@ public class XrayConfigPersistor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
FileUtils.cleanDirectory(
|
FileUtils.cleanDirectory(
|
||||||
new ClassPathResource(XrayResultPath).getFile()
|
XrayResultPath
|
||||||
);
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("清楚旧的目录失败! 请检查问题!");
|
log.error("清楚旧的目录失败! 请检查问题!");
|
||||||
@@ -190,23 +216,13 @@ public class XrayConfigPersistor {
|
|||||||
*/
|
*/
|
||||||
private File getResultFile(String fileName) {
|
private File getResultFile(String fileName) {
|
||||||
|
|
||||||
ClassPathResource classPathResource = new ClassPathResource(XrayResultPath);
|
// 打包之后 无法获取到包内的文件 https://blog.csdn.net/u013084266/article/details/112238267
|
||||||
|
|
||||||
|
// 需要创建一个文件
|
||||||
try {
|
return new File(
|
||||||
// 需要创建一个文件
|
XrayResultPath,
|
||||||
return new File(
|
fileName
|
||||||
classPathResource.getFile(),
|
);
|
||||||
fileName
|
|
||||||
);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(
|
|
||||||
"获取文件失败请检查! fileName is => {}",
|
|
||||||
fileName
|
|
||||||
);
|
|
||||||
throw new MyRuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user