From 0a7181d0d1f040a3aff9f41256171a7b1b7ba3da Mon Sep 17 00:00:00 2001
From: Kai Reinhard <K.Reinhard@micromata.de>
Date: Sat, 08 Dec 2018 23:02:28 +0000
Subject: [PATCH] ...
---
borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java | 16 ++++++-
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java | 19 +++------
borgbutler-core/src/test/java/de/micromata/borgbutler/cache/CacheTest.java | 26 ++++++++++--
3 files changed, 41 insertions(+), 20 deletions(-)
diff --git a/borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java b/borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java
index a9a2893..41da950 100644
--- a/borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java
+++ b/borgbutler-core/src/main/java/de/micromata/borgbutler/BorgCommands.java
@@ -4,7 +4,6 @@
import de.micromata.borgbutler.config.Configuration;
import de.micromata.borgbutler.config.ConfigurationHandler;
import de.micromata.borgbutler.json.JsonUtils;
-import de.micromata.borgbutler.json.borg.Archive1;
import de.micromata.borgbutler.json.borg.ArchiveList;
import de.micromata.borgbutler.json.borg.RepoInfo;
import de.micromata.borgbutler.json.borg.RepoList;
@@ -45,8 +44,8 @@
* @param archive
* @return
*/
- public static ArchiveList info(BorgRepoConfig repoConfig, Archive1 archive) {
- String json = execute(repoConfig, "info", repoConfig.getRepo() + "::" + archive.getArchive(), "--json");
+ public static ArchiveList info(BorgRepoConfig repoConfig, String archive) {
+ String json = execute(repoConfig, "info", repoConfig.getRepo() + "::" + archive, "--json");
if (json == null) {
return null;
}
@@ -65,6 +64,17 @@
return repoList;
}
+ public static String list(BorgRepoConfig repoConfig, String archive) {
+ String json = execute(repoConfig, "list", repoConfig.getRepo() + "::" + archive,
+ "--json-lines");
+ if (json == null) {
+ return null;
+ }
+ // RepoList repoList = JsonUtils.fromJson(RepoList.class, json);
+ // repoList.setOriginalJson(json);
+ return json;
+ }
+
private static String execute(BorgRepoConfig repoConfig, String command, String repoOrArchive, String... args) {
CommandLine cmdLine = new CommandLine(ConfigurationHandler.getConfiguration().getBorgCommand());
cmdLine.addArgument(command);
diff --git a/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java b/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
index 8664817..f9e9789 100644
--- a/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
+++ b/borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -1,6 +1,7 @@
package de.micromata.borgbutler.cache;
import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,8 +14,11 @@
public static final String CACHE_DIR_NAME = ".borgbutler";
private static ButlerCache instance = new ButlerCache();
+ @Getter
private RepoInfoCache repoInfoCache;
+ @Getter
private RepoListCache repoListCache;
+ private ArchiveListCache archiveListCache;
private List<AbstractCache> caches;
@JsonIgnore
@@ -24,14 +28,6 @@
return instance;
}
- public static RepoInfoCache getRepoInfoCache() {
- return instance.repoInfoCache;
- }
-
- public static RepoListCache getRepoListCache() {
- return instance.repoListCache;
- }
-
public void read() {
for (AbstractCache cache : caches) {
cache.read();
@@ -67,10 +63,9 @@
log.info("Creating cache dir: " + cacheDir.getAbsolutePath());
cacheDir.mkdir();
}
- repoInfoCache = new RepoInfoCache(cacheDir);
- repoListCache = new RepoListCache(cacheDir);
caches = new ArrayList<>();
- caches.add(repoInfoCache);
- caches.add(repoListCache);
+ caches.add(repoInfoCache = new RepoInfoCache(cacheDir));
+ caches.add(repoListCache = new RepoListCache(cacheDir));
+ caches.add(archiveListCache = new ArchiveListCache(cacheDir));
}
}
diff --git a/borgbutler-core/src/test/java/de/micromata/borgbutler/cache/CacheTest.java b/borgbutler-core/src/test/java/de/micromata/borgbutler/cache/CacheTest.java
index 0b1bfef..7f68d7a 100644
--- a/borgbutler-core/src/test/java/de/micromata/borgbutler/cache/CacheTest.java
+++ b/borgbutler-core/src/test/java/de/micromata/borgbutler/cache/CacheTest.java
@@ -5,7 +5,6 @@
import de.micromata.borgbutler.config.Configuration;
import de.micromata.borgbutler.config.ConfigurationHandler;
import de.micromata.borgbutler.json.borg.Archive1;
-import de.micromata.borgbutler.json.borg.ArchiveList;
import de.micromata.borgbutler.json.borg.RepoInfo;
import de.micromata.borgbutler.json.borg.RepoList;
import org.apache.commons.collections4.CollectionUtils;
@@ -35,20 +34,30 @@
//butlerCache.removeAllCacheFiles();
butlerCache.read();
{
- RepoInfoCache repoInfoCache = ButlerCache.getRepoInfoCache();
+ RepoInfoCache repoInfoCache = ButlerCache.getInstance().getRepoInfoCache();
if (repoInfoCache.getElements().size() != config.getRepoConfigs().size()) {
refreshRepoInfoCache(config, repoInfoCache);
}
assertEquals(config.getRepoConfigs().size(), repoInfoCache.getElements().size());
}
{
- RepoListCache repoListCache = ButlerCache.getRepoListCache();
+ RepoListCache repoListCache = ButlerCache.getInstance().getRepoListCache();
if (repoListCache.getElements().size() != config.getRepoConfigs().size()) {
refreshRepoListCache(config, repoListCache);
}
assertEquals(config.getRepoConfigs().size(), repoListCache.getElements().size());
}
- {
+ List<BorgRepoConfig> repoConfigs = ConfigurationHandler.getConfiguration().getRepoConfigs();
+ Archive1 archive = null;
+ BorgRepoConfig repoConfig = null;
+ if (CollectionUtils.isNotEmpty(repoConfigs)) {
+ repoConfig = repoConfigs.get(0);
+ RepoList repoList = ButlerCache.getInstance().getRepoListCache().get(repoConfig.getRepo());
+ if (repoList != null && CollectionUtils.isNotEmpty(repoList.getArchives())) {
+ archive = repoList.getArchives().get(0);
+ }
+ }
+ {/*
List<BorgRepoConfig> repoConfigs = ConfigurationHandler.getConfiguration().getRepoConfigs();
if (CollectionUtils.isNotEmpty(repoConfigs)) {
BorgRepoConfig repoConfig = repoConfigs.get(0);
@@ -56,10 +65,17 @@
if (repoList != null && CollectionUtils.isNotEmpty(repoList.getArchives())) {
Archive1 archive = repoList.getArchives().get(0);
if (archive != null) {
- ArchiveList list = BorgCommands.info(repoConfig, archive);
+ ArchiveList list = ButlerCache.getArchiveListCache().get(archive.getArchive());
+ ArchiveList list = BorgCommands.info(repoConfig, archive.getArchive());
log.info(list.toString());
}
}
+ }*/
+ }
+ {
+ if (archive != null) {
+ String json = BorgCommands.list(repoConfig, archive.getArchive());
+ log.info(json);
}
}
butlerCache.save();
--
Gitblit v1.10.0