@@ -107,10 +107,23 @@ func NewDumper(ctx context.Context, format string, output io.Writer) (*Dumper, e
107107 return d , nil
108108}
109109
110- // AddFilePath adds a file by its filesystem path
111- func (dumper * Dumper ) AddFilePath (filePath , absPath string ) error {
110+ func (dumper * Dumper ) runArchiveJob (job archives.ArchiveAsyncJob ) error {
111+ dumper .jobs <- job
112+ select {
113+ case err := <- dumper .errArchiveAsync :
114+ if err == nil {
115+ return errors .New ("archiver has been closed" )
116+ }
117+ return err
118+ case err := <- dumper .errArchiveJob :
119+ return err
120+ }
121+ }
122+
123+ // AddFileByPath adds a file by its filesystem path
124+ func (dumper * Dumper ) AddFileByPath (filePath , absPath string ) error {
112125 if dumper .Verbose {
113- log .Info ("Adding file path %s" , filePath )
126+ log .Info ("Adding local file %s" , filePath )
114127 }
115128
116129 fileInfo , err := os .Stat (absPath )
@@ -121,24 +134,13 @@ func (dumper *Dumper) AddFilePath(filePath, absPath string) error {
121134 archiveFileInfo := archives.FileInfo {
122135 FileInfo : fileInfo ,
123136 NameInArchive : filePath ,
124- Open : func () (fs.File , error ) {
125- return os .Open (absPath )
126- },
137+ Open : func () (fs.File , error ) { return os .Open (absPath ) },
127138 }
128139
129- dumper .jobs <- archives.ArchiveAsyncJob {
140+ return dumper .runArchiveJob ( archives.ArchiveAsyncJob {
130141 File : archiveFileInfo ,
131142 Result : dumper .errArchiveJob ,
132- }
133- select {
134- case err = <- dumper .errArchiveAsync :
135- if err == nil {
136- return errors .New ("archiver has been closed" )
137- }
138- return err
139- case err = <- dumper .errArchiveJob :
140- return err
141- }
143+ })
142144}
143145
144146type readerFile struct {
@@ -152,35 +154,28 @@ func (f *readerFile) Stat() (fs.FileInfo, error) { return f.info, nil }
152154func (f * readerFile ) Read (bytes []byte ) (int , error ) { return f .r .Read (bytes ) }
153155func (f * readerFile ) Close () error { return nil }
154156
155- // AddReader adds a file's contents from a Reader, this uses a pipe to stream files from object store to prevent them from filling up disk
156- func (dumper * Dumper ) AddReader (r io.Reader , info os.FileInfo , customName string ) error {
157+ // AddFileByReader adds a file's contents from a Reader
158+ func (dumper * Dumper ) AddFileByReader (r io.Reader , info os.FileInfo , customName string ) error {
157159 if dumper .Verbose {
158- log .Info ("Adding file %s" , customName )
160+ log .Info ("Adding storage file %s" , customName )
159161 }
160162
161163 fileInfo := archives.FileInfo {
162164 FileInfo : info ,
163165 NameInArchive : customName ,
164166 Open : func () (fs.File , error ) { return & readerFile {r , info }, nil },
165167 }
166-
167- dumper .jobs <- archives.ArchiveAsyncJob {
168+ return dumper .runArchiveJob (archives.ArchiveAsyncJob {
168169 File : fileInfo ,
169170 Result : dumper .errArchiveJob ,
170- }
171- return <- dumper .errArchiveJob
171+ })
172172}
173173
174174func (dumper * Dumper ) Close () error {
175175 close (dumper .jobs )
176176 return <- dumper .errArchiveAsync
177177}
178178
179- // AddFile kept for backwards compatibility since streaming is more efficient
180- func (dumper * Dumper ) AddFile (filePath , absPath string ) error {
181- return dumper .AddFilePath (filePath , absPath )
182- }
183-
184179func (dumper * Dumper ) normalizeFilePath (absPath string ) string {
185180 absPath = filepath .Clean (absPath )
186181 if setting .IsWindows {
@@ -231,7 +226,7 @@ func (dumper *Dumper) addFileOrDir(insidePath, absPath string, excludes []string
231226
232227 currentInsidePath := path .Join (insidePath , file .Name ())
233228 if file .IsDir () {
234- if err := dumper .AddFile (currentInsidePath , currentAbsPath ); err != nil {
229+ if err := dumper .AddFileByPath (currentInsidePath , currentAbsPath ); err != nil {
235230 return err
236231 }
237232 if err = dumper .addFileOrDir (currentInsidePath , currentAbsPath , excludes ); err != nil {
@@ -252,7 +247,7 @@ func (dumper *Dumper) addFileOrDir(insidePath, absPath string, excludes []string
252247 shouldAdd = targetStat .Mode ().IsRegular ()
253248 }
254249 if shouldAdd {
255- if err = dumper .AddFile (currentInsidePath , currentAbsPath ); err != nil {
250+ if err = dumper .AddFileByPath (currentInsidePath , currentAbsPath ); err != nil {
256251 return err
257252 }
258253 }
0 commit comments