Skip to content

Commit

Permalink
feat(lib): provide path to abs func
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <huangjy@emqx.io>
  • Loading branch information
ngjaying committed Dec 24, 2024
1 parent 5f6f4aa commit 957b637
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/conf/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,16 @@ func relativePath(subdir string) (dir string, err error) {
}

func ProcessPath(p string) (string, error) {
if abs, err := filepath.Abs(p); err != nil {
return "", nil
} else {
if _, err := os.Stat(abs); os.IsNotExist(err) {
abs := p
var err error
if !filepath.IsAbs(p) {
abs, err = GetLoc(p)
if err != nil {
return "", err
}
return abs, nil
}
if _, err := os.Stat(abs); os.IsNotExist(err) {
return "", err
}
return abs, nil
}
28 changes: 28 additions & 0 deletions pkg/path/path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 EMQ Technologies Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package path

import (
"path/filepath"

"github.com/lf-edge/ekuiper/contract/v2/api"
)

func AbsPath(ctx api.StreamContext, path string) string {
if filepath.IsAbs(path) {
return path
}
return filepath.Join(ctx.GetRootPath(), path)
}

0 comments on commit 957b637

Please sign in to comment.