Skip to content

Commit

Permalink
Use c/storage/pkg/ioutils.AtomicWriteFiles to update auth.json
Browse files Browse the repository at this point in the history
... so that users can't observe an intermediate empty, or partial, file.

(Note that there is still no locking, so two simultaneous updates to
auth.json might lose some updates.)

Fixes at least the worst impact of containers#1365 .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Apr 4, 2022
1 parent dc7fe92 commit b12b8a2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/docker/config/config.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/image/v5/types"
"github.com/containers/storage/pkg/homedir"
"github.com/containers/storage/pkg/ioutils"
helperclient "github.com/docker/docker-credential-helpers/client"
"github.com/docker/docker-credential-helpers/credentials"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -605,7 +606,7 @@ func modifyJSON(sys *types.SystemContext, editor func(auths *dockerConfigFile) (
return "", errors.Wrapf(err, "marshaling JSON %q", path)
}

if err = ioutil.WriteFile(path, newData, 0600); err != nil {
if err = ioutils.AtomicWriteFile(path, newData, 0600); err != nil {
return "", errors.Wrapf(err, "writing to file %q", path)
}
}
Expand Down

0 comments on commit b12b8a2

Please sign in to comment.