Skip to content

Commit e4274f6

Browse files
KN4CK3R6543wxiaoguang
authored
Allow package dump skipping (#19506)
* Added addReader to support verbose. * Allow skipping packages. * Updated docs. * Update cmd/dump.go Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 6dd3637 commit e4274f6

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

cmd/dump.go

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77

88
import (
99
"fmt"
10+
"io"
1011
"os"
1112
"path"
1213
"path/filepath"
@@ -25,10 +26,21 @@ import (
2526
"github.com/urfave/cli"
2627
)
2728

28-
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
29+
func addReader(w archiver.Writer, r io.ReadCloser, info os.FileInfo, customName string, verbose bool) error {
2930
if verbose {
30-
log.Info("Adding file %s\n", filePath)
31+
log.Info("Adding file %s", customName)
3132
}
33+
34+
return w.Write(archiver.File{
35+
FileInfo: archiver.FileInfo{
36+
FileInfo: info,
37+
CustomName: customName,
38+
},
39+
ReadCloser: r,
40+
})
41+
}
42+
43+
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
3244
file, err := os.Open(absPath)
3345
if err != nil {
3446
return err
@@ -39,13 +51,7 @@ func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
3951
return err
4052
}
4153

42-
return w.Write(archiver.File{
43-
FileInfo: archiver.FileInfo{
44-
FileInfo: fileInfo,
45-
CustomName: filePath,
46-
},
47-
ReadCloser: file,
48-
})
54+
return addReader(w, file, fileInfo, filePath, verbose)
4955
}
5056

5157
func isSubdir(upper, lower string) (bool, error) {
@@ -136,6 +142,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
136142
Name: "skip-attachment-data",
137143
Usage: "Skip attachment data",
138144
},
145+
cli.BoolFlag{
146+
Name: "skip-package-data",
147+
Usage: "Skip package data",
148+
},
139149
cli.GenericFlag{
140150
Name: "type",
141151
Value: outputTypeEnum,
@@ -241,13 +251,7 @@ func runDump(ctx *cli.Context) error {
241251
return err
242252
}
243253

244-
return w.Write(archiver.File{
245-
FileInfo: archiver.FileInfo{
246-
FileInfo: info,
247-
CustomName: path.Join("data", "lfs", objPath),
248-
},
249-
ReadCloser: object,
250-
})
254+
return addReader(w, object, info, path.Join("data", "lfs", objPath), verbose)
251255
}); err != nil {
252256
fatal("Failed to dump LFS objects: %v", err)
253257
}
@@ -326,6 +330,7 @@ func runDump(ctx *cli.Context) error {
326330
excludes = append(excludes, setting.RepoRootPath)
327331
excludes = append(excludes, setting.LFS.Path)
328332
excludes = append(excludes, setting.Attachment.Path)
333+
excludes = append(excludes, setting.Packages.Path)
329334
excludes = append(excludes, setting.LogRootPath)
330335
excludes = append(excludes, absFileName)
331336
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
@@ -341,17 +346,24 @@ func runDump(ctx *cli.Context) error {
341346
return err
342347
}
343348

344-
return w.Write(archiver.File{
345-
FileInfo: archiver.FileInfo{
346-
FileInfo: info,
347-
CustomName: path.Join("data", "attachments", objPath),
348-
},
349-
ReadCloser: object,
350-
})
349+
return addReader(w, object, info, path.Join("data", "attachments", objPath), verbose)
351350
}); err != nil {
352351
fatal("Failed to dump attachments: %v", err)
353352
}
354353

354+
if ctx.IsSet("skip-package-data") && ctx.Bool("skip-package-data") {
355+
log.Info("Skip dumping package data")
356+
} else if err := storage.Packages.IterateObjects(func(objPath string, object storage.Object) error {
357+
info, err := object.Stat()
358+
if err != nil {
359+
return err
360+
}
361+
362+
return addReader(w, object, info, path.Join("data", "packages", objPath), verbose)
363+
}); err != nil {
364+
fatal("Failed to dump packages: %v", err)
365+
}
366+
355367
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
356368
// ensuring that it's clear the dump is skipped whether the directory's initialized
357369
// yet or not.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,13 @@ in the current directory.
313313
- `--tempdir path`, `-t path`: Path to the temporary directory used. Optional. (default: /tmp).
314314
- `--skip-repository`, `-R`: Skip the repository dumping. Optional.
315315
- `--skip-custom-dir`: Skip dumping of the custom dir. Optional.
316+
- `--skip-lfs-data`: Skip dumping of LFS data. Optional.
317+
- `--skip-attachment-data`: Skip dumping of attachment data. Optional.
318+
- `--skip-package-data`: Skip dumping of package data. Optional.
319+
- `--skip-log`: Skip dumping of log data. Optional.
316320
- `--database`, `-d`: Specify the database SQL syntax. Optional.
317321
- `--verbose`, `-V`: If provided, shows additional details. Optional.
322+
- `--type`: Set the dump output format. Optional. (default: zip)
318323
- Examples:
319324
- `gitea dump`
320325
- `gitea dump --verbose`

0 commit comments

Comments
 (0)