mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #74 from overleaf/ew-add-file-number-limit
add file limit error
This commit is contained in:
commit
3c28b30680
6 changed files with 75 additions and 22 deletions
|
@ -97,23 +97,20 @@ You have to restart the server for configuration changes to take effect.
|
||||||
|
|
||||||
## Creating OAuth app
|
## Creating OAuth app
|
||||||
|
|
||||||
In dev-env, run `bin/run rails_v1 rake db:seed`, or, if using this solo, run the following in the v1
|
In dev-env, run the following command in mongo to create the oauth application
|
||||||
database:
|
for git-bridge.
|
||||||
|
|
||||||
```sql
|
```
|
||||||
INSERT INTO public.oauth_applications (
|
db.oauthApplications.insert({
|
||||||
"name", uid, secret, redirect_uri, scopes, skip_authorization,
|
"clientSecret" : "e6b2e9eee7ae2bb653823250bb69594a91db0547fe3790a7135acb497108e62d",
|
||||||
created_at, updated_at, partner, confidential
|
"grants" : [
|
||||||
) VALUES (
|
"password"
|
||||||
'gitbridge',
|
],
|
||||||
'264c723c925c13590880751f861f13084934030c13b4452901e73bdfab226edc',
|
"id" : "264c723c925c13590880751f861f13084934030c13b4452901e73bdfab226edc",
|
||||||
'e6b2e9eee7ae2bb653823250bb69594a91db0547fe3790a7135acb497108e62d',
|
"name" : "Overleaf Git Bridge",
|
||||||
'http://www.overleaf.test:5000/no-callback-required',
|
"redirectUris" : [],
|
||||||
'git_bridge',
|
"scopes" : [
|
||||||
true,
|
"git_bridge"
|
||||||
now(),
|
]
|
||||||
now(),
|
})
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"oauth2Server": "https://localhost"
|
"oauth2Server": "https://localhost"
|
||||||
},
|
},
|
||||||
"repoStore": {
|
"repoStore": {
|
||||||
|
"maxFileNum": 2000,
|
||||||
"maxFileSize": 52428800
|
"maxFileSize": 52428800
|
||||||
},
|
},
|
||||||
"swapStore": {
|
"swapStore": {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"oauth2Server": "http://v2.overleaf.test:4000"
|
"oauth2Server": "http://v2.overleaf.test:4000"
|
||||||
},
|
},
|
||||||
"repoStore": {
|
"repoStore": {
|
||||||
|
"maxFileNum": 2000,
|
||||||
"maxFileSize": 52428800
|
"maxFileSize": 52428800
|
||||||
},
|
},
|
||||||
"swapStore": {
|
"swapStore": {
|
||||||
|
|
|
@ -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.data.model.Snapshot;
|
||||||
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
|
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
|
||||||
import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
|
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.WLReceivePackFactory;
|
||||||
import uk.ac.ic.wlgitbridge.git.handler.WLRepositoryResolver;
|
import uk.ac.ic.wlgitbridge.git.handler.WLRepositoryResolver;
|
||||||
import uk.ac.ic.wlgitbridge.git.handler.WLUploadPackFactory;
|
import uk.ac.ic.wlgitbridge.git.handler.WLUploadPackFactory;
|
||||||
|
@ -426,6 +427,7 @@ public class Bridge {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws MissingRepositoryException
|
* @throws MissingRepositoryException
|
||||||
* @throws ForbiddenException
|
* @throws ForbiddenException
|
||||||
|
* @throws GitUserException
|
||||||
*/
|
*/
|
||||||
public void push(
|
public void push(
|
||||||
Optional<Credential> oauth2,
|
Optional<Credential> oauth2,
|
||||||
|
@ -433,7 +435,7 @@ public class Bridge {
|
||||||
RawDirectory directoryContents,
|
RawDirectory directoryContents,
|
||||||
RawDirectory oldDirectoryContents,
|
RawDirectory oldDirectoryContents,
|
||||||
String hostname
|
String hostname
|
||||||
) throws SnapshotPostException, IOException, MissingRepositoryException, ForbiddenException {
|
) throws SnapshotPostException, IOException, MissingRepositoryException, ForbiddenException, GitUserException {
|
||||||
try (LockGuard __ = lock.lockGuard(projectName)) {
|
try (LockGuard __ = lock.lockGuard(projectName)) {
|
||||||
pushCritical(
|
pushCritical(
|
||||||
oauth2,
|
oauth2,
|
||||||
|
@ -507,13 +509,23 @@ public class Bridge {
|
||||||
* @throws MissingRepositoryException
|
* @throws MissingRepositoryException
|
||||||
* @throws ForbiddenException
|
* @throws ForbiddenException
|
||||||
* @throws SnapshotPostException
|
* @throws SnapshotPostException
|
||||||
|
* @throws GitUserException
|
||||||
*/
|
*/
|
||||||
private void pushCritical(
|
private void pushCritical(
|
||||||
Optional<Credential> oauth2,
|
Optional<Credential> oauth2,
|
||||||
String projectName,
|
String projectName,
|
||||||
RawDirectory directoryContents,
|
RawDirectory directoryContents,
|
||||||
RawDirectory oldDirectoryContents
|
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);
|
Log.info("[{}] Pushing", projectName);
|
||||||
String postbackKey = postbackManager.makeKeyForProject(projectName);
|
String postbackKey = postbackManager.makeKeyForProject(projectName);
|
||||||
Log.info(
|
Log.info(
|
||||||
|
@ -529,7 +541,7 @@ public class Bridge {
|
||||||
);
|
);
|
||||||
) {
|
) {
|
||||||
Log.info(
|
Log.info(
|
||||||
"[{}] Candindate snapshot created: {}",
|
"[{}] Candidate snapshot created: {}",
|
||||||
projectName,
|
projectName,
|
||||||
candidate
|
candidate
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,11 +11,19 @@ public class RepoStoreConfig {
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Long maxFileSize;
|
private final Long maxFileSize;
|
||||||
|
|
||||||
public RepoStoreConfig(Long maxFileSize) {
|
@Nullable
|
||||||
|
private final Long maxFileNum;
|
||||||
|
|
||||||
|
public RepoStoreConfig(Long maxFileSize, Long maxFileNum) {
|
||||||
this.maxFileSize = maxFileSize;
|
this.maxFileSize = maxFileSize;
|
||||||
|
this.maxFileNum = maxFileNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Long> getMaxFileSize() {
|
public Optional<Long> getMaxFileSize() {
|
||||||
return Optional.ofNullable(maxFileSize);
|
return Optional.ofNullable(maxFileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Long> getMaxFileNum() {
|
||||||
|
return Optional.ofNullable(maxFileNum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue