1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-26 16:03:10 +03:00

create backups of patch files in case something goes wrong

This commit is contained in:
Jesse Duffield
2019-11-05 12:42:07 +11:00
parent 733145d132
commit 0046e9c469
3 changed files with 20 additions and 7 deletions

View File

@@ -262,6 +262,21 @@ func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
return tmpfile.Name(), nil
}
// CreateFileWithContent creates a file with the given content
func (c *OSCommand) CreateFileWithContent(path string, content string) error {
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
c.Log.Error(err)
return err
}
if err := ioutil.WriteFile(path, []byte(content), 0644); err != nil {
c.Log.Error(err)
return WrapError(err)
}
return nil
}
// Remove removes a file or directory at the specified path
func (c *OSCommand) Remove(filename string) error {
err := os.RemoveAll(filename)