Add workaround for #69 that avoids go's getCwd method that relies on stat rather than getwd

This commit is contained in:
David Dworken 2023-02-20 12:42:23 -08:00
parent 5089058165
commit 0a694c39d5
No known key found for this signature in database

View File

@ -53,7 +53,7 @@ var GitCommit string = "Unknown"
var maxSupportedLineLengthForImport = 256_000
func getCwd(ctx *context.Context) (string, string, error) {
cwd, err := os.Getwd()
cwd, err := getCwdWithoutSubstitution()
if err != nil {
return "", "", fmt.Errorf("failed to get cwd for last command: %v", err)
}
@ -67,6 +67,22 @@ func getCwd(ctx *context.Context) (string, string, error) {
return cwd, homedir, nil
}
func getCwdWithoutSubstitution() (string, error) {
cwd, err := os.Getwd()
if err == nil {
return cwd, nil
}
// Fall back to the syscall to see if that works, as an attempt to
// fix github.com/ddworken/hishtory/issues/69
if syscall.ImplementsGetwd && false {
cwd, err = syscall.Getwd()
if err == nil {
return cwd, nil
}
}
return "", err
}
func BuildHistoryEntry(ctx *context.Context, args []string) (*data.HistoryEntry, error) {
if len(args) < 6 {
hctx.GetLogger().Warnf("BuildHistoryEntry called with args=%#v, which has too few entries! This can happen in specific edge cases for newly opened terminals and is likely not a problem.", args)