[fix](repository) the exist repo_file must contails same name with new repo (#27668)

The user manually adjusted the 'name' field in the __repo_info file under the repo file on S3, but did not modify the folder name. This led to an issue when the user created a repo with the same name as the folder in a certain cluster. The system parsed the 'name' field in the existing __repo_info and used an incorrect name, causing the subsequent repo to be unusable. A judgment has been added here: the 'name' field in the __repo_info must be the same as the new repo's name, otherwise, an error will be reported.
This commit is contained in:
xueweizhang
2023-12-09 01:46:54 +08:00
committed by GitHub
parent 07336980f9
commit c6f8b1b2ee

View File

@ -262,6 +262,11 @@ public class Repository implements Writable {
byte[] bytes = Files.readAllBytes(Paths.get(localFilePath));
String json = new String(bytes, StandardCharsets.UTF_8);
JSONObject root = (JSONObject) JSONValue.parse(json);
if (name.compareTo((String) root.get("name")) != 0) {
return new Status(ErrCode.COMMON_ERROR,
"Invalid repository __repo_info, expected repo '" + name + "', but get name '"
+ (String) root.get("name") + "' from " + repoInfoFilePath);
}
name = (String) root.get("name");
createTime = TimeUtils.timeStringToLong((String) root.get("create_time"));
if (createTime == -1) {