mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add messages to precondition checks
This commit is contained in:
parent
fd743d1bf3
commit
045eea8282
3 changed files with 29 additions and 8 deletions
|
@ -76,13 +76,13 @@ public class FSGitRepoStore implements RepoStore {
|
|||
String projectName,
|
||||
long[] sizePtr
|
||||
) throws IOException {
|
||||
Preconditions.checkArgument(Project.isValidProjectName(projectName));
|
||||
Project.checkValidProjectName(projectName);
|
||||
return Tar.bz2.zip(getDotGitForProject(projectName), sizePtr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(String projectName) throws IOException {
|
||||
Preconditions.checkArgument(Project.isValidProjectName(projectName));
|
||||
Project.checkValidProjectName(projectName);
|
||||
FileUtils.deleteDirectory(new File(rootDirectory, projectName));
|
||||
}
|
||||
|
||||
|
@ -91,13 +91,22 @@ public class FSGitRepoStore implements RepoStore {
|
|||
String projectName,
|
||||
InputStream dataStream
|
||||
) throws IOException {
|
||||
Preconditions.checkArgument(Project.isValidProjectName(projectName));
|
||||
Preconditions.checkState(getDirForProject(projectName).mkdirs());
|
||||
Preconditions.checkArgument(
|
||||
Project.isValidProjectName(projectName),
|
||||
"[%s] invalid project name: ",
|
||||
projectName
|
||||
);
|
||||
Preconditions.checkState(
|
||||
getDirForProject(projectName).mkdirs(),
|
||||
"[%s] directories for " +
|
||||
"evicted project already exist",
|
||||
projectName
|
||||
);
|
||||
Tar.bz2.unzip(dataStream, getDirForProject(projectName));
|
||||
}
|
||||
|
||||
private File getDirForProject(String projectName) {
|
||||
Preconditions.checkArgument(Project.isValidProjectName(projectName));
|
||||
Project.checkValidProjectName(projectName);
|
||||
return Paths.get(
|
||||
rootDirectory.getAbsolutePath()
|
||||
).resolve(
|
||||
|
@ -106,7 +115,7 @@ public class FSGitRepoStore implements RepoStore {
|
|||
}
|
||||
|
||||
private File getDotGitForProject(String projectName) {
|
||||
Preconditions.checkArgument(Project.isValidProjectName(projectName));
|
||||
Project.checkValidProjectName(projectName);
|
||||
return Paths.get(
|
||||
rootDirectory.getAbsolutePath()
|
||||
).resolve(
|
||||
|
@ -119,7 +128,12 @@ public class FSGitRepoStore implements RepoStore {
|
|||
private File initRootGitDirectory(String rootGitDirectoryPath) {
|
||||
File rootGitDirectory = new File(rootGitDirectoryPath);
|
||||
rootGitDirectory.mkdirs();
|
||||
Preconditions.checkArgument(rootGitDirectory.isDirectory());
|
||||
Preconditions.checkArgument(
|
||||
rootGitDirectory.isDirectory(),
|
||||
"given root git directory " +
|
||||
"is not a directory: %s",
|
||||
rootGitDirectory.getAbsolutePath()
|
||||
);
|
||||
return rootGitDirectory;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ public class SwapJobImpl implements SwapJob {
|
|||
*/
|
||||
@Override
|
||||
public void evict(String projName) throws IOException {
|
||||
Preconditions.checkNotNull(projName);
|
||||
Preconditions.checkNotNull(projName, "projName was null");
|
||||
Log.info("Evicting project: {}", projName);
|
||||
try (LockGuard __ = lock.lockGuard(projName)) {
|
||||
long[] sizePtr = new long[1];
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package uk.ac.ic.wlgitbridge.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* Created by winston on 23/08/2016.
|
||||
*/
|
||||
|
@ -10,4 +12,9 @@ public class Project {
|
|||
&& !projectName.startsWith(".");
|
||||
}
|
||||
|
||||
public static void checkValidProjectName(String projectName) {
|
||||
Preconditions.checkArgument(isValidProjectName(projectName),
|
||||
"[%s] invalid project name", projectName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue