Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 953b35a

Browse files
committed
improve messaging in download command
* do not force download on new. but print a message * if failed to move even a single file. do not print corrupted message
1 parent 7887012 commit 953b35a

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

download_cmd.go

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path"
1111
"path/filepath"
12+
"sync/atomic"
1213

1314
"github.com/facebookgo/errgroup"
1415
"github.com/facebookgo/stackerr"
@@ -48,8 +49,10 @@ func (d *downloadCmd) moveFiles(
4849
var wg errgroup.Group
4950

5051
maxParallel := make(chan struct{}, maxOpenFD)
51-
wg.Add(len(release.Versions.Cloud) + len(release.Versions.Public))
52+
numFiles := len(release.Versions.Cloud) + len(release.Versions.Public)
53+
wg.Add(numFiles)
5254

55+
var numErrors int32
5356
moveFile := func(tempDir, kind, file, checksum string) {
5457
defer func() {
5558
wg.Done()
@@ -61,6 +64,7 @@ func (d *downloadCmd) moveFiles(
6164
0755,
6265
)
6366
if err != nil {
67+
atomic.AddInt32(&numErrors, 1)
6468
wg.Error(stackerr.Wrap(err))
6569
return
6670
}
@@ -70,6 +74,7 @@ func (d *downloadCmd) moveFiles(
7074
filepath.Join(e.Root, kind, file),
7175
)
7276
if err != nil {
77+
atomic.AddInt32(&numErrors, 1)
7378
wg.Error(stackerr.Wrap(err))
7479
return
7580
}
@@ -79,6 +84,7 @@ func (d *downloadCmd) moveFiles(
7984
checksum,
8085
)
8186
if err != nil {
87+
atomic.AddInt32(&numErrors, 1)
8288
wg.Error(err)
8389
return
8490
}
@@ -102,7 +108,37 @@ func (d *downloadCmd) moveFiles(
102108
checksum,
103109
)
104110
}
105-
return wg.Wait()
111+
112+
if err := wg.Wait(); err != nil {
113+
// could not move a single file so no corruption:w
114+
if int(numErrors) == numFiles {
115+
fmt.Fprintf(
116+
e.Out,
117+
`Failed to download Cloud Code to
118+
%q
119+
Try "parse download" and manually move contents from
120+
the temporary download location.
121+
`,
122+
e.Root,
123+
)
124+
return nil
125+
}
126+
127+
fmt.Fprintf(
128+
e.Out,
129+
`Failed to download Cloud Code to
130+
%q
131+
132+
It might have corrupted contents, due to partially moved files.
133+
134+
Try "parse download" and manually move contents from
135+
the temporary download location.
136+
`,
137+
e.Root,
138+
)
139+
return err
140+
}
141+
return nil
106142
}
107143

108144
func (d *downloadCmd) download(e *env, tempDir string, release *deployInfo) error {
@@ -221,21 +257,7 @@ func (d *downloadCmd) run(e *env, c *context) error {
221257
return nil
222258
}
223259

224-
err = d.moveFiles(e, tempDir, d.release)
225-
if err != nil {
226-
fmt.Fprintf(
227-
e.Out,
228-
`Failed to download Cloud Code to %q.
229-
Sorry! but %s might have corrupted contents.
230-
If you want to download Cloud Code from Parse,
231-
try again without the "-f" option.
232-
`,
233-
e.Root,
234-
e.Root,
235-
)
236-
return stackerr.Wrap(err)
237-
}
238-
return nil
260+
return stackerr.Wrap(d.moveFiles(e, tempDir, d.release))
239261
}
240262

241263
func newDownloadCmd(e *env) *cobra.Command {
@@ -247,6 +269,6 @@ func newDownloadCmd(e *env) *cobra.Command {
247269
Run: runWithClient(e, d.run),
248270
}
249271
cmd.Flags().BoolVarP(&d.force, "force", "f", d.force,
250-
"Force will overwrite any content in the current project directory")
272+
"Force will overwrite any files in the current project directory")
251273
return cmd
252274
}

new.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,13 @@ func (n *newCmd) run(e *env) error {
251251
}
252252

253253
if decision == "e" || decision == "existing" {
254-
fmt.Fprintln(e.Out, "Fetching Cloud Code for the selected app from Parse.")
255-
d := &downloadCmd{force: true}
256-
ctx, err := newContext(e, app.Name)
257-
if err != nil {
258-
return stackerr.Wrap(err)
259-
}
260-
if err := d.run(e, ctx); err != nil {
261-
return stackerr.Wrap(err)
262-
}
254+
fmt.Fprintln(
255+
e.Out,
256+
`
257+
NOTE: If you like to fetch the latest deployed Cloud Code from Parse,
258+
you can use the "parse download" command after finishing the set up.
259+
`,
260+
)
263261
}
264262

265263
fmt.Fprintf(e.Out, n.cloudCodeHelpMessage(e, app))

0 commit comments

Comments
 (0)