MCPcopy
hub / github.com/containers/toolbox / sanitizeRedirectionTarget

Function sanitizeRedirectionTarget

src/cmd/initContainer.go:1119–1165  ·  view source on GitHub ↗
(target string)

Source from the content-addressed store, hash-verified

1117}
1118
1119func sanitizeRedirectionTarget(target string) string {
1120 if !filepath.IsAbs(target) {
1121 panic("target must be an absolute path")
1122 }
1123
1124 fileInfo, err := os.Lstat(target)
1125 if err != nil {
1126 if os.IsNotExist(err) {
1127 logrus.Warnf("%s not found", target)
1128 } else {
1129 logrus.Warnf("Failed to lstat %s: %v", target, err)
1130 }
1131
1132 return target
1133 }
1134
1135 fileMode := fileInfo.Mode()
1136 if fileMode&os.ModeSymlink == 0 {
1137 logrus.Debugf("%s isn't a symbolic link", target)
1138 return target
1139 }
1140
1141 logrus.Debugf("%s is a symbolic link", target)
1142
1143 _, err = filepath.EvalSymlinks(target)
1144 if err == nil {
1145 return target
1146 }
1147
1148 logrus.Warnf("Failed to resolve %s: %v", target, err)
1149
1150 targetDestination, err := os.Readlink(target)
1151 if err != nil {
1152 logrus.Warnf("Failed to get the destination of %s: %v", target, err)
1153 return target
1154 }
1155
1156 logrus.Debugf("%s points to %s", target, targetDestination)
1157
1158 if filepath.IsAbs(targetDestination) {
1159 logrus.Debugf("Prepending /run/host to %s", targetDestination)
1160 targetGuess := filepath.Join("/run/host", targetDestination)
1161 return targetGuess
1162 }
1163
1164 return target
1165}
1166
1167func extractTimeZoneFromLocalTimeSymLink(path string) (string, error) {
1168 zoneInfoRoots := []string{

Callers 1

redirectPathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…