Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
d54462870f
3 changed files with 22 additions and 6 deletions
|
@ -432,7 +432,7 @@ func SearchAssetsByName(keyword string, exts []string) (ret []*cache.Asset) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetAssetAbsPath(relativePath string) (absPath string, err error) {
|
||||
func GetAssetAbsPath(relativePath string) (ret string, err error) {
|
||||
relativePath = strings.TrimSpace(relativePath)
|
||||
if strings.Contains(relativePath, "?") {
|
||||
relativePath = relativePath[:strings.Index(relativePath, "?")]
|
||||
|
@ -455,13 +455,18 @@ func GetAssetAbsPath(relativePath string) (absPath string, err error) {
|
|||
}
|
||||
if p := filepath.ToSlash(path); strings.HasSuffix(p, relativePath) {
|
||||
if gulu.File.IsExist(path) {
|
||||
absPath = path
|
||||
ret = path
|
||||
return io.EOF
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if "" != absPath {
|
||||
|
||||
if "" != ret {
|
||||
if !util.IsSubPath(util.WorkspaceDir, ret) {
|
||||
err = fmt.Errorf("[%s] is not sub path of workspace", ret)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -469,7 +474,11 @@ func GetAssetAbsPath(relativePath string) (absPath string, err error) {
|
|||
// 在全局 assets 路径下搜索
|
||||
p := filepath.Join(util.DataDir, relativePath)
|
||||
if gulu.File.IsExist(p) {
|
||||
absPath = p
|
||||
ret = p
|
||||
if !util.IsSubPath(util.WorkspaceDir, ret) {
|
||||
err = fmt.Errorf("[%s] is not sub path of workspace", ret)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
|
||||
|
|
|
@ -190,6 +190,10 @@ func IsSubPath(absPath, toCheckPath string) bool {
|
|||
if 1 > len(absPath) || 1 > len(toCheckPath) {
|
||||
return false
|
||||
}
|
||||
if absPath == toCheckPath { // 相同路径时不认为是子路径
|
||||
return false
|
||||
}
|
||||
|
||||
if gulu.OS.IsWindows() {
|
||||
if filepath.IsAbs(absPath) && filepath.IsAbs(toCheckPath) {
|
||||
if strings.ToLower(absPath)[0] != strings.ToLower(toCheckPath)[0] {
|
||||
|
|
|
@ -268,9 +268,12 @@ func IsDisplayableAsset(p string) bool {
|
|||
|
||||
func GetAbsPathInWorkspace(relPath string) (string, error) {
|
||||
absPath := filepath.Join(WorkspaceDir, relPath)
|
||||
if WorkspaceDir == absPath {
|
||||
return absPath, nil
|
||||
}
|
||||
|
||||
if IsSubPath(WorkspaceDir, absPath) {
|
||||
return absPath, nil
|
||||
} else {
|
||||
return "", os.ErrPermission
|
||||
}
|
||||
return "", os.ErrPermission
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue