Skip to content

Commit

Permalink
fix symlink error on windows,download and get api will return abs pat…
Browse files Browse the repository at this point in the history
…h now
  • Loading branch information
Cyberhan123 committed Dec 11, 2023
1 parent c0787b9 commit 3bf181c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 23 deletions.
23 changes: 18 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ func (r *CacheRepo) Get(filename string) (string, error) {
if _, err = os.Stat(path); err != nil {
return "", err
}
return path, nil

absPath, err := filepath.Abs(path)
if err != nil {
return "", err
}

return absPath, nil
}

func (r *CacheRepo) path() string {
Expand Down Expand Up @@ -213,7 +219,7 @@ func (r *Repo) FolderName() string {
case Dataset:
prefix = "datasets"
case Space:
prefix = "space"
prefix = "spaces"
}
result := fmt.Sprintf("%s--%s", prefix, r.repoId)
result = strings.ReplaceAll(result, "/", "--")
Expand Down Expand Up @@ -603,9 +609,11 @@ func (r *ApiRepo) Download(filename string) (string, error) {
} else {
message = filename
}
bar = progressbar.DefaultBytes(

bar = progressbar.NewOptions64(
int64(metadata.size),
message,
progressbar.OptionSetDescription(message),
progressbar.OptionUseANSICodes(useANSICodes),
)
}

Expand Down Expand Up @@ -637,7 +645,12 @@ func (r *ApiRepo) Download(filename string) (string, error) {
return "", err
}

return pointerPath, nil
absPointerPath, err := filepath.Abs(pointerPath)
if err != nil {
return "", err
}

return absPointerPath, nil
}

type Siblings struct {
Expand Down
18 changes: 0 additions & 18 deletions api/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ func shouldRedirect(statusCode int) bool {
return (redirectStatusCodes & statusCode) != 0
}

func symlinkOrRename(src, dst string) error {
if info, err := os.Stat(dst); err == nil && info != nil {
return nil
}

//relSrc := makeRelative(src, dst)

err := os.Symlink(src, dst)
if err != nil && !os.IsExist(err) {
err = os.Rename(src, dst)
if err != nil {
return err
}
}

return nil
}

func GetSHA256FromFile(path string) (string, error) {
f, err := os.Open(path)
defer f.Close()
Expand Down
36 changes: 36 additions & 0 deletions api/helper_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) seasonjs. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

//go:build !windows

package api

import (
"os"
"path/filepath"
)

const useANSICodes = true

func symlinkOrRename(src, dst string) error {
if info, err := os.Stat(dst); err == nil && info != nil {
return nil
}

absSrc, err := filepath.Abs(src)
if err != nil {
return err
}

absDst, err := filepath.Abs(dst)
if err != nil {
return err
}

err = os.Symlink(absSrc, absDst)
if err != nil && !os.IsExist(err) {
return err
}

return nil
}
38 changes: 38 additions & 0 deletions api/helper_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) seasonjs. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

//go:build windows

package api

import (
"os"
"path/filepath"
)

const useANSICodes = true

func symlinkOrRename(src, dst string) error {
if info, err := os.Stat(dst); err == nil && info != nil {
return nil
}

absSrc, err := filepath.Abs(src)
if err != nil {
return err
}

absDst, err := filepath.Abs(dst)
if err != nil {
return err
}

if err = os.Link(absSrc, absDst); !os.IsExist(err) && err != nil {
err = os.Rename(absSrc, absDst)
if err != nil {
return err
}
}

return nil
}

0 comments on commit 3bf181c

Please sign in to comment.