summaryrefslogtreecommitdiffstats
path: root/pkg/commands/os.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-05 12:42:07 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-05 19:22:01 +1100
commit0046e9c469a86c22a98a6671c6d4802c4f8e74c5 (patch)
treed108f2dd87626a3400b6348a5e9781c725fca0c9 /pkg/commands/os.go
parent733145d13271affa666790ac394a43f43d698850 (diff)
create backups of patch files in case something goes wrong
Diffstat (limited to 'pkg/commands/os.go')
-rw-r--r--pkg/commands/os.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index c61404c41..df1b56efd 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -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)