2017-10-27 00:26:04 +00:00
|
|
|
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
|
|
|
|
}
|
2017-10-30 18:31:31 +00:00
|
|
|
defer f.Close()
|
2017-10-27 00:26:04 +00:00
|
|
|
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
|
|
|
|
}
|