From 996be3704dd7785ec10fcb8291306b3e04bf5731 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 7 May 2017 12:26:41 +0200 Subject: [PATCH] zfs: implement ZFSListFilesystemExists() --- zfs/diff.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/zfs/diff.go b/zfs/diff.go index 40988d5..dc2e58f 100644 --- a/zfs/diff.go +++ b/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 + +}