Jelajahi Sumber

fix resume download

Bruce MacDonald 1 tahun lalu
induk
melakukan
c316893545
1 mengubah file dengan 17 tambahan dan 21 penghapusan
  1. 17 21
      cmd/cmd.go

+ 17 - 21
cmd/cmd.go

@@ -43,27 +43,23 @@ func RunRun(cmd *cobra.Command, args []string) error {
 }
 
 func pull(model string) error {
-	// TODO: check if the local model is up to date with remote
-	_, err := os.Stat(cacheDir() + "/models/" + model + ".bin")
-	switch {
-	case errors.Is(err, os.ErrNotExist):
-		client := api.NewClient()
-		var bar *progressbar.ProgressBar
-		return client.Pull(
-			context.Background(),
-			&api.PullRequest{Model: model},
-			func(progress api.PullProgress) error {
-				if bar == nil {
-					bar = progressbar.DefaultBytes(progress.Total)
-				}
-
-				return bar.Set64(progress.Completed)
-			},
-		)
-	case err != nil:
-		return err
-	}
-	return nil
+	client := api.NewClient()
+	var bar *progressbar.ProgressBar
+	return client.Pull(
+		context.Background(),
+		&api.PullRequest{Model: model},
+		func(progress api.PullProgress) error {
+			if bar == nil && progress.Percent == 100 {
+				// already downloaded
+				return nil
+			}
+			if bar == nil {
+				bar = progressbar.DefaultBytes(progress.Total)
+			}
+
+			return bar.Set64(progress.Completed)
+		},
+	)
 }
 
 func RunGenerate(_ *cobra.Command, args []string) error {