forked from apptainer/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainthread.go
48 lines (41 loc) · 1.12 KB
/
mainthread.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2018, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package mainthread
import (
"os"
"path/filepath"
)
// FuncChannel passes functions executed in main thread
var FuncChannel = make(chan func())
// Execute allows to execute a function in the main thread
func Execute(f func()) {
done := make(chan bool)
FuncChannel <- func() {
f()
done <- true
}
<-done
}
// Stat retrieves file stat information from main thread
func Stat(name string) (fi os.FileInfo, err error) {
Execute(func() {
fi, err = os.Stat(name)
})
return
}
// Readlink returns the destination of link name from main thread
func Readlink(name string) (dest string, err error) {
Execute(func() {
dest, err = os.Readlink(name)
})
return
}
// EvalSymlinks returns the evaluated path after link resolution from main thread
func EvalSymlinks(path string) (rpath string, err error) {
Execute(func() {
rpath, err = filepath.EvalSymlinks(path)
})
return
}