From 8136a700fa6c3efb7a469e45d846e9db4ec9b4e2 Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Mon, 17 Jul 2017 13:16:03 -0700 Subject: [PATCH] filesystem: Distinguish support and setup for fs This commit splits two pieces of functionality. Detecting if the fscrypt metadata exists is now in CheckSetup() and checking if the filesystem supports encryption is now in CheckSupport(). --- filesystem/filesystem.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index a85d24a..b5fedf9 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -171,13 +171,15 @@ func (m *Mount) err(err error) error { return errors.Wrapf(err, "filesystem %s", m.Path) } -// CheckSetup returns an error if this filesystem does not support fscrypt or -// all the fscrypt metadata directories do not exist. Will log any unexpected -// errors or incorrect permissions. +// CheckSupport returns an error if this filesystem does not support filesystem +// encryption. +func (m *Mount) CheckSupport() error { + return m.err(metadata.CheckSupport(m.Path)) +} + +// CheckSetup returns an error if all the fscrypt metadata directories do not +// exist. Will log any unexpected errors or incorrect permissions. func (m *Mount) CheckSetup() error { - if err := metadata.CheckSupport(m.Path); err != nil { - return m.err(err) - } // Run all the checks so we will always get all the warnings baseGood := isDirCheckPerm(m.BaseDir(), basePermissions) policyGood := isDirCheckPerm(m.PolicyDir(), dirPermissions) @@ -212,13 +214,8 @@ func (m *Mount) makeDirectories() error { // the filesystem's feature flags. This operation is atomic, it either succeeds // or no files in the baseDir are created. func (m *Mount) Setup() error { - switch err := m.CheckSetup(); errors.Cause(err) { - case ErrNotSetup: - break - case nil: + if m.CheckSetup() == nil { return m.err(ErrAlreadySetup) - default: - return err } // We build the directories under a temp Mount and then move into place. temp, err := m.tempMount() -- 2.39.5