Skip to content

Commit

Permalink
bugfix: fix file.conf read failed after package (#6899)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlgod authored Oct 8, 2024
1 parent f83b6ea commit b16f9cd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6881](https://github.com/apache/incubator-seata/pull/6881)]support grpc

### bugfix:

- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] fix file.conf read failed after package

### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] remove the branch registration operation of the XA read-only transaction
Expand Down Expand Up @@ -36,8 +36,8 @@ Thanks to these contributors for their code commits. Please report an unintended
- [dk2k](https://github.com/dk2k)
- [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
- [yougecn](https://github.com/yougecn)
- [xjlgod](https://github.com/xjlgod)
- [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)



Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
3 changes: 2 additions & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[[#6881](https://github.com/apache/incubator-seata/pull/6881)]全链路支持grpc

### bugfix:

- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] 修复file.conf打包后的读取

### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] 移除只读XA事务的分支注册操作
Expand Down Expand Up @@ -36,6 +36,7 @@
- [dk2k](https://github.com/dk2k)
- [MaoMaoandSnail](https://github.com/MaoMaoandSnail)
- [yougecn](https://github.com/yougecn)
- [xjlgod](https://github.com/xjlgod)
- [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@
*/
package org.apache.seata.config;

import org.apache.commons.lang.ObjectUtils;
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.config.ConfigFuture.ConfigOperation;
import org.apache.seata.config.file.FileConfig;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -32,15 +41,8 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.config.ConfigFuture.ConfigOperation;
import org.apache.seata.config.file.FileConfig;
import org.apache.commons.lang.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The type FileConfiguration.
*
Expand Down Expand Up @@ -134,7 +136,6 @@ private File getConfigFile(String name) {
boolean filePathCustom = name.startsWith(SYS_FILE_RESOURCE_PREFIX);
String filePath = filePathCustom ? name.substring(SYS_FILE_RESOURCE_PREFIX.length()) : name;
String decodedPath = URLDecoder.decode(filePath, StandardCharsets.UTF_8.name());

File targetFile = getFileFromFileSystem(decodedPath);
if (targetFile != null) {
return targetFile;
Expand All @@ -157,21 +158,18 @@ private File getFileFromFileSystem(String decodedPath) {

// run with jar file and not package third lib into jar file, this.getClass().getClassLoader() will be null
URL resourceUrl = this.getClass().getClassLoader().getResource("");
String[] tryPaths = null;
// try to get log dir (spring.config.additional-location) after package and run sh or bat in bin dir
String configLocation = System.getProperty("spring.config.additional-location");
List<String> tryPathsList = new ArrayList<>();
tryPathsList.add(decodedPath);
if (resourceUrl != null) {
tryPaths = new String[]{
// first: project dir
resourceUrl.getPath() + decodedPath,
// second: system path
decodedPath
};
} else {
tryPaths = new String[]{
decodedPath
};
tryPathsList.add(resourceUrl.getPath() + decodedPath);
}
if (configLocation != null) {
tryPathsList.add(configLocation + decodedPath);
}


String[] tryPaths = tryPathsList.toArray(new String[0]);
for (String tryPath : tryPaths) {
File targetFile = new File(tryPath);
if (targetFile.exists()) {
Expand Down

0 comments on commit b16f9cd

Please sign in to comment.