-
Notifications
You must be signed in to change notification settings - Fork 2k
Proposal for incremental path refactor #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f0fca35
Start path refactor
4028236
Top level cwd is now an absolute path
gsoltis fa61d76
Merge branch 'main' into gsoltis/path_first_pass
108b55a
Merge branch 'main' into gsoltis/path_first_pass
2bc1286
Merge branch 'main' into gsoltis/path_first_pass
255b961
Merge branch 'main' into gsoltis/path_first_pass
2f10d01
Merge branch 'main' into gsoltis/path_first_pass
69dd954
Merge branch 'main' into gsoltis/path_first_pass
39e6168
Merge branch 'main' into gsoltis/path_first_pass
f8ea589
Merge branch 'main' into gsoltis/path_first_pass
21ea3e4
Merge branch 'main' into gsoltis/path_first_pass
7dde7fd
Merge branch 'main' into gsoltis/path_first_pass
7acd665
Merge branch 'main' into gsoltis/path_first_pass
1c7e736
Merge in main
32334d0
Merge branch 'main' into gsoltis/path_first_pass
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
package fs | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// AbsolutePath represents a platform-dependent absolute path on the filesystem, | ||
// and is used to enfore correct path manipulation | ||
type AbsolutePath string | ||
|
||
func CheckedToAbsolutePath(s string) (AbsolutePath, error) { | ||
if filepath.IsAbs(s) { | ||
return AbsolutePath(s), nil | ||
} | ||
return "", fmt.Errorf("%v is not an absolute path", s) | ||
} | ||
|
||
func UnsafeToAbsolutePath(s string) AbsolutePath { | ||
return AbsolutePath(s) | ||
} | ||
|
||
func GetCwd() (AbsolutePath, error) { | ||
cwdRaw, err := os.Getwd() | ||
if err != nil { | ||
return "", fmt.Errorf("invalid working directory: %w", err) | ||
} | ||
cwd, err := CheckedToAbsolutePath(cwdRaw) | ||
if err != nil { | ||
return "", fmt.Errorf("cwd is not an absolute path %v: %v", cwdRaw, err) | ||
} | ||
return cwd, nil | ||
} | ||
|
||
func (ap AbsolutePath) ToStringDuringMigration() string { | ||
return ap.asString() | ||
} | ||
|
||
func (ap AbsolutePath) Join(args ...string) AbsolutePath { | ||
return AbsolutePath(filepath.Join(ap.asString(), filepath.Join(args...))) | ||
} | ||
func (ap AbsolutePath) asString() string { | ||
return string(ap) | ||
} | ||
func (ap AbsolutePath) Dir() AbsolutePath { | ||
return AbsolutePath(filepath.Dir(ap.asString())) | ||
} | ||
func (ap AbsolutePath) MkdirAll() error { | ||
return os.MkdirAll(ap.asString(), DirPermissions) | ||
} | ||
func (ap AbsolutePath) Remove() error { | ||
return os.Remove(ap.asString()) | ||
} | ||
func (ap AbsolutePath) Open() (*os.File, error) { | ||
return os.Open(ap.asString()) | ||
} | ||
func (ap AbsolutePath) ReadFile() ([]byte, error) { | ||
return ioutil.ReadFile(ap.asString()) | ||
} | ||
func (ap AbsolutePath) FileExists() bool { | ||
return FileExists(ap.asString()) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call this
SafeAbsolutePath
?