Skip to content

Commit

Permalink
fix(vfox curTmpPath): reuse temporary directories across days
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-bar committed Jun 25, 2024
1 parent d3d731c commit ca9f722
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/commands/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func activateCmd(ctx *cli.Context) error {
osPaths := env.NewPaths(env.OsPaths)
pathsStr := envKeys.Paths.Merge(osPaths).String()
exportEnvs["PATH"] = &pathsStr
exportEnvs[internal.HookCurTmpPath] = &manager.PathMeta.CurTmpPath

path := manager.PathMeta.ExecutablePath
path = strings.Replace(path, "\\", "/", -1)
Expand Down
15 changes: 11 additions & 4 deletions internal/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type PathMeta struct {
GlobalShimsPath string
}

const (
HookCurTmpPath = "__VFOX_CURTMPPATH"
)

func newPathMeta() (*PathMeta, error) {
userHomeDir, err := os.UserHomeDir()
if err != nil {
Expand All @@ -53,10 +57,13 @@ func newPathMeta() (*PathMeta, error) {
if err != nil {
return nil, err
}
pid := env.GetPid()
timestamp := util.GetBeginOfToday()
name := fmt.Sprintf("%d-%d", timestamp, pid)
curTmpPath := filepath.Join(tmpPath, name)
curTmpPath := os.Getenv(HookCurTmpPath)
if curTmpPath == "" {
pid := env.GetPid()
timestamp := util.GetBeginOfToday()
name := fmt.Sprintf("%d-%d", timestamp, pid)
curTmpPath = filepath.Join(tmpPath, name)
}
if !util.FileExists(curTmpPath) {
err = os.Mkdir(curTmpPath, 0755)
if err != nil {
Expand Down

0 comments on commit ca9f722

Please sign in to comment.