This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 612a81b Refactor delete local dist meta data file (#11582)
612a81b is described below
commit 612a81b35d220a0efa3d0652ba1d82419fe963ee
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Jul 30 16:54:58 2021 +0800
Refactor delete local dist meta data file (#11582)
---
.../local/LocalDistMetaDataDeleteVisitor.java | 53 ++++++++++++++++++++++
.../local/LocalDistMetaDataPersistRepository.java | 8 ++--
2 files changed, 57 insertions(+), 4 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataDeleteVisitor.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataDeleteVisitor.java
new file mode 100644
index 0000000..ae2bd37
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataDeleteVisitor.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.config.persist.repository.local;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.FileVisitor;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+
+/**
+ * Local dist meta data delete visitor.
+ */
+public final class LocalDistMetaDataDeleteVisitor implements FileVisitor {
+
+ @Override
+ public FileVisitResult preVisitDirectory(final Object dir, final
BasicFileAttributes attrs) {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(final Object file, final
BasicFileAttributes attrs) throws IOException {
+ Files.deleteIfExists((Path) file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(final Object file, final
IOException exc) {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(final Object dir, final
IOException exc) throws IOException {
+ Files.deleteIfExists((Path) dir);
+ return FileVisitResult.CONTINUE;
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataPersistRepository.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataPersistRepository.java
index f1e16d6..ba484e6 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataPersistRepository.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/local/LocalDistMetaDataPersistRepository.java
@@ -76,10 +76,10 @@ public final class LocalDistMetaDataPersistRepository
implements DistMetaDataPer
@Override
public void delete(final String key) {
- boolean isDeleted = new File(path, key).delete();
- if (!isDeleted) {
- //TODO process exception
- log.error("Delete local dist meta data key: {} failed", key);
+ try {
+ Files.walkFileTree(Paths.get(path, key), new
LocalDistMetaDataDeleteVisitor());
+ } catch (final IOException ex) {
+ log.error("Delete local dist meta data key: {} failed", key, ex);
}
}