mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-14 09:04:38 +00:00
Use df equivalent as default for calculating used space
This commit is contained in:
parent
9a0f18e516
commit
fe058e8695
3 changed files with 35 additions and 16 deletions
services/git-bridge/src
main/java/uk/ac/ic/wlgitbridge/bridge/repo
test/java/uk/ac/ic/wlgitbridge/bridge
|
@ -12,6 +12,7 @@ import java.nio.file.Paths;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static uk.ac.ic.wlgitbridge.util.Util.deleteInDirectoryApartFrom;
|
||||
|
||||
|
@ -22,10 +23,16 @@ public class FSGitRepoStore implements RepoStore {
|
|||
|
||||
private final String repoStorePath;
|
||||
private final File rootDirectory;
|
||||
private final Function<File, Long> fsSizer;
|
||||
|
||||
public FSGitRepoStore(String repoStorePath) {
|
||||
this(repoStorePath, d -> d.getTotalSpace() - d.getFreeSpace());
|
||||
}
|
||||
|
||||
public FSGitRepoStore(String repoStorePath, Function<File, Long> fsSizer) {
|
||||
this.repoStorePath = repoStorePath;
|
||||
rootDirectory = initRootGitDirectory(repoStorePath);
|
||||
this.fsSizer = fsSizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,7 +61,7 @@ public class FSGitRepoStore implements RepoStore {
|
|||
|
||||
@Override
|
||||
public long totalSize() {
|
||||
return FileUtils.sizeOfDirectory(rootDirectory);
|
||||
return fsSizer.apply(rootDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
package uk.ac.ic.wlgitbridge.bridge.repo;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import uk.ac.ic.wlgitbridge.util.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by winston on 23/08/2016.
|
||||
|
@ -52,16 +49,29 @@ public class FSGitRepoStoreTest {
|
|||
public void testPurgeNonexistentProjects() {
|
||||
File toDelete = new File(repoStore.getRootDirectory(), "idontexist");
|
||||
File wlgb = new File(repoStore.getRootDirectory(), ".wlgb");
|
||||
Assert.assertTrue(toDelete.exists());
|
||||
Assert.assertTrue(wlgb.exists());
|
||||
assertTrue(toDelete.exists());
|
||||
assertTrue(wlgb.exists());
|
||||
repoStore.purgeNonexistentProjects(Arrays.asList("proj1", "proj2"));
|
||||
Assert.assertFalse(toDelete.exists());
|
||||
Assert.assertTrue(wlgb.exists());
|
||||
assertFalse(toDelete.exists());
|
||||
assertTrue(wlgb.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTotalSize() {
|
||||
assertEquals(31860, repoStore.totalSize());
|
||||
public void totalSizeShouldChangeWhenFilesAreCreatedAndDeleted()
|
||||
throws IOException {
|
||||
long old = repoStore.totalSize();
|
||||
repoStore.remove("proj1");
|
||||
long new_ = repoStore.totalSize();
|
||||
assertTrue(new_ < old);
|
||||
try (
|
||||
OutputStream out = new FileOutputStream(
|
||||
new File(repoStore.getRootDirectory(), "__temp.txt")
|
||||
)
|
||||
) {
|
||||
out.write(new byte[1 * 1024 * 1024]);
|
||||
}
|
||||
long new__ = repoStore.totalSize();
|
||||
assertTrue(new__ > new_);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -69,10 +79,10 @@ public class FSGitRepoStoreTest {
|
|||
long beforeSize = repoStore.totalSize();
|
||||
InputStream zipped = repoStore.bzip2Project("proj1");
|
||||
repoStore.remove("proj1");
|
||||
Assert.assertTrue(beforeSize > repoStore.totalSize());
|
||||
assertTrue(beforeSize > repoStore.totalSize());
|
||||
repoStore.unbzip2Project("proj1", zipped);
|
||||
Assert.assertEquals(beforeSize, repoStore.totalSize());
|
||||
Assert.assertTrue(
|
||||
assertEquals(beforeSize, repoStore.totalSize());
|
||||
assertTrue(
|
||||
Files.contentsAreEqual(
|
||||
original,
|
||||
repoStore.getRootDirectory()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package uk.ac.ic.wlgitbridge.bridge.swap.job;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
@ -43,7 +44,8 @@ public class SwapJobImplTest {
|
|||
FSGitRepoStoreTest.makeTempRepoDir(
|
||||
tmpFolder,
|
||||
"repostore"
|
||||
).getAbsolutePath()
|
||||
).getAbsolutePath(),
|
||||
FileUtils::sizeOfDirectory
|
||||
);
|
||||
dbStore = new SqliteDBStore(tmpFolder.newFile());
|
||||
dbStore.setLatestVersionForProject("proj1", 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue