Skip to content

Conversation

@andreynering
Copy link
Member

  • Realistically, this should almost never fail.
  • If it does, returning "" probably makes more sense than a temp dir. Empty means Go will assume the working directory.
  • Getting rid of sync.Once is good as it locks and this can be called on every render cycle. (Used to compute ~ on the sidebar, etc).

@andreynering andreynering self-assigned this Oct 31, 2025
@andreynering andreynering requested a review from a team as a code owner October 31, 2025 19:12
return tmp
})
// Dir returns the user home directory.
func Dir() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably keep the OnceValue though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Otherwise, this is a solid one, @andreynering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caarlos0 I want to remove OnceValue because it hold a sync.Mutex inside and it locks reads.

If we want to cache it, then I think we can just compute on func init() and hold on a global unexported variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes. Take a look again.

Copy link
Member

@meowgorithm meowgorithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done. Might be worth at least logging the error but up to you.

Fwiw, here's the os.UserHomeDir definition.
https://cs.opensource.google/go/go/+/refs/tags/go1.25.3:src/os/file.go;l=608-627

* Realistically, this should almost never fail.
* If it does, returning `""` probably makes more sense than a temp dir.
  Empty means Go will assume the working directory.
* Getting rid of `sync.Once` is good as it locks and this can be called
  on every render cycle. (Used to compute `~` on the sidebar, etc).
@andreynering andreynering force-pushed the refactor-simplify-home branch from 74f63ac to 5b72be5 Compare November 3, 2025 16:43
@andreynering andreynering enabled auto-merge (squash) November 3, 2025 16:44
@andreynering andreynering merged commit c658994 into main Nov 3, 2025
17 checks passed
@andreynering andreynering deleted the refactor-simplify-home branch November 3, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants