Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull: relay along errors encountered #737

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,10 @@ func (g *Commands) playPullChanges(cl []*Change, exports []string, opMap *map[Op

results := semalim.Run(jobsChan, uint64(n))
for result := range results {
res, err := result.Value(), result.Err()
if err != nil {
g.log.LogErrf("pull: %s err: %v\n", res, err)
res, rErr := result.Value(), result.Err()
if rErr != nil {
msg := fmt.Sprintf("%v err: %v\n", res, rErr)
err = reComposeError(err, msg)
}
}

Expand Down Expand Up @@ -602,13 +603,17 @@ func (g *Commands) makeExportsDir(segments ...string) string {
}

func (g *Commands) export(f *File, destAbsPath string, exports []string) (manifest []string, err error) {
if len(exports) < 1 || f == nil {
return
if len(exports) < 1 {
return nil, nil
}

if f == nil {
return nil, fmt.Errorf("nil file dereference")
}

dirPath := g.makeExportsDir(destAbsPath)
if err = os.MkdirAll(dirPath, os.ModeDir|0755); err != nil {
return
if err := os.MkdirAll(dirPath, os.ModeDir|0755); err != nil {
return nil, err
}

var ok bool
Expand All @@ -631,15 +636,17 @@ func (g *Commands) export(f *File, destAbsPath string, exports []string) (manife
}

n := len(waitables)
doneAck := make(chan bool, n)
errsChan := make(chan error, n)

basePath := filepath.Base(f.Name)
baseDir := path.Join(dirPath, basePath)

for _, exportee := range waitables {
go func(baseDirPath, id string, urlMExt *urlMimeTypeExt) error {
go func(baseDirPath, id string, urlMExt *urlMimeTypeExt) {
var err error

defer func() {
doneAck <- true
errsChan <- err
}()

exportPath := sepJoin(".", baseDirPath, urlMExt.ext)
Expand All @@ -661,20 +668,21 @@ func (g *Commands) export(f *File, destAbsPath string, exports []string) (manife
exportURL: urlMExt.url,
}

err := g.singleDownload(&dlArg)
err = g.singleDownload(&dlArg)
if err == nil {
manifest = append(manifest, exportPath)
}

return err
}(baseDir, f.Id, exportee)
}

for i := 0; i < n; i++ {
<-doneAck
ithErr := <-errsChan
if ithErr != nil {
err = reComposeError(err, ithErr.Error())
}
}

return
return manifest, err
}

func isLocalFile(f *File) bool {
Expand Down