Handle already-existing files correctly

This commit is contained in:
Alex D. 2024-09-10 14:21:03 +00:00
parent 0d38256c5d
commit decceb85d4
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
1 changed files with 4 additions and 4 deletions

8
s6.go
View File

@ -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 {