cri-o/libpod/util.go
baude c6cc205b78 Reviewer comments and suggestions incorporated.
Signed-off-by: baude <bbaude@redhat.com>
2017-10-31 14:10:47 -05:00

34 lines
601 B
Go

package libpod
import (
"os"
"path/filepath"
)
// WriteFile writes a provided string to a provided path
func WriteFile(content string, path string) error {
baseDir := filepath.Dir(path)
if baseDir != "" {
if _, err := os.Stat(path); err != nil {
return err
}
}
f, err := os.Create(path)
if err != nil {
return err
}
defer f.Close()
f.WriteString(content)
f.Sync()
return nil
}
// StringInSlice determines if a string is in a string slice, returns bool
func StringInSlice(s string, sl []string) bool {
for _, i := range sl {
if i == s {
return true
}
}
return false
}