@@ -7,6 +7,7 @@ package cmd
77
88import (
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
5157func 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.
0 commit comments