diff --git a/internal/conf/path.go b/internal/conf/path.go index bfeb2d6d72..226dfff2c1 100644 --- a/internal/conf/path.go +++ b/internal/conf/path.go @@ -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 } diff --git a/pkg/path/path.go b/pkg/path/path.go new file mode 100644 index 0000000000..cf9995a10c --- /dev/null +++ b/pkg/path/path.go @@ -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) +}