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 --- filesystem/path.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'filesystem/path.go') diff --git a/filesystem/path.go b/filesystem/path.go index 3be1859..d788a6b 100644 --- a/filesystem/path.go +++ b/filesystem/path.go @@ -23,6 +23,8 @@ import ( "log" "os" "path/filepath" + + "github.com/pkg/errors" ) // We only check the unix permissions and the sticky bit @@ -34,8 +36,14 @@ func cannonicalizePath(path string) (string, error) { if err != nil { return "", err } + path, err = filepath.EvalSymlinks(path) + + // Get a better error if we have an invalid path + if pathErr, ok := err.(*os.PathError); ok { + err = errors.Wrap(pathErr.Err, pathErr.Path) + } - return filepath.EvalSymlinks(path) + return path, err } // loggedStat runs os.Stat, but it logs the error if stat returns any error -- cgit v1.2.3