Skip to content

Commit

Permalink
Avoid storing empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Westberg committed Oct 20, 2020
1 parent 8f29ac9 commit 7259825
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -25,6 +25,7 @@
import org.openjdk.skara.vcs.Repository;

import java.io.*;
import java.nio.file.Files;
import java.util.*;

class RepositoryStorage<T> implements Storage<T> {
Expand Down Expand Up @@ -74,8 +75,13 @@ public void put(Collection<T> items) {
}
current = updated;
try {
repository.add(repository.root().resolve(fileName));
var filePath = repository.root().resolve(fileName);
repository.add(filePath);
repository.commit(message, authorName, authorEmail);

if (Files.size(filePath) == 0) {
throw new IllegalStateException("Storage file is empty: " + filePath);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit 7259825

Please sign in to comment.