Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix file.conf read failed after package #6899

Merged
merged 7 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading