add file limit error

This commit is contained in:
Ersun Warncke
2019-11-12 11:16:54 -04:00
parent 132e8f308d
commit 5188e7c06a
6 changed files with 75 additions and 22 deletions

View File

@@ -28,6 +28,7 @@ import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.model.Snapshot;
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
import uk.ac.ic.wlgitbridge.git.exception.FileLimitExceededException;
import uk.ac.ic.wlgitbridge.git.handler.WLReceivePackFactory;
import uk.ac.ic.wlgitbridge.git.handler.WLRepositoryResolver;
import uk.ac.ic.wlgitbridge.git.handler.WLUploadPackFactory;
@@ -426,6 +427,7 @@ public class Bridge {
* @throws IOException
* @throws MissingRepositoryException
* @throws ForbiddenException
* @throws GitUserException
*/
public void push(
Optional<Credential> oauth2,
@@ -433,7 +435,7 @@ public class Bridge {
RawDirectory directoryContents,
RawDirectory oldDirectoryContents,
String hostname
) throws SnapshotPostException, IOException, MissingRepositoryException, ForbiddenException {
) throws SnapshotPostException, IOException, MissingRepositoryException, ForbiddenException, GitUserException {
try (LockGuard __ = lock.lockGuard(projectName)) {
pushCritical(
oauth2,
@@ -507,13 +509,23 @@ public class Bridge {
* @throws MissingRepositoryException
* @throws ForbiddenException
* @throws SnapshotPostException
* @throws GitUserException
*/
private void pushCritical(
Optional<Credential> oauth2,
String projectName,
RawDirectory directoryContents,
RawDirectory oldDirectoryContents
) throws IOException, MissingRepositoryException, ForbiddenException, SnapshotPostException {
) throws IOException, MissingRepositoryException, ForbiddenException, SnapshotPostException, GitUserException {
Optional<Long> maxFileNum = config
.getRepoStore()
.flatMap(RepoStoreConfig::getMaxFileNum);
if (maxFileNum.isPresent()) {
long maxFileNum_ = maxFileNum.get();
if (directoryContents.getFileTable().size() > maxFileNum_) {
throw new FileLimitExceededException(directoryContents.getFileTable().size(), maxFileNum_);
}
}
Log.info("[{}] Pushing", projectName);
String postbackKey = postbackManager.makeKeyForProject(projectName);
Log.info(
@@ -529,7 +541,7 @@ public class Bridge {
);
) {
Log.info(
"[{}] Candindate snapshot created: {}",
"[{}] Candidate snapshot created: {}",
projectName,
candidate
);

View File

@@ -11,11 +11,19 @@ public class RepoStoreConfig {
@Nullable
private final Long maxFileSize;
public RepoStoreConfig(Long maxFileSize) {
@Nullable
private final Long maxFileNum;
public RepoStoreConfig(Long maxFileSize, Long maxFileNum) {
this.maxFileSize = maxFileSize;
this.maxFileNum = maxFileNum;
}
public Optional<Long> getMaxFileSize() {
return Optional.ofNullable(maxFileSize);
}
public Optional<Long> getMaxFileNum() {
return Optional.ofNullable(maxFileNum);
}
}

View File

@@ -0,0 +1,34 @@
package uk.ac.ic.wlgitbridge.git.exception;
import uk.ac.ic.wlgitbridge.util.Util;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class FileLimitExceededException extends GitUserException {
private final long numFiles;
private final long maxFiles;
public FileLimitExceededException(long numFiles, long maxFiles) {
this.numFiles = numFiles;
this.maxFiles = maxFiles;
}
@Override
public String getMessage() {
return "too many files";
}
@Override
public List<String> getDescriptionLines() {
return Arrays.asList(
"repository contains " +
numFiles + " files, which exceeds the limit of " +
maxFiles + " files"
);
}
}