From 2808e7cf7bf91a5db8a4d3bf541950a034ef445f Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 2 Jul 2024 00:18:41 +0200 Subject: [PATCH] feat: Add tempDir configuration variable --- .../docs/reference/configuration-file/variables.md.yaml | 3 +++ internal/cmd/config.go | 6 ++++-- internal/cmd/editcmd.go | 6 ++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml b/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml index 71d4f1ae560..5c051fca792 100644 --- a/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml +++ b/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml @@ -51,6 +51,9 @@ sections: `$HOME/.local/share/chezmoi`
`%USERPROFILE%/.local/share/chezmoi` description: Source directory + tempDir: + default: '*from system*' + description: Temporary directory umask: type: int default: '*from system*' diff --git a/internal/cmd/config.go b/internal/cmd/config.go index f39a6a03cbb..b2890bb510d 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -115,6 +115,7 @@ type ConfigFile struct { ScriptEnv map[string]string `json:"scriptEnv" mapstructure:"scriptEnv" yaml:"scriptEnv"` ScriptTempDir chezmoi.AbsPath `json:"scriptTempDir" mapstructure:"scriptTempDir" yaml:"scriptTempDir"` SourceDirAbsPath chezmoi.AbsPath `json:"sourceDir" mapstructure:"sourceDir" yaml:"sourceDir"` + TempDir chezmoi.AbsPath `json:"tempDir" mapstructure:"tempDir" yaml:"tempDir"` Template templateConfig `json:"template" mapstructure:"template" yaml:"template"` TextConv textConv `json:"textConv" mapstructure:"textConv" yaml:"textConv"` Umask fs.FileMode `json:"umask" mapstructure:"umask" yaml:"umask"` @@ -2631,7 +2632,7 @@ func (c *Config) tempDir(key string) (chezmoi.AbsPath, error) { if tempDirAbsPath, ok := c.tempDirs[key]; ok { return tempDirAbsPath, nil } - tempDir, err := os.MkdirTemp("", key) + tempDir, err := os.MkdirTemp(c.TempDir.String(), key) chezmoilog.InfoOrError(c.logger, "MkdirTemp", err, slog.String("tempDir", tempDir)) if err != nil { return chezmoi.EmptyAbsPath, err @@ -2709,7 +2710,8 @@ func newConfigFile(bds *xdg.BaseDirectorySpecification) ConfigFile { PINEntry: pinEntryConfig{ Options: pinEntryDefaultOptions, }, - Safe: true, + Safe: true, + TempDir: chezmoi.NewAbsPath(os.TempDir()), Template: templateConfig{ Options: chezmoi.DefaultTemplateOptions, }, diff --git a/internal/cmd/editcmd.go b/internal/cmd/editcmd.go index ebc3fdec33d..336fecb9901 100644 --- a/internal/cmd/editcmd.go +++ b/internal/cmd/editcmd.go @@ -144,10 +144,8 @@ TARGET_REL_PATH: // Attempt to create the hard link. If this succeeds, continue to // the next target. Hardlinking will fail if the temporary directory // is on a different filesystem to the source directory, which is - // not the case for most users. - // - // FIXME create a temporary directory on the same filesystem as the - // source directory if needed. + // not the case for most users. The user can set the tempDir + // configuration variable if needed. if err := os.MkdirAll(hardlinkAbsPath.Dir().String(), 0o700); err != nil { return err }