@@ -49,38 +49,6 @@ func addFile(w archiver.Writer, filePath string, absPath string, verbose bool) e
49
49
})
50
50
}
51
51
52
- func addRecursive (w archiver.Writer , dirPath string , absPath string , verbose bool ) error {
53
- if verbose {
54
- log .Info ("Adding dir %s\n " , dirPath )
55
- }
56
- dir , err := os .Open (absPath )
57
- if err != nil {
58
- return fmt .Errorf ("Could not open directory %s: %s" , absPath , err )
59
- }
60
- defer dir .Close ()
61
-
62
- files , err := dir .Readdir (0 )
63
- if err != nil {
64
- return fmt .Errorf ("Unable to list files in %s: %s" , absPath , err )
65
- }
66
-
67
- if err := addFile (w , dirPath , absPath , false ); err != nil {
68
- return err
69
- }
70
-
71
- for _ , fileInfo := range files {
72
- if fileInfo .IsDir () {
73
- err = addRecursive (w , filepath .Join (dirPath , fileInfo .Name ()), filepath .Join (absPath , fileInfo .Name ()), verbose )
74
- } else {
75
- err = addFile (w , filepath .Join (dirPath , fileInfo .Name ()), filepath .Join (absPath , fileInfo .Name ()), verbose )
76
- }
77
- if err != nil {
78
- return err
79
- }
80
- }
81
- return nil
82
- }
83
-
84
52
func isSubdir (upper string , lower string ) (bool , error ) {
85
53
if relPath , err := filepath .Rel (upper , lower ); err != nil {
86
54
return false , err
@@ -157,6 +125,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
157
125
Name : "skip-log, L" ,
158
126
Usage : "Skip the log dumping" ,
159
127
},
128
+ cli.BoolFlag {
129
+ Name : "skip-custom-dir" ,
130
+ Usage : "Skip custom directory" ,
131
+ },
160
132
cli.GenericFlag {
161
133
Name : "type" ,
162
134
Value : outputTypeEnum ,
@@ -211,6 +183,11 @@ func runDump(ctx *cli.Context) error {
211
183
}
212
184
defer file .Close ()
213
185
186
+ absFileName , err := filepath .Abs (fileName )
187
+ if err != nil {
188
+ return err
189
+ }
190
+
214
191
verbose := ctx .Bool ("verbose" )
215
192
outType := ctx .String ("type" )
216
193
var iface interface {}
@@ -233,7 +210,7 @@ func runDump(ctx *cli.Context) error {
233
210
log .Info ("Skip dumping local repositories" )
234
211
} else {
235
212
log .Info ("Dumping local repositories... %s" , setting .RepoRootPath )
236
- if err := addRecursive (w , "repos" , setting .RepoRootPath , verbose ); err != nil {
213
+ if err := addRecursiveExclude (w , "repos" , setting .RepoRootPath , [] string { absFileName } , verbose ); err != nil {
237
214
fatal ("Failed to include repositories: %v" , err )
238
215
}
239
216
@@ -292,17 +269,21 @@ func runDump(ctx *cli.Context) error {
292
269
}
293
270
}
294
271
295
- customDir , err := os .Stat (setting .CustomPath )
296
- if err == nil && customDir .IsDir () {
297
- if is , _ := isSubdir (setting .AppDataPath , setting .CustomPath ); ! is {
298
- if err := addRecursive (w , "custom" , setting .CustomPath , verbose ); err != nil {
299
- fatal ("Failed to include custom: %v" , err )
272
+ if ctx .IsSet ("skip-custom-dir" ) && ctx .Bool ("skip-custom-dir" ) {
273
+ log .Info ("Skiping custom directory" )
274
+ } else {
275
+ customDir , err := os .Stat (setting .CustomPath )
276
+ if err == nil && customDir .IsDir () {
277
+ if is , _ := isSubdir (setting .AppDataPath , setting .CustomPath ); ! is {
278
+ if err := addRecursiveExclude (w , "custom" , setting .CustomPath , []string {absFileName }, verbose ); err != nil {
279
+ fatal ("Failed to include custom: %v" , err )
280
+ }
281
+ } else {
282
+ log .Info ("Custom dir %s is inside data dir %s, skipped" , setting .CustomPath , setting .AppDataPath )
300
283
}
301
284
} else {
302
- log .Info ("Custom dir %s is inside data dir %s , skipped" , setting .CustomPath , setting . AppDataPath )
285
+ log .Info ("Custom dir %s doesn't exist , skipped" , setting .CustomPath )
303
286
}
304
- } else {
305
- log .Info ("Custom dir %s doesn't exist, skipped" , setting .CustomPath )
306
287
}
307
288
308
289
isExist , err := util .IsExist (setting .AppDataPath )
@@ -325,6 +306,7 @@ func runDump(ctx *cli.Context) error {
325
306
excludes = append (excludes , setting .LFS .Path )
326
307
excludes = append (excludes , setting .Attachment .Path )
327
308
excludes = append (excludes , setting .LogRootPath )
309
+ excludes = append (excludes , absFileName )
328
310
if err := addRecursiveExclude (w , "data" , setting .AppDataPath , excludes , verbose ); err != nil {
329
311
fatal ("Failed to include data directory: %v" , err )
330
312
}
@@ -358,7 +340,7 @@ func runDump(ctx *cli.Context) error {
358
340
log .Error ("Unable to check if %s exists. Error: %v" , setting .LogRootPath , err )
359
341
}
360
342
if isExist {
361
- if err := addRecursive (w , "log" , setting .LogRootPath , verbose ); err != nil {
343
+ if err := addRecursiveExclude (w , "log" , setting .LogRootPath , [] string { absFileName } , verbose ); err != nil {
362
344
fatal ("Failed to include log: %v" , err )
363
345
}
364
346
}
0 commit comments