Skip to content
Permalink
Browse files
Avoid resetting an existing storage file
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Oct 30, 2020
1 parent 352c276 commit e261f30c092d50579050cde360784332345984b8
Showing 2 changed files with 14 additions and 1 deletion.
@@ -25,6 +25,7 @@
requires org.openjdk.skara.host;
requires org.openjdk.skara.forge;
requires org.openjdk.skara.vcs;
requires java.logging;

exports org.openjdk.skara.storage;
}
@@ -28,6 +28,7 @@
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.logging.Logger;

class HostedRepositoryStorage<T> implements Storage<T> {
private final HostedRepository hostedRepository;
@@ -42,6 +43,7 @@

private RepositoryStorage<T> repositoryStorage;
private Set<T> current;
private final static Logger log = Logger.getLogger("org.openjdk.skara.storage");

HostedRepositoryStorage(HostedRepository repository, Path localStorage, String ref, String fileName, String authorName, String authorEmail, String message, StorageSerializer<T> serializer, StorageDeserializer<T> deserializer) {
this.hostedRepository = repository;
@@ -66,9 +68,19 @@ private static Repository tryMaterialize(HostedRepository repository, Path local
try {
try {
return Repository.materialize(localStorage, repository.url(), "+" + ref + ":storage");
} catch (IOException ignored) {
} catch (IOException e2) {
// The remote ref may not yet exist
Repository localRepository = Repository.init(localStorage, repository.repositoryType());
if (!localRepository.isEmpty()) {
// If the materialization failed but the local repository already contains data, do not initialize the ref
log.warning("Materialization into existing local repository failed");
log.throwing("HostedRepositoryStorage", "tryMaterialize", e2);
lastException = e2;
retryCount++;
continue;
}

log.info("Creating initial storage for: " + ref);
var file = localStorage.resolve(fileName);
Files.createDirectories(file.getParent());
var storage = Files.writeString(localStorage.resolve(fileName), "");

1 comment on commit e261f30

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on e261f30 Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.