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

Function redirectPath

src/cmd/initContainer.go:1075–1111  ·  view source on GitHub ↗

redirectPath serves for creating symbolic links for crucial system configuration files to their counterparts on the host's file system. containerPath and target must be absolute paths If the target itself is a symbolic link, redirectPath will evaluate the link. If it's valid then redirectPath will

(containerPath, target string, folder bool)

Source from the content-addressed store, hash-verified

1073//
1074// folder signifies if the target is a folder
1075func redirectPath(containerPath, target string, folder bool) error {
1076 if !filepath.IsAbs(containerPath) {
1077 panic("containerPath must be an absolute path")
1078 }
1079
1080 if !filepath.IsAbs(target) {
1081 panic("target must be an absolute path")
1082 }
1083
1084 logrus.Debugf("Preparing to redirect %s to %s", containerPath, target)
1085 targetSanitized := sanitizeRedirectionTarget(target)
1086
1087 if err := os.Remove(containerPath); err != nil {
1088 if errors.Is(err, syscall.EBUSY) {
1089 return fmt.Errorf("failed to redirect %s to %s: %s is a mount point",
1090 containerPath,
1091 target,
1092 containerPath)
1093 } else if !errors.Is(err, os.ErrNotExist) {
1094 return fmt.Errorf("failed to redirect %s to %s: %w", containerPath, target, err)
1095 }
1096 }
1097
1098 if folder {
1099 if err := os.MkdirAll(target, 0755); err != nil {
1100 return fmt.Errorf("failed to redirect %s to %s: %w", containerPath, target, err)
1101 }
1102 }
1103
1104 logrus.Debugf("Redirecting %s to %s", containerPath, targetSanitized)
1105
1106 if err := os.Symlink(targetSanitized, containerPath); err != nil {
1107 return fmt.Errorf("failed to redirect %s to %s: %w", containerPath, target, err)
1108 }
1109
1110 return nil
1111}
1112
1113func runUpdateDb() {
1114 if err := shell.Run("updatedb", nil, nil, nil); err != nil {

Callers 2

initContainerFunction · 0.85
configureUsersFunction · 0.85

Calls 2

IsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…