-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better handling of windows paths (#646)
Issue #, if available: *Description of changes:* - Handle edge cases when dealing with Windows paths *Testing done:* - Tested on my Windows host - [x] I've reviewed the guidance in CONTRIBUTING.md #### License Acceptance By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: Justin Alvarez <[email protected]>
- Loading branch information
Showing
4 changed files
with
45 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package path | ||
|
||
// FinchRootDir returns the path to the Finch root directory, which is $HOME on UNIX. | ||
func (Finch) FinchRootDir(ffd FinchFinderDeps) (string, error) { | ||
home, err := ffd.GetUserHome() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return home, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build windows | ||
// +build windows | ||
|
||
package path | ||
|
||
import ( | ||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
// FinchRootDir returns the path to the Finch root directory, which is %LOCALAPPDATA% on Windows. | ||
// It also canonicalizes any environment variables that may be unexpanded in the path so that all | ||
// paths based on it can be passed safely to other programs which may execute outside of the user's context. | ||
func (Finch) FinchRootDir(ffd FinchFinderDeps) (string, error) { | ||
appDir := ffd.Env("LOCALAPPDATA") | ||
expandedPath, err := registry.ExpandString(appDir) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return expandedPath, nil | ||
} |