You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2023/10/30 20:13:06 UTC
(jackrabbit-filevault) branch master updated: JCRVLT-727: Prune unused synced directories
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
The following commit(s) were added to refs/heads/master by this push:
new 30ca7282 JCRVLT-727: Prune unused synced directories
30ca7282 is described below
commit 30ca7282256e375781cd3955ac894442d8dd780a
Author: jochen-a-klein <13...@users.noreply.github.com>
AuthorDate: Mon Oct 30 21:13:01 2023 +0100
JCRVLT-727: Prune unused synced directories
Improve tracking
Co-authored-by: Konrad Windszus <kw...@apache.org>
---
.../vault/sync/impl/VaultSyncServiceImplIT.java | 2 +-
.../jackrabbit/vault/fs/io/PlatformExporter.java | 50 ++++++++++++++++------
2 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/sync/impl/VaultSyncServiceImplIT.java b/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/sync/impl/VaultSyncServiceImplIT.java
index 0a65a226..b993db23 100644
--- a/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/sync/impl/VaultSyncServiceImplIT.java
+++ b/vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/sync/impl/VaultSyncServiceImplIT.java
@@ -61,7 +61,7 @@ public class VaultSyncServiceImplIT extends IntegrationTestBase {
Path filterFile = syncRootDirectory1.resolve(".vlt-sync-filter.xml");
assertTrue(Files.exists(filterFile));
// check for file not yet being there in repo
- assertNodeMissing("/testroot/testfile1.txt");
+ assertNodeMissing("/testroot/testfile.txt");
// modify filter
try (InputStream input = this.getClass().getResourceAsStream("filter.xml")) {
Files.copy(input, filterFile, StandardCopyOption.REPLACE_EXISTING);
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java
index b870af3f..2a9e45aa 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/PlatformExporter.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
+import java.util.Comparator;
import javax.jcr.RepositoryException;
@@ -84,13 +85,30 @@ public class PlatformExporter extends AbstractExporter {
*/
public void close() throws IOException {
if (pruneMissing) {
- for (ExportInfo.Entry e: exportInfo.getEntries().values()) {
- if (e.type == ExportInfo.Type.DELETE) {
- File file = new File(e.path);
- FileUtils.deleteQuietly(file);
- track("D", PathUtil.getRelativePath(localParent.getAbsolutePath(), e.path));
- }
- }
+ // first, remove all empty directories
+ exportInfo.getEntries().values().stream()
+ .filter(e -> e.type == ExportInfo.Type.RMDIR)
+ .map(e -> e.path)
+ .sorted(Comparator.comparingInt(String::length))
+ .forEachOrdered(path -> {
+ File file = new File(path);
+ if (file.exists()) {
+ FileUtils.deleteQuietly(file);
+ track("D", PathUtil.getRelativePath(localParent.getAbsolutePath(), path));
+ }
+ });
+
+ // then remove files, which are still there
+ exportInfo.getEntries().values().stream()
+ .filter(e -> e.type == ExportInfo.Type.DELETE)
+ .map(e -> e.path)
+ .forEach(path -> {
+ File file = new File(path);
+ if (file.exists()) {
+ FileUtils.deleteQuietly(file);
+ track("D", PathUtil.getRelativePath(localParent.getAbsolutePath(), path));
+ }
+ });
}
}
@@ -117,12 +135,13 @@ public class PlatformExporter extends AbstractExporter {
throws RepositoryException, IOException {
File dir = new File(localParent, getPlatformFilePath(file, relPath));
mkdirs(dir);
- track("A", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), dir.getAbsolutePath()));
+ exportInfo.update(ExportInfo.Type.MKDIR, dir.getPath());
}
public void createDirectory(String relPath) throws IOException {
File dir = new File(localParent, relPath);
mkdirs(dir);
+ exportInfo.update(ExportInfo.Type.MKDIR, dir.getPath());
}
public void writeFile(VaultFile file, String relPath)
@@ -133,10 +152,11 @@ public class PlatformExporter extends AbstractExporter {
}
if (local.exists()) {
exportInfo.update(ExportInfo.Type.UPDATE, local.getPath());
+ track("U", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), local.getAbsolutePath()));
} else {
exportInfo.update(ExportInfo.Type.ADD, local.getPath());
+ track("A", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), local.getAbsolutePath()));
}
- track("A", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), local.getAbsolutePath()));
Artifact a = file.getArtifact();
switch (a.getPreferredAccess()) {
case NONE:
@@ -150,7 +170,7 @@ public class PlatformExporter extends AbstractExporter {
case STREAM:
try (InputStream in = a.getInputStream();
- OutputStream out = new FileOutputStream(local)) {
+ OutputStream out = new FileOutputStream(local)) {
IOUtils.copy(in, out);
}
break;
@@ -168,8 +188,10 @@ public class PlatformExporter extends AbstractExporter {
}
if (local.exists()) {
exportInfo.update(ExportInfo.Type.UPDATE, local.getPath());
+ track("U", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), local.getAbsolutePath()));
} else {
exportInfo.update(ExportInfo.Type.ADD, local.getPath());
+ track("A", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), local.getAbsolutePath()));
}
Files.copy(in, local.toPath(), StandardCopyOption.REPLACE_EXISTING);
} finally {
@@ -178,8 +200,10 @@ public class PlatformExporter extends AbstractExporter {
}
private void mkdirs(File dir) throws IOException {
- dir.mkdirs();
- exportInfo.update(ExportInfo.Type.MKDIR, dir.getPath());
+ if (!dir.exists()) {
+ dir.mkdirs();
+ track("A", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), dir.getAbsolutePath()));
+ }
}
-}
\ No newline at end of file
+}