Skip to content

Commit

Permalink
feat: Add tempDir configuration variable
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jul 1, 2024
1 parent 4241393 commit 2808e7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ sections:
`$HOME/.local/share/chezmoi` <br/>
`%USERPROFILE%/.local/share/chezmoi`
description: Source directory
tempDir:
default: '*from system*'
description: Temporary directory
umask:
type: int
default: '*from system*'
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down
6 changes: 2 additions & 4 deletions internal/cmd/editcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2808e7c

Please sign in to comment.