CreateFileWithContent creates a file with the given content
(path string, content string)
| 157 | |
| 158 | // CreateFileWithContent creates a file with the given content |
| 159 | func (c *OSCommand) CreateFileWithContent(path string, content string) error { |
| 160 | msg := utils.ResolvePlaceholderString( |
| 161 | c.Tr.Log.CreateFileWithContent, |
| 162 | map[string]string{ |
| 163 | "path": path, |
| 164 | }, |
| 165 | ) |
| 166 | c.LogCommand(msg, false) |
| 167 | if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { |
| 168 | c.Log.Error(err) |
| 169 | return err |
| 170 | } |
| 171 | |
| 172 | if err := os.WriteFile(path, []byte(content), 0o644); err != nil { |
| 173 | c.Log.Error(err) |
| 174 | return utils.WrapError(err) |
| 175 | } |
| 176 | |
| 177 | return nil |
| 178 | } |
| 179 | |
| 180 | // Remove removes a file or directory at the specified path |
| 181 | func (c *OSCommand) Remove(filename string) error { |
no test coverage detected