Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add tempDir configuration variable #3847

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading