MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / commentSSHConfigLines

Function commentSSHConfigLines

agent/app/service/ssh.go:1107–1128  ·  view source on GitHub ↗
(fileName string, targetLines []int)

Source from the content-addressed store, hash-verified

1105}
1106
1107func commentSSHConfigLines(fileName string, targetLines []int) error {
1108 content, err := os.ReadFile(fileName)
1109 if err != nil {
1110 return err
1111 }
1112 lines := strings.Split(string(content), "\n")
1113 targetSet := make(map[int]struct{}, len(targetLines))
1114 for _, line := range targetLines {
1115 targetSet[line] = struct{}{}
1116 }
1117 for index := range lines {
1118 if _, ok := targetSet[index]; !ok {
1119 continue
1120 }
1121 trimmed := strings.TrimSpace(lines[index])
1122 if trimmed == "" || strings.HasPrefix(trimmed, "#") {
1123 continue
1124 }
1125 lines[index] = "#" + lines[index]
1126 }
1127 return os.WriteFile(fileName, []byte(strings.Join(lines, "\n")), constant.FilePerm)
1128}
1129
1130func loadSSHInsertIndex(lines []string) int {
1131 for index, line := range lines {

Callers 2

Calls 1

WriteFileMethod · 0.80

Tested by

no test coverage detected