MCPcopy Index your code
hub / github.com/devspace-sh/devspace / appendToIgnoreFile

Function appendToIgnoreFile

cmd/init.go:843–868  ·  view source on GitHub ↗
(ignoreFile, content string)

Source from the content-addressed store, hash-verified

841}
842
843func appendToIgnoreFile(ignoreFile, content string) error {
844 // Check if ignoreFile exists
845 _, err := os.Stat(ignoreFile)
846 if os.IsNotExist(err) {
847 _ = fsutil.WriteToFile([]byte(content), ignoreFile)
848 } else {
849 fileContent, err := os.ReadFile(ignoreFile)
850 if err != nil {
851 return errors.Errorf("Error reading file %s: %v", ignoreFile, err)
852 }
853
854 // append only if not found in file content
855 if !strings.Contains(string(fileContent), content) {
856 file, err := os.OpenFile(ignoreFile, os.O_APPEND|os.O_WRONLY, 0600)
857 if err != nil {
858 return errors.Errorf("Error writing file %s: %v", ignoreFile, err)
859 }
860
861 defer file.Close()
862 if _, err = file.WriteString(content); err != nil {
863 return errors.Errorf("Error writing file %s: %v", ignoreFile, err)
864 }
865 }
866 }
867 return nil
868}
869
870func getProjectName() (string, string, error) {
871 projectName := ""

Callers 2

initDevspaceMethod · 0.85
initDockerComposeMethod · 0.85

Calls 4

WriteToFileFunction · 0.92
CloseMethod · 0.65
WriteStringMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected