@@ -7,6 +7,7 @@ package cmd
7
7
8
8
import (
9
9
"fmt"
10
+ "io"
10
11
"os"
11
12
"path"
12
13
"path/filepath"
@@ -25,10 +26,21 @@ import (
25
26
"github.com/urfave/cli"
26
27
)
27
28
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 {
29
30
if verbose {
30
- log .Info ("Adding file %s\n " , filePath )
31
+ log .Info ("Adding file %s" , customName )
31
32
}
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 {
32
44
file , err := os .Open (absPath )
33
45
if err != nil {
34
46
return err
@@ -39,13 +51,7 @@ func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
39
51
return err
40
52
}
41
53
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 )
49
55
}
50
56
51
57
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`,
136
142
Name : "skip-attachment-data" ,
137
143
Usage : "Skip attachment data" ,
138
144
},
145
+ cli.BoolFlag {
146
+ Name : "skip-package-data" ,
147
+ Usage : "Skip package data" ,
148
+ },
139
149
cli.GenericFlag {
140
150
Name : "type" ,
141
151
Value : outputTypeEnum ,
@@ -241,13 +251,7 @@ func runDump(ctx *cli.Context) error {
241
251
return err
242
252
}
243
253
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 )
251
255
}); err != nil {
252
256
fatal ("Failed to dump LFS objects: %v" , err )
253
257
}
@@ -326,6 +330,7 @@ func runDump(ctx *cli.Context) error {
326
330
excludes = append (excludes , setting .RepoRootPath )
327
331
excludes = append (excludes , setting .LFS .Path )
328
332
excludes = append (excludes , setting .Attachment .Path )
333
+ excludes = append (excludes , setting .Packages .Path )
329
334
excludes = append (excludes , setting .LogRootPath )
330
335
excludes = append (excludes , absFileName )
331
336
if err := addRecursiveExclude (w , "data" , setting .AppDataPath , excludes , verbose ); err != nil {
@@ -341,17 +346,24 @@ func runDump(ctx *cli.Context) error {
341
346
return err
342
347
}
343
348
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 )
351
350
}); err != nil {
352
351
fatal ("Failed to dump attachments: %v" , err )
353
352
}
354
353
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
+
355
367
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
356
368
// ensuring that it's clear the dump is skipped whether the directory's initialized
357
369
// yet or not.
0 commit comments