From 77b226a90ef70b77ca556830528c013a23b01e57 Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Wed, 21 Jun 2017 09:52:40 -0700 Subject: Change error handling to new package This commit changes the error handing for the crypto, filesystem, metadata, pam, and util packages to use the error handling library github.com/pkg/errors. This means elimination of the FSError type, an increased use of wrapping errors (as opposed to logging), switching on the Cause() of an error (as opposed to its value), and improving our integration tests involving TEST_FILESYSTEM_ROOT. This commit also fixes a few bugs with the keyring code to ensure that our {Find|Remove|Insert}PolicyKey functions are always operating on the same keyring. The check for filesystem support has been moved from the filesystem package to the metadata package. Finally, the API for the filesystem package has been slightly modified: * filesystem.AllFilesystems() now returns all the filesystems in sorted order * certain path methods are now public O_SYNC is also removed for writing the metadata. We don't get that much from syncing the metadata, as the actual file data could also be corrupted by and IO error. The sync operation is also occasionally very slow (~3 seconds) and can be unfriendly to battery life. Change-Id: I392c2655141714b16dfdbc84ac09780072be2cf0 --- metadata/policy_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'metadata/policy_test.go') diff --git a/metadata/policy_test.go b/metadata/policy_test.go index 6dc2567..58e19d7 100644 --- a/metadata/policy_test.go +++ b/metadata/policy_test.go @@ -25,6 +25,8 @@ import ( "path/filepath" "reflect" "testing" + + . "fscrypt/util" ) const goodDescriptor = "0123456789abcdef" @@ -34,13 +36,14 @@ var goodPolicy = &PolicyData{ Options: DefaultOptions, } -// Creates a temporary directory in TEST_FILESYSTEM_ROOT for testing. Fails if -// the root directory is not specified. +// Creates a temporary directory for testing. func createTestDirectory() (directory string, err error) { - baseDirectory := os.Getenv("TEST_FILESYSTEM_ROOT") + baseDirectory, err := TestPath() + if err != nil { + return + } if s, err := os.Stat(baseDirectory); err != nil || !s.IsDir() { - return "", fmt.Errorf("invalid directory %q: "+ - "set TEST_FILESYSTEM_ROOT to be a valid directory", baseDirectory) + return "", fmt.Errorf("%s: %q is not a valid directory", TestEnvVarName, baseDirectory) } directoryPath := filepath.Join(baseDirectory, "test") -- cgit v1.2.3