Skip to content

Commit b62c9bc

Browse files
authored
Merge branch 'master' into more-radical-savepatch
2 parents 6ae5c4d + c3d31e5 commit b62c9bc

File tree

19 files changed

+218
-53
lines changed

19 files changed

+218
-53
lines changed

cmd/web.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func runWeb(ctx *cli.Context) error {
122122
switch setting.Protocol {
123123
case setting.UnixSocket:
124124
case setting.FCGI:
125+
case setting.FCGIUnix:
125126
default:
126127
// Save LOCAL_ROOT_URL if port changed
127128
cfg := ini.Empty()
@@ -149,7 +150,7 @@ func runWeb(ctx *cli.Context) error {
149150
}
150151

151152
listenAddr := setting.HTTPAddr
152-
if setting.Protocol != setting.UnixSocket {
153+
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
153154
listenAddr += ":" + setting.HTTPPort
154155
}
155156
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
@@ -183,10 +184,13 @@ func runWeb(ctx *cli.Context) error {
183184
err = runHTTPS("tcp", listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
184185
case setting.FCGI:
185186
NoHTTPRedirector()
186-
err = runFCGI(listenAddr, context2.ClearHandler(m))
187+
err = runFCGI("tcp", listenAddr, context2.ClearHandler(m))
187188
case setting.UnixSocket:
188189
NoHTTPRedirector()
189190
err = runHTTP("unix", listenAddr, context2.ClearHandler(m))
191+
case setting.FCGIUnix:
192+
NoHTTPRedirector()
193+
err = runFCGI("unix", listenAddr, context2.ClearHandler(m))
190194
default:
191195
log.Fatal("Invalid protocol: %s", setting.Protocol)
192196
}

cmd/web_graceful.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func NoMainListener() {
3737
graceful.Manager.InformCleanup()
3838
}
3939

40-
func runFCGI(listenAddr string, m http.Handler) error {
40+
func runFCGI(network, listenAddr string, m http.Handler) error {
4141
// This needs to handle stdin as fcgi point
42-
fcgiServer := graceful.NewServer("tcp", listenAddr)
42+
fcgiServer := graceful.NewServer(network, listenAddr)
4343

4444
err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
4545
return fcgi.Serve(listener, m)

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
140140

141141
## Server (`server`)
142142

143-
- `PROTOCOL`: **http**: \[http, https, fcgi, unix\]
143+
- `PROTOCOL`: **http**: \[http, https, fcgi, unix, fcgi+unix\]
144144
- `DOMAIN`: **localhost**: Domain name of this server.
145145
- `ROOT_URL`: **%(PROTOCOL)s://%(DOMAIN)s:%(HTTP\_PORT)s/**:
146146
Overwrite the automatically generated public URL.
@@ -155,7 +155,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
155155
- `HTTP_ADDR`: **0.0.0.0**: HTTP listen address.
156156
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
157157
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
158-
- If `PROTOCOL` is set to `unix`, this should be the name of the Unix socket file to use.
158+
- If `PROTOCOL` is set to `unix` or `fcgi+unix`, this should be the name of the Unix socket file to use.
159159
- `HTTP_PORT`: **3000**: HTTP listen port.
160160
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
161161
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.

docs/content/doc/usage/command-line.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Starts the server:
4646
- `gitea web --port 80`
4747
- `gitea web --config /etc/gitea.ini --pid /var/run/gitea.pid`
4848
- Notes:
49-
- Gitea should not be run as root. To bind to a port below 1000, you can use setcap on
49+
- Gitea should not be run as root. To bind to a port below 1024, you can use setcap on
5050
Linux: `sudo setcap 'cap_net_bind_service=+ep' /path/to/gitea`. This will need to be
5151
redone every time you update Gitea.
5252

integrations/attachement_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"bytes"
9+
"image"
10+
"image/png"
11+
"io"
12+
"mime/multipart"
13+
"net/http"
14+
"testing"
15+
16+
"code.gitea.io/gitea/modules/test"
17+
"github.com/stretchr/testify/assert"
18+
)
19+
20+
func generateImg() bytes.Buffer {
21+
// Generate image
22+
myImage := image.NewRGBA(image.Rect(0, 0, 32, 32))
23+
var buff bytes.Buffer
24+
png.Encode(&buff, myImage)
25+
return buff
26+
}
27+
28+
func createAttachment(t *testing.T, session *TestSession, repoURL, filename string, buff bytes.Buffer, expectedStatus int) string {
29+
body := &bytes.Buffer{}
30+
31+
//Setup multi-part
32+
writer := multipart.NewWriter(body)
33+
part, err := writer.CreateFormFile("file", filename)
34+
assert.NoError(t, err)
35+
_, err = io.Copy(part, &buff)
36+
assert.NoError(t, err)
37+
err = writer.Close()
38+
assert.NoError(t, err)
39+
40+
csrf := GetCSRF(t, session, repoURL)
41+
42+
req := NewRequestWithBody(t, "POST", "/attachments", body)
43+
req.Header.Add("X-Csrf-Token", csrf)
44+
req.Header.Add("Content-Type", writer.FormDataContentType())
45+
resp := session.MakeRequest(t, req, expectedStatus)
46+
47+
if expectedStatus != http.StatusOK {
48+
return ""
49+
}
50+
var obj map[string]string
51+
DecodeJSON(t, resp, &obj)
52+
return obj["uuid"]
53+
}
54+
55+
func TestCreateAnonymousAttachment(t *testing.T) {
56+
prepareTestEnv(t)
57+
session := emptyTestSession(t)
58+
createAttachment(t, session, "user2/repo1", "image.png", generateImg(), http.StatusFound)
59+
}
60+
61+
func TestCreateIssueAttachement(t *testing.T) {
62+
prepareTestEnv(t)
63+
const repoURL = "user2/repo1"
64+
session := loginUser(t, "user2")
65+
uuid := createAttachment(t, session, repoURL, "image.png", generateImg(), http.StatusOK)
66+
67+
req := NewRequest(t, "GET", repoURL+"/issues/new")
68+
resp := session.MakeRequest(t, req, http.StatusOK)
69+
htmlDoc := NewHTMLParser(t, resp.Body)
70+
71+
link, exists := htmlDoc.doc.Find("form").Attr("action")
72+
assert.True(t, exists, "The template has changed")
73+
74+
postData := map[string]string{
75+
"_csrf": htmlDoc.GetCSRF(),
76+
"title": "New Issue With Attachement",
77+
"content": "some content",
78+
"files[0]": uuid,
79+
}
80+
81+
req = NewRequestWithValues(t, "POST", link, postData)
82+
resp = session.MakeRequest(t, req, http.StatusFound)
83+
test.RedirectURL(resp) // check that redirect URL exists
84+
85+
//Validate that attachement is available
86+
req = NewRequest(t, "GET", "/attachments/"+uuid)
87+
session.MakeRequest(t, req, http.StatusOK)
88+
}

integrations/release_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestCreateRelease(t *testing.T) {
7878
session := loginUser(t, "user2")
7979
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
8080

81-
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 1)
81+
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 2)
8282
}
8383

8484
func TestCreateReleasePreRelease(t *testing.T) {
@@ -87,7 +87,7 @@ func TestCreateReleasePreRelease(t *testing.T) {
8787
session := loginUser(t, "user2")
8888
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
8989

90-
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 1)
90+
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 2)
9191
}
9292

9393
func TestCreateReleaseDraft(t *testing.T) {
@@ -96,7 +96,7 @@ func TestCreateReleaseDraft(t *testing.T) {
9696
session := loginUser(t, "user2")
9797
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
9898

99-
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 1)
99+
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 2)
100100
}
101101

102102
func TestCreateReleasePaging(t *testing.T) {

models/attachment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) {
133133
return attach, nil
134134
}
135135

136+
// GetAttachmentsByUUIDs returns attachment by given UUID list.
137+
func GetAttachmentsByUUIDs(uuids []string) ([]*Attachment, error) {
138+
return getAttachmentsByUUIDs(x, uuids)
139+
}
140+
136141
func getAttachmentsByUUIDs(e Engine, uuids []string) ([]*Attachment, error) {
137142
if len(uuids) == 0 {
138143
return []*Attachment{}, nil

models/attachment_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@ func TestUpdateAttachment(t *testing.T) {
116116

117117
AssertExistsAndLoadBean(t, &Attachment{Name: "new_name"})
118118
}
119+
120+
func TestGetAttachmentsByUUIDs(t *testing.T) {
121+
assert.NoError(t, PrepareTestDatabase())
122+
123+
attachList, err := GetAttachmentsByUUIDs([]string{"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", "not-existing-uuid"})
124+
assert.NoError(t, err)
125+
assert.Equal(t, 2, len(attachList))
126+
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attachList[0].UUID)
127+
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", attachList[1].UUID)
128+
assert.Equal(t, int64(1), attachList[0].IssueID)
129+
assert.Equal(t, int64(5), attachList[1].IssueID)
130+
}

models/fixtures/attachment.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,18 @@
6969
name: attach1
7070
download_count: 0
7171
created_unix: 946684800
72+
73+
-
74+
id: 9
75+
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a19
76+
release_id: 1
77+
name: attach1
78+
download_count: 0
79+
created_unix: 946684800
80+
81+
-
82+
id: 10
83+
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a20
84+
name: attach1
85+
download_count: 0
86+
created_unix: 946684800

models/fixtures/release.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
[] # empty
1+
-
2+
id: 1
3+
repo_id: 1
4+
publisher_id: 2
5+
tag_name: "v1.1"
6+
lower_tag_name: "v1.1"
7+
target: "master"
8+
title: "testing-release"
9+
sha1: "65f1bf27bc3bf70f64657658635e66094edbcb4d"
10+
num_commits: 10
11+
is_draft: false
12+
is_prerelease: false
13+
is_tag: false
14+
created_unix: 946684800

models/issue_comment.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,9 @@ func updateCommentInfos(e *xorm.Session, opts *CreateCommentOptions, comment *Co
567567
}
568568

569569
// Check attachments
570-
attachments := make([]*Attachment, 0, len(opts.Attachments))
571-
for _, uuid := range opts.Attachments {
572-
attach, err := getAttachmentByUUID(e, uuid)
573-
if err != nil {
574-
if IsErrAttachmentNotExist(err) {
575-
continue
576-
}
577-
return fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
578-
}
579-
attachments = append(attachments, attach)
570+
attachments, err := getAttachmentsByUUIDs(e, opts.Attachments)
571+
if err != nil {
572+
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err)
580573
}
581574

582575
for i := range attachments {

models/release.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,9 @@ func UpdateRelease(rel *Release) error {
129129
// AddReleaseAttachments adds a release attachments
130130
func AddReleaseAttachments(releaseID int64, attachmentUUIDs []string) (err error) {
131131
// Check attachments
132-
var attachments = make([]*Attachment, 0)
133-
for _, uuid := range attachmentUUIDs {
134-
attach, err := getAttachmentByUUID(x, uuid)
135-
if err != nil {
136-
if IsErrAttachmentNotExist(err) {
137-
continue
138-
}
139-
return fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
140-
}
141-
attachments = append(attachments, attach)
132+
attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs)
133+
if err != nil {
134+
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", attachmentUUIDs, err)
142135
}
143136

144137
for i := range attachments {

models/test_fixtures.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,37 @@ func LoadFixtures() error {
3535
if err != nil {
3636
fmt.Printf("LoadFixtures failed after retries: %v\n", err)
3737
}
38+
// Now if we're running postgres we need to tell it to update the sequences
39+
if x.Dialect().DriverName() == "postgres" {
40+
results, err := x.QueryString(`SELECT 'SELECT SETVAL(' ||
41+
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
42+
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
43+
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
44+
FROM pg_class AS S,
45+
pg_depend AS D,
46+
pg_class AS T,
47+
pg_attribute AS C,
48+
pg_tables AS PGT
49+
WHERE S.relkind = 'S'
50+
AND S.oid = D.objid
51+
AND D.refobjid = T.oid
52+
AND D.refobjid = C.attrelid
53+
AND D.refobjsubid = C.attnum
54+
AND T.relname = PGT.tablename
55+
ORDER BY S.relname;`)
56+
if err != nil {
57+
fmt.Printf("Failed to generate sequence update: %v\n", err)
58+
return err
59+
}
60+
for _, r := range results {
61+
for _, value := range r {
62+
_, err = x.Exec(value)
63+
if err != nil {
64+
fmt.Printf("Failed to update sequence: %s Error: %v\n", value, err)
65+
return err
66+
}
67+
}
68+
}
69+
}
3870
return err
3971
}

0 commit comments

Comments
 (0)