github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/internal/safefilepath/path.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package safefilepath manipulates operating-system file paths. 6 package safefilepath 7 8 import ( 9 "errors" 10 "io/fs" 11 ) 12 13 var errInvalidPath = errors.New("invalid path") 14 15 // Localize is filepath.Localize. 16 // 17 // It is implemented in this package to avoid a dependency cycle 18 // between os and file/filepath. 19 // 20 // Tests for this function are in path/filepath. 21 func Localize(path string) (string, error) { 22 if !fs.ValidPath(path) { 23 return "", errInvalidPath 24 } 25 return localize(path) 26 }