Skip to content

Commit 38996b6

Browse files
committed
Merge branch 'master' into search_type
2 parents a2deec3 + fe79b13 commit 38996b6

File tree

124 files changed

+6045
-3333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+6045
-3333
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,6 @@ issues:
9898
- path: models/update.go
9999
linters:
100100
- unused
101+
- path: cmd/dump.go
102+
linters:
103+
- dupl

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ENV GOPROXY ${GOPROXY:-direct}
88

99
ARG GITEA_VERSION
1010
ARG TAGS="sqlite sqlite_unlock_notify"
11-
ENV TAGS "bindata $TAGS"
11+
ENV TAGS "bindata timetzdata $TAGS"
1212
ARG CGO_EXTRA_CFLAGS
1313

1414
#Build deps
@@ -38,7 +38,6 @@ RUN apk --no-cache add \
3838
s6 \
3939
sqlite \
4040
su-exec \
41-
tzdata \
4241
gnupg
4342

4443
RUN addgroup \

cmd/dump.go

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/models"
1919
"code.gitea.io/gitea/modules/log"
2020
"code.gitea.io/gitea/modules/setting"
21+
"code.gitea.io/gitea/modules/storage"
2122
"code.gitea.io/gitea/modules/util"
2223

2324
"gitea.com/macaron/session"
@@ -57,6 +58,8 @@ func addRecursive(w archiver.Writer, dirPath string, absPath string, verbose boo
5758
if err != nil {
5859
return fmt.Errorf("Could not open directory %s: %s", absPath, err)
5960
}
61+
defer dir.Close()
62+
6063
files, err := dir.Readdir(0)
6164
if err != nil {
6265
return fmt.Errorf("Unable to list files in %s: %s", absPath, err)
@@ -197,6 +200,10 @@ func runDump(ctx *cli.Context) error {
197200
return err
198201
}
199202

203+
if err := storage.Init(); err != nil {
204+
return err
205+
}
206+
200207
if file == nil {
201208
file, err = os.Create(fileName)
202209
if err != nil {
@@ -231,11 +238,21 @@ func runDump(ctx *cli.Context) error {
231238
fatal("Failed to include repositories: %v", err)
232239
}
233240

234-
if _, err := os.Stat(setting.LFS.ContentPath); !os.IsNotExist(err) {
235-
log.Info("Dumping lfs... %s", setting.LFS.ContentPath)
236-
if err := addRecursive(w, "lfs", setting.LFS.ContentPath, verbose); err != nil {
237-
fatal("Failed to include lfs: %v", err)
241+
if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error {
242+
info, err := object.Stat()
243+
if err != nil {
244+
return err
238245
}
246+
247+
return w.Write(archiver.File{
248+
FileInfo: archiver.FileInfo{
249+
FileInfo: info,
250+
CustomName: path.Join("data", "lfs", objPath),
251+
},
252+
ReadCloser: object,
253+
})
254+
}); err != nil {
255+
fatal("Failed to dump LFS objects: %v", err)
239256
}
240257
}
241258

@@ -302,13 +319,31 @@ func runDump(ctx *cli.Context) error {
302319
}
303320

304321
excludes = append(excludes, setting.RepoRootPath)
305-
excludes = append(excludes, setting.LFS.ContentPath)
322+
excludes = append(excludes, setting.LFS.Path)
323+
excludes = append(excludes, setting.Attachment.Path)
306324
excludes = append(excludes, setting.LogRootPath)
307325
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
308326
fatal("Failed to include data directory: %v", err)
309327
}
310328
}
311329

330+
if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error {
331+
info, err := object.Stat()
332+
if err != nil {
333+
return err
334+
}
335+
336+
return w.Write(archiver.File{
337+
FileInfo: archiver.FileInfo{
338+
FileInfo: info,
339+
CustomName: path.Join("data", "attachments", objPath),
340+
},
341+
ReadCloser: object,
342+
})
343+
}); err != nil {
344+
fatal("Failed to dump attachments: %v", err)
345+
}
346+
312347
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
313348
// ensuring that it's clear the dump is skipped whether the directory's initialized
314349
// yet or not.

cmd/migrate_storage.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"context"
99
"fmt"
10+
"strings"
1011

1112
"code.gitea.io/gitea/models"
1213
"code.gitea.io/gitea/models/migrations"
@@ -30,8 +31,8 @@ var CmdMigrateStorage = cli.Command{
3031
Usage: "Kinds of files to migrate, currently only 'attachments' is supported",
3132
},
3233
cli.StringFlag{
33-
Name: "store, s",
34-
Value: "local",
34+
Name: "storage, s",
35+
Value: setting.LocalStorageType,
3536
Usage: "New storage type, local or minio",
3637
},
3738
cli.StringFlag{
@@ -112,15 +113,15 @@ func runMigrateStorage(ctx *cli.Context) error {
112113

113114
var dstStorage storage.ObjectStorage
114115
var err error
115-
switch ctx.String("store") {
116-
case "local":
116+
switch strings.ToLower(ctx.String("storage")) {
117+
case setting.LocalStorageType:
117118
p := ctx.String("path")
118119
if p == "" {
119-
log.Fatal("Path must be given when store is loal")
120+
log.Fatal("Path must be given when storage is loal")
120121
return nil
121122
}
122123
dstStorage, err = storage.NewLocalStorage(p)
123-
case "minio":
124+
case setting.MinioStorageType:
124125
dstStorage, err = storage.NewMinioStorage(
125126
context.Background(),
126127
ctx.String("minio-endpoint"),
@@ -132,14 +133,14 @@ func runMigrateStorage(ctx *cli.Context) error {
132133
ctx.Bool("minio-use-ssl"),
133134
)
134135
default:
135-
return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store"))
136+
return fmt.Errorf("Unsupported attachments storage type: %s", ctx.String("storage"))
136137
}
137138

138139
if err != nil {
139140
return err
140141
}
141142

142-
tp := ctx.String("type")
143+
tp := strings.ToLower(ctx.String("type"))
143144
switch tp {
144145
case "attachments":
145146
if err := migrateAttachments(dstStorage); err != nil {

0 commit comments

Comments
 (0)