(containerPath, source, flags string)
| 993 | } |
| 994 | |
| 995 | func mountBind(containerPath, source, flags string) error { |
| 996 | fi, err := os.Stat(source) |
| 997 | if err != nil { |
| 998 | if os.IsNotExist(err) { |
| 999 | return nil |
| 1000 | } |
| 1001 | |
| 1002 | return fmt.Errorf("failed to stat %s", source) |
| 1003 | } |
| 1004 | |
| 1005 | fileMode := fi.Mode() |
| 1006 | |
| 1007 | if fileMode.IsDir() { |
| 1008 | logrus.Debugf("Creating directory %s", containerPath) |
| 1009 | if err := os.MkdirAll(containerPath, 0755); err != nil { |
| 1010 | return fmt.Errorf("failed to create directory %s: %w", containerPath, err) |
| 1011 | } |
| 1012 | } else if fileMode.IsRegular() || fileMode&os.ModeSocket != 0 { |
| 1013 | logrus.Debugf("Creating regular file %s", containerPath) |
| 1014 | |
| 1015 | containerPathDir := filepath.Dir(containerPath) |
| 1016 | if err := os.MkdirAll(containerPathDir, 0755); err != nil { |
| 1017 | return fmt.Errorf("failed to create directory %s: %w", containerPathDir, err) |
| 1018 | } |
| 1019 | |
| 1020 | containerPathFile, err := os.Create(containerPath) |
| 1021 | if err != nil && !os.IsExist(err) { |
| 1022 | return fmt.Errorf("failed to create regular file %s: %w", containerPath, err) |
| 1023 | } |
| 1024 | |
| 1025 | defer containerPathFile.Close() |
| 1026 | } |
| 1027 | |
| 1028 | logrus.Debugf("Binding %s to %s", containerPath, source) |
| 1029 | |
| 1030 | args := []string{ |
| 1031 | "--rbind", |
| 1032 | } |
| 1033 | |
| 1034 | if flags != "" { |
| 1035 | args = append(args, []string{"-o", flags}...) |
| 1036 | } |
| 1037 | |
| 1038 | args = append(args, []string{source, containerPath}...) |
| 1039 | |
| 1040 | if err := shell.Run("mount", nil, nil, nil, args...); err != nil { |
| 1041 | return fmt.Errorf("failed to bind %s to %s", containerPath, source) |
| 1042 | } |
| 1043 | |
| 1044 | return nil |
| 1045 | } |
| 1046 | |
| 1047 | // redirectPath serves for creating symbolic links for crucial system |
| 1048 | // configuration files to their counterparts on the host's file system. |
no outgoing calls
no test coverage detected
searching dependent graphs…