2018-01-28 14:56:30 +00:00
|
|
|
// Copyright 2013, 2014 Canonical Ltd.
|
|
|
|
// Licensed under the LGPLv3, see LICENCE file for details.
|
|
|
|
|
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
2019-04-21 17:58:15 +00:00
|
|
|
"go/build"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-01-28 14:56:30 +00:00
|
|
|
"strings"
|
2019-11-03 17:51:13 +00:00
|
|
|
"sync/atomic"
|
2018-01-28 14:56:30 +00:00
|
|
|
)
|
|
|
|
|
2019-11-03 17:51:13 +00:00
|
|
|
var trimValue atomic.Value
|
|
|
|
var trimDefault = filepath.Join(build.Default.GOPATH, "src") + string(os.PathSeparator)
|
2018-01-28 14:56:30 +00:00
|
|
|
|
2019-11-03 17:51:13 +00:00
|
|
|
func trimSourcePath(filename string) string {
|
|
|
|
prefix := trimDefault
|
|
|
|
if v := trimValue.Load(); v != nil {
|
|
|
|
prefix = v.(string)
|
|
|
|
}
|
|
|
|
return strings.TrimPrefix(filename, prefix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetSourceTrimPrefix(s string) string {
|
|
|
|
previous := trimDefault
|
|
|
|
if v := trimValue.Load(); v != nil {
|
|
|
|
previous = v.(string)
|
|
|
|
}
|
|
|
|
trimValue.Store(s)
|
|
|
|
return previous
|
2018-01-28 14:56:30 +00:00
|
|
|
}
|