From 0e5c2e1cff7cfe5dcaf893f9c8fa838c3cf22b8a Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Tue, 5 Nov 2019 17:19:56 +0100 Subject: [PATCH] improve dataset detection by only including mounted datasets --- findoid | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/findoid b/findoid index 48301a4..67b5de6 100755 --- a/findoid +++ b/findoid @@ -102,14 +102,19 @@ sub getdataset { my ($path) = @_; - open FH, "$zfs list -Ho mountpoint |"; + open FH, "$zfs list -H -t filesystem -o mountpoint,mounted |"; my @datasets = ; close FH; my @matchingdatasets; foreach my $dataset (@datasets) { chomp $dataset; - if ( $path =~ /^$dataset/ ) { push @matchingdatasets, $dataset; } + my ($mountpoint, $mounted) = ($dataset =~ m/([^\t]*)\t*(.*)/); + if ($mounted ne "yes") { + next; + } + + if ( $path =~ /^$mountpoint/ ) { push @matchingdatasets, $mountpoint; } } my $bestmatch = '';