summaryrefslogtreecommitdiff
path: root/libpod/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/util.go')
-rw-r--r--libpod/util.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go
index 0c6700fbf..ca93fc097 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -107,3 +107,32 @@ func MountExists(specMounts []spec.Mount, dest string) bool {
}
return false
}
+
+// WaitForFile waits until a file has been created or the given timeout has occurred
+func WaitForFile(path string, timeout time.Duration) error {
+ done := make(chan struct{})
+ chControl := make(chan struct{})
+ go func() {
+ for {
+ select {
+ case <-chControl:
+ return
+ default:
+ _, err := os.Stat(path)
+ if err == nil {
+ close(done)
+ return
+ }
+ time.Sleep(25 * time.Millisecond)
+ }
+ }
+ }()
+
+ select {
+ case <-done:
+ return nil
+ case <-time.After(timeout):
+ close(chControl)
+ return errors.Wrapf(ErrInternal, "timed out waiting for file %s", path)
+ }
+}