]> source.dussan.org Git - gitea.git/commitdiff
Copy git data from disk when restore repository (#16066)
authorLunny Xiao <xiaolunwen@gmail.com>
Fri, 4 Jun 2021 13:14:20 +0000 (21:14 +0800)
committerGitHub <noreply@github.com>
Fri, 4 Jun 2021 13:14:20 +0000 (16:14 +0300)
modules/migrations/gitea_uploader.go
modules/migrations/migrate.go
modules/migrations/restore.go

index 217acb00e2156238efee734f3a0156245da0188a..2b18098b7f161696ab7873175445952c41002eed 100644 (file)
@@ -276,19 +276,22 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
                                // asset.DownloadURL maybe a local file
                                var rc io.ReadCloser
                                var err error
-                               if asset.DownloadURL == nil {
+                               if asset.DownloadFunc != nil {
                                        rc, err = asset.DownloadFunc()
                                        if err != nil {
                                                return err
                                        }
-                               } else {
+                               } else if asset.DownloadURL != nil {
                                        rc, err = uri.Open(*asset.DownloadURL)
                                        if err != nil {
                                                return err
                                        }
                                }
-                               defer rc.Close()
+                               if rc == nil {
+                                       return nil
+                               }
                                _, err = storage.Attachments.Save(attach.RelativePath(), rc, int64(*asset.Size))
+                               rc.Close()
                                return err
                        }()
                        if err != nil {
index 2f8889e67b5318ec4824ce42fedc494cd32ed916..7eff3a3576db77a776636688978e79903ca589d6 100644 (file)
@@ -184,7 +184,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
                return err
        }
 
-       log.Trace("migrating git data")
+       log.Trace("migrating git data from %s", repo.CloneURL)
        if err = uploader.CreateRepo(repo, opts); err != nil {
                return err
        }
index 4e63df14292ad706e0259e1abcb0a7b53ad145b6..5b44811d529274def75f69c67eb622a1a3ccf3f0 100644 (file)
@@ -83,7 +83,7 @@ func (r *RepositoryRestorer) GetRepoInfo() (*base.Repository, error) {
                IsPrivate:     isPrivate,
                Description:   opts["description"],
                OriginalURL:   opts["original_url"],
-               CloneURL:      opts["clone_addr"],
+               CloneURL:      filepath.Join(r.baseDir, "git"),
                DefaultBranch: opts["default_branch"],
        }, nil
 }
@@ -155,7 +155,9 @@ func (r *RepositoryRestorer) GetReleases() ([]*base.Release, error) {
        }
        for _, rel := range releases {
                for _, asset := range rel.Assets {
-                       *asset.DownloadURL = "file://" + filepath.Join(r.baseDir, *asset.DownloadURL)
+                       if asset.DownloadURL != nil {
+                               *asset.DownloadURL = "file://" + filepath.Join(r.baseDir, *asset.DownloadURL)
+                       }
                }
        }
        return releases, nil