Example usage for org.eclipse.jgit.lfs.server LfsObject getSize

List of usage examples for org.eclipse.jgit.lfs.server LfsObject getSize

Introduction

In this page you can find the example usage for org.eclipse.jgit.lfs.server LfsObject getSize.

Prototype

public long getSize() 

Source Link

Document

Get the size of this object.

Usage

From source file:com.googlesource.gerrit.plugins.lfs.LfsApiServlet.java

License:Apache License

@Override
protected LargeFileRepository getLargeFileRepository(LfsRequest request, String path, String auth)
        throws LfsException {
    String pathInfo = path.startsWith("/") ? path : "/" + path;
    Matcher matcher = URL_PATTERN.matcher(pathInfo);
    if (!matcher.matches()) {
        throw new LfsException("no repository at " + pathInfo);
    }//from  www .  ja  v  a  2 s  . c o m
    String projName = matcher.group(1);
    Project.NameKey project = Project.NameKey.parse(ProjectUtil.stripGitSuffix(projName));
    ProjectState state = projectCache.get(project);
    if (state == null || state.getProject().getState() == HIDDEN) {
        throw new LfsRepositoryNotFound(project.get());
    }
    authorizeUser(userProvider.getUser(auth, projName, request.getOperation()), state, request);

    if (request.isUpload() && state.getProject().getState() == READ_ONLY) {
        throw new LfsRepositoryReadOnly(project.get());
    }

    LfsProjectConfigSection config = lfsConfigFactory.getProjectsConfig().getForProject(project);
    // Only accept requests for projects where LFS is enabled.
    // No config means we default to "not enabled".
    if (config != null && config.isEnabled()) {
        // For uploads, check object sizes against limit if configured
        if (request.isUpload()) {
            if (config.isReadOnly()) {
                throw new LfsRepositoryReadOnly(project.get());
            }

            long maxObjectSize = config.getMaxObjectSize();
            if (maxObjectSize > 0) {
                for (LfsObject object : request.getObjects()) {
                    if (object.getSize() > maxObjectSize) {
                        throw new LfsValidationError(
                                String.format("size of object %s (%d bytes) exceeds limit (%d bytes)",
                                        object.getOid(), object.getSize(), maxObjectSize));
                    }
                }
            }
        }

        return repoResolver.get(project, config.getBackend());
    }

    throw new LfsUnavailable(project.get());
}