|
|
|
@ -5,6 +5,7 @@ import (
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/mickael-menu/zk/util/errors"
|
|
|
|
|
"github.com/mickael-menu/zk/util/paths"
|
|
|
|
@ -254,10 +255,10 @@ func (zk *Zk) DBPath() string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RelPath returns the path relative to the notebook root to the given path.
|
|
|
|
|
func (zk *Zk) RelPath(path string) (string, error) {
|
|
|
|
|
wrap := errors.Wrapperf("%v: not a valid notebook path", path)
|
|
|
|
|
func (zk *Zk) RelPath(absPath string) (string, error) {
|
|
|
|
|
wrap := errors.Wrapperf("%v: not a valid notebook path", absPath)
|
|
|
|
|
|
|
|
|
|
path, err := filepath.Abs(path)
|
|
|
|
|
path, err := filepath.Abs(absPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return path, wrap(err)
|
|
|
|
|
}
|
|
|
|
@ -265,6 +266,9 @@ func (zk *Zk) RelPath(path string) (string, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return path, wrap(err)
|
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(path, "..") {
|
|
|
|
|
return path, fmt.Errorf("%s: path is outside the notebook", absPath)
|
|
|
|
|
}
|
|
|
|
|
if path == "." {
|
|
|
|
|
path = ""
|
|
|
|
|
}
|
|
|
|
|