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)
| 1073 | // |
| 1074 | // folder signifies if the target is a folder |
| 1075 | func 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 | |
| 1113 | func runUpdateDb() { |
| 1114 | if err := shell.Run("updatedb", nil, nil, nil); err != nil { |
no test coverage detected
searching dependent graphs…