From a58e6d37ae8469ba651ab4b86b8cb4306d180738 Mon Sep 17 00:00:00 2001 From: zyx Date: Mon, 25 Mar 2019 23:40:04 +0800 Subject: [PATCH] change owner of folder to current user after creating zfs dataset (close #89) --- worker/zfs_hook.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/worker/zfs_hook.go b/worker/zfs_hook.go index 7e8f25e..785adef 100644 --- a/worker/zfs_hook.go +++ b/worker/zfs_hook.go @@ -3,6 +3,7 @@ package worker import ( "fmt" "os" + "os/user" "strings" "github.com/codeskyblue/go-sh" @@ -40,6 +41,14 @@ func (z *zfsHook) preJob() error { if err := sh.Command("sudo", "zfs", "set", "mountpoint="+workingDir, zfsDataset).Run(); err != nil { return err } + usr, err := user.Current() + if err != nil { + return err + } + logger.Infof("Chown %s to %s(%s)", workingDir, usr.Uid, usr.Username) + if err := sh.Command("sudo", "chown", usr.Uid, workingDir).Run(); err != nil { + return err + } } return nil }