mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 00:13:52 +01:00
zfs: implement ZFSListFilesystemExists()
This commit is contained in:
parent
6a420e872e
commit
996be3704d
21
zfs/diff.go
21
zfs/diff.go
@ -241,3 +241,24 @@ outer:
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// A somewhat efficient way to determine if a filesystem exists on this host.
|
||||
// Particularly useful if exists is called more than once (will only fork exec once and cache the result)
|
||||
func ZFSListFilesystemExists() (exists func(p DatasetPath) bool, err error) {
|
||||
|
||||
var actual [][]string
|
||||
if actual, err = ZFSList([]string{"name"}, "-t", "filesystem,volume"); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
filesystems := make(map[string]bool, len(actual))
|
||||
for _, e := range actual {
|
||||
filesystems[e[0]] = true
|
||||
}
|
||||
|
||||
exists = func(p DatasetPath) bool {
|
||||
return filesystems[p.ToString()]
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user