From decceb85d4fa49c1d1bf0f9e95f68c0c4a4d31ed Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Tue, 10 Sep 2024 14:21:03 +0000 Subject: [PATCH] Handle already-existing files correctly --- s6.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/s6.go b/s6.go index 3a3e390..2544efd 100644 --- a/s6.go +++ b/s6.go @@ -108,7 +108,7 @@ func (t *S6SvcTree) S6CommitService(s *S6Svc) (err error) { } sdir := filepath.Join(t.rcdir, string(s.Name)) - if err = os.Mkdir(sdir, fs.ModeDir|0777); err != nil { + if err = os.Mkdir(sdir, fs.ModeDir|0777); err != nil && !errors.Is(err, os.ErrExist) { return } @@ -148,7 +148,7 @@ func (t *S6SvcTree) S6CommitService(s *S6Svc) (err error) { for _, v := range kvfiles { var f *os.File - if f, err = os.OpenFile(filepath.Join(sdir, v.name), os.O_CREATE|os.O_RDWR, fs.FileMode(v.perm)); err != nil && !errors.Is(err, os.ErrExist) { + if f, err = os.OpenFile(filepath.Join(sdir, v.name), os.O_CREATE|os.O_RDWR, fs.FileMode(v.perm)); err != nil { return } _, err = fmt.Fprintln(f, v.value) @@ -167,7 +167,7 @@ func (t *S6SvcTree) S6CommitService(s *S6Svc) (err error) { dirname = "dependencies.d" } cdir := filepath.Join(sdir, dirname) - if err = os.Mkdir(cdir, fs.ModeDir|0777); err != nil { + if err = os.Mkdir(cdir, fs.ModeDir|0777); err != nil && !errors.Is(err, os.ErrExist) { return } @@ -184,7 +184,7 @@ func (t *S6SvcTree) S6CommitService(s *S6Svc) (err error) { return } sdir := filepath.Join(t.envdir, string(s.Name)) - if err = os.Mkdir(sdir, fs.ModeDir|0777); err != nil { + if err = os.Mkdir(sdir, fs.ModeDir|0777); err != nil && !errors.Is(err, os.ErrExist) { return } for k, v := range s.env {