()
| 60 | private PackStatistics stats; |
| 61 | |
| 62 | @Override |
| 63 | protected void runImpl() throws IOException, Failure { |
| 64 | PermissionBackend.ForProject perm = |
| 65 | permissionBackend.user(user).project(projectState.getNameKey()); |
| 66 | try { |
| 67 | perm.check(ProjectPermission.RUN_UPLOAD_PACK); |
| 68 | } catch (AuthException e) { |
| 69 | throw new Failure(1, "fatal: upload-pack not permitted on this server", e); |
| 70 | } catch (PermissionBackendException e) { |
| 71 | throw new Failure(1, "fatal: unable to check permissions ", e); |
| 72 | } |
| 73 | |
| 74 | Repository permissionAwareRepo = PermissionAwareRepositoryManager.wrap(repo, perm); |
| 75 | UploadPack up = new UploadPack(permissionAwareRepo); |
| 76 | |
| 77 | up.setPackConfig(config.getPackConfig()); |
| 78 | up.setTimeout(config.getTimeout()); |
| 79 | up.setPostUploadHook(PostUploadHookChain.newChain(Lists.newArrayList(postUploadHooks))); |
| 80 | if (projectState.isAllUsers()) { |
| 81 | up.setAdvertiseRefsHook(usersSelfAdvertiseRefsHook); |
| 82 | } |
| 83 | if (extraParameters != null) { |
| 84 | up.setExtraParameters(ImmutableList.copyOf(extraParameters)); |
| 85 | } |
| 86 | |
| 87 | List<PreUploadHook> allPreUploadHooks = Lists.newArrayList(preUploadHooks); |
| 88 | allPreUploadHooks.add( |
| 89 | uploadValidatorsFactory.create( |
| 90 | project, permissionAwareRepo, session.getRemoteAddressAsString())); |
| 91 | up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks)); |
| 92 | for (UploadPackInitializer initializer : uploadPackInitializers) { |
| 93 | initializer.init(projectState.getNameKey(), up); |
| 94 | } |
| 95 | try (TraceContext traceContext = TraceContext.open(); |
| 96 | TracingHook tracingHook = new TracingHook((name, id) -> setTraceId(id))) { |
| 97 | RequestInfo requestInfo = |
| 98 | RequestInfo.builder(RequestInfo.RequestType.GIT_UPLOAD, getName(), user, traceContext) |
| 99 | .project(projectState.getNameKey()) |
| 100 | .build(); |
| 101 | Throwable error = null; |
| 102 | try { |
| 103 | requestListeners.runEach(l -> l.onRequest(requestInfo)); |
| 104 | up.setProtocolV2Hook(tracingHook); |
| 105 | up.upload(in, out, err); |
| 106 | session.setPeerAgent(up.getPeerUserAgent()); |
| 107 | stats = up.getStatistics(); |
| 108 | } catch (UploadValidationException e) { |
| 109 | error = e; |
| 110 | // UploadValidationException is used by the UploadValidators to |
| 111 | // stop the uploadPack. We do not want this exception to go beyond this |
| 112 | // point otherwise it would print a stacktrace in the logs and return an |
| 113 | // internal server error to the client. |
| 114 | if (!e.isOutput()) { |
| 115 | up.sendMessage(e.getMessage()); |
| 116 | } |
| 117 | } catch (RuntimeException e) { |
| 118 | error = e; |
| 119 | throw e; |
nothing calls this directly
no test coverage detected