MCPcopy Create free account
hub / github.com/GerritCodeReview/gerrit / runImpl

Method runImpl

java/com/google/gerrit/sshd/commands/Upload.java:62–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 15

wrapMethod · 0.95
openMethod · 0.95
builderMethod · 0.95
getPackConfigMethod · 0.80
getTimeoutMethod · 0.80
isAllUsersMethod · 0.80
uploadMethod · 0.80
setPeerAgentMethod · 0.80
projectMethod · 0.65
userMethod · 0.65
checkMethod · 0.65

Tested by

no test coverage detected