Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b15642

Browse files
authored
Make coder dotfiles symlinking idempotent (#7525)
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent424f954 commit0b15642

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

‎cli/dotfiles.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ func (r *RootCmd) dotfiles() *clibase.Cmd {
225225
}
226226
}
227227

228+
// attempt to delete the file before creating a new symlink. This overwrites any existing symlinks
229+
// which are typically leftover from a previous call to coder dotfiles. We do this best effort and
230+
// ignore errors because the symlink may or may not exist. Any regular files are backed up above.
231+
_=os.Remove(to)
228232
err=os.Symlink(from,to)
229233
iferr!=nil {
230234
returnxerrors.Errorf("symlinking %s to %s: %w",from,to,err)

‎cli/dotfiles_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ func TestDotfiles(t *testing.T) {
116116
b,err=os.ReadFile(filepath.Join(string(root),".bashrc.bak"))
117117
require.NoError(t,err)
118118
require.Equal(t,string(b),"backup")
119+
120+
// check for idempotency
121+
inv,_=clitest.New(t,"dotfiles","--global-config",string(root),"--symlink-dir",string(root),"-y",testRepo)
122+
err=inv.Run()
123+
require.NoError(t,err)
124+
b,err=os.ReadFile(filepath.Join(string(root),".bashrc"))
125+
require.NoError(t,err)
126+
require.Equal(t,string(b),"wow")
127+
b,err=os.ReadFile(filepath.Join(string(root),".bashrc.bak"))
128+
require.NoError(t,err)
129+
require.Equal(t,string(b),"backup")
119130
})
120131
}
121132

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp