Welcome to mirror list, hosted at ThFree Co, Russian Federation.

upload_strategy.go « objectstore « internal « workhorse - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5707ba5f24eaef9cd900b5bcfc821aa96b575cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package objectstore

import (
	"context"
	"io"
	"net/http"

	"gitlab.com/gitlab-org/labkit/log"
	"gitlab.com/gitlab-org/labkit/mask"
)

type uploadStrategy interface {
	Upload(ctx context.Context, r io.Reader) error
	ETag() string
	Abort()
	Delete()
}

func deleteURL(url string) {
	if url == "" {
		return
	}

	req, err := http.NewRequest("DELETE", url, nil)
	if err != nil {
		log.WithError(err).WithField("object", mask.URL(url)).Warning("Delete failed")
		return
	}
	// TODO: consider adding the context to the outgoing request for better instrumentation

	// here we are not using u.ctx because we must perform cleanup regardless of parent context
	resp, err := httpClient.Do(req)
	if err != nil {
		log.WithError(err).WithField("object", mask.URL(url)).Warning("Delete failed")
		return
	}
	resp.Body.Close()
}

func extractETag(rawETag string) string {
	if rawETag != "" && rawETag[0] == '"' {
		rawETag = rawETag[1 : len(rawETag)-1]
	}

	return rawETag
}