fix file size descriptor (#9568)

This commit is contained in:
Sylvia Moss 2020-07-14 11:36:49 +02:00 committed by GitHub
parent e2cbe0de48
commit eb5c3c3efb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 6 deletions

View File

@ -194,15 +194,20 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste
i.Path = s.Name + "-" + i.Path i.Path = s.Name + "-" + i.Path
} }
ui.Message("Downloading: " + i.File().Path) file := i.File()
err = s.Download(ctx, lease, i)
ui.Message("Downloading: " + file.Path)
size, err := s.Download(ctx, lease, i)
if err != nil { if err != nil {
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }
ui.Message("Exporting file: " + i.File().Path) // Fix file size descriptor
cdp.OvfFiles = append(cdp.OvfFiles, i.File()) file.Size = size
ui.Message("Exporting file: " + file.Path)
cdp.OvfFiles = append(cdp.OvfFiles, file)
} }
if err = lease.Complete(ctx); err != nil { if err = lease.Complete(ctx); err != nil {
@ -292,7 +297,7 @@ func (s *StepExport) addHash(p string, h hash.Hash) {
_, _ = fmt.Fprintf(&s.mf, "%s(%s)= %x\n", strings.ToUpper(s.Manifest), p, h.Sum(nil)) _, _ = fmt.Fprintf(&s.mf, "%s(%s)= %x\n", strings.ToUpper(s.Manifest), p, h.Sum(nil))
} }
func (s *StepExport) Download(ctx context.Context, lease *nfc.Lease, item nfc.FileItem) error { func (s *StepExport) Download(ctx context.Context, lease *nfc.Lease, item nfc.FileItem) (int64, error) {
path := filepath.Join(s.OutputDir, item.Path) path := filepath.Join(s.OutputDir, item.Path)
opts := soap.Download{} opts := soap.Download{}
@ -301,5 +306,14 @@ func (s *StepExport) Download(ctx context.Context, lease *nfc.Lease, item nfc.Fi
defer s.addHash(item.Path, h) defer s.addHash(item.Path, h)
} }
return lease.DownloadFile(ctx, path, item, opts) err := lease.DownloadFile(ctx, path, item, opts)
if err != nil {
return 0, err
}
f, err := os.Stat(path)
if err != nil {
return 0, err
}
return f.Size(), err
} }