diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-10-23 14:45:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-23 14:45:33 -0700 |
commit | 37e9e5667e2ed6b790d5d8271509ef93d2935083 (patch) | |
tree | a4d1d7bad134c2fa77a30ea2ee019f460a4745b2 /libpod/util.go | |
parent | 28279ce6bda0e5a5acd06b98f7d8f52c8fc8a393 (diff) | |
parent | dfc689efc9a5746b0c31147562c5051c45874002 (diff) | |
download | podman-37e9e5667e2ed6b790d5d8271509ef93d2935083.tar.gz podman-37e9e5667e2ed6b790d5d8271509ef93d2935083.tar.bz2 podman-37e9e5667e2ed6b790d5d8271509ef93d2935083.zip |
Merge pull request #1706 from giuseppe/fix-cidfile-rootless
create: fix writing cidfile when using rootless
Diffstat (limited to 'libpod/util.go')
-rw-r--r-- | libpod/util.go | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/libpod/util.go b/libpod/util.go index 3b51e4fcc..7007b29cd 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -24,22 +24,15 @@ const ( DefaultTransport = "docker://" ) -// WriteFile writes a provided string to a provided path -func WriteFile(content string, path string) error { +// OpenExclusiveFile opens a file for writing and ensure it doesn't already exist +func OpenExclusiveFile(path string) (*os.File, error) { baseDir := filepath.Dir(path) if baseDir != "" { if _, err := os.Stat(baseDir); err != nil { - return err + return nil, err } } - f, err := os.Create(path) - if err != nil { - return err - } - defer f.Close() - f.WriteString(content) - f.Sync() - return nil + return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) } // FuncTimer helps measure the execution time of a function |