diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2022-04-01 23:38:41 +0900 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-04-02 08:48:38 +1100 |
commit | 86c259623c0f54b5eac6022cbdf232521de19ab8 (patch) | |
tree | e88a06d4f261da5f9ba8d5594e25b639a06af095 /pkg/commands | |
parent | 2fbb52fa2cc1eaed9952206b0091b9ac2ee63d8b (diff) |
feat: fix permission problem of temp dirs
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/working_tree.go | 2 | ||||
-rw-r--r-- | pkg/commands/oscommands/dummies.go | 5 | ||||
-rw-r--r-- | pkg/commands/oscommands/os.go | 10 |
3 files changed, 11 insertions, 6 deletions
diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 08e247459..d9aecf01f 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -251,7 +251,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain } func (self *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error { - filepath := filepath.Join(oscommands.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch") + filepath := filepath.Join(self.os.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch") self.Log.Infof("saving temporary patch to %s", filepath) if err := self.os.CreateFileWithContent(filepath, patch); err != nil { return err diff --git a/pkg/commands/oscommands/dummies.go b/pkg/commands/oscommands/dummies.go index 158e9a9c1..b5978e4b5 100644 --- a/pkg/commands/oscommands/dummies.go +++ b/pkg/commands/oscommands/dummies.go @@ -2,12 +2,13 @@ package oscommands import ( "github.com/jesseduffield/lazygit/pkg/common" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/utils" ) // NewDummyOSCommand creates a new dummy OSCommand for testing func NewDummyOSCommand() *OSCommand { - osCmd := NewOSCommand(utils.NewDummyCommon(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog())) + osCmd := NewOSCommand(utils.NewDummyCommon(), config.NewDummyAppConfig(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog())) return osCmd } @@ -56,7 +57,7 @@ var dummyPlatform = &Platform{ } func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand { - osCommand := NewOSCommand(utils.NewDummyCommon(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog())) + osCommand := NewOSCommand(utils.NewDummyCommon(), config.NewDummyAppConfig(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog())) osCommand.Cmd = NewDummyCmdObjBuilder(runner) return osCommand diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index a9c38e482..702aca783 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -14,6 +14,7 @@ import ( "github.com/atotto/clipboard" "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/common" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -27,6 +28,8 @@ type OSCommand struct { removeFileFn func(string) error Cmd *CmdObjBuilder + + tempDir string } // Platform stores the os state @@ -39,13 +42,14 @@ type Platform struct { } // NewOSCommand os command runner -func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCommand { +func NewOSCommand(common *common.Common, config config.AppConfigurer, platform *Platform, guiIO *guiIO) *OSCommand { c := &OSCommand{ Common: common, Platform: platform, getenvFn: os.Getenv, removeFileFn: os.RemoveAll, guiIO: guiIO, + tempDir: config.GetTempDir(), } runner := &cmdObjRunner{log: common.Log, guiIO: guiIO} @@ -236,8 +240,8 @@ func (c *OSCommand) Getenv(key string) string { return c.getenvFn(key) } -func GetTempDir() string { - return filepath.Join(os.TempDir(), "lazygit") +func (c *OSCommand) GetTempDir() string { + return c.tempDir } // GetLazygitPath returns the path of the currently executed file |