Skip to content

Commit

Permalink
use filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Apr 22, 2024
1 parent 97f53fc commit 4b3fe2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/windows-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: test windows
on:
pull_request:
jobs:
tests:
runs-on: windows-latest
steps:
- uses: tidbcloud/setup-tidbcloud-cli@v0
with:
api_public_key: ${{ secrets.TIDB_CLOUD_API_PUBLIC_KEY }}
api_private_key: ${{ secrets.TIDB_CLOUD_API_PRIVATE_KEY }}
- name: run
run: ticloud serverless ls -p 1372813089191151295
7 changes: 0 additions & 7 deletions internal/cli/serverless/export/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ func DownloadCmd(h *internal.Helper) *cobra.Command {
}

func DownloadFilesPrompt(h *internal.Helper, urls []*exportModel.V1beta1DownloadURL, path string, concurrency int) error {
if path == "" {
path = "."
}
if concurrency <= 0 {
concurrency = 3
}
Expand Down Expand Up @@ -311,10 +308,6 @@ type DownloadJob struct {
}

func DownloadFilesWithoutPrompt(h *internal.Helper, urls []*exportModel.V1beta1DownloadURL, path string, concurrency int) error {
if path == "" {
path = "."
}

// create the path if not exist
err := util.CreateFolder(path)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions internal/util/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net/http"
"os"
"path/filepath"
)

// GetResponse returns the response of a given URL
Expand All @@ -39,13 +40,11 @@ func GetResponse(url string) (*http.Response, error) {

// CreateFile creates a file if it does not exist
func CreateFile(path, fileName string) (*os.File, error) {
if path == "" {
path = "."
}
if _, err := os.Stat(path + "/" + fileName); err == nil {
filePath := filepath.Join(path, fileName)
if _, err := os.Stat(filePath); err == nil {
return nil, fmt.Errorf("file already exists")
}
file, err := os.Create(path + "/" + fileName)
file, err := os.Create(filePath)
if err != nil {
return nil, err
}
Expand All @@ -54,6 +53,9 @@ func CreateFile(path, fileName string) (*os.File, error) {

// CreateFolder creates a folder if it does not exist
func CreateFolder(path string) error {
if path == "" {
return nil
}
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(path, 0755)
Expand Down

0 comments on commit 4b3fe2f

Please sign in to comment.