Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
52a3cdb8
Unverified
Commit
52a3cdb8
authored
Oct 17, 2019
by
Matthew Fisher
Committed by
GitHub
Oct 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6694 from bacongobbler/fix-6682-helm2
fix(cmd): acquire file lock on repository.lock
parents
07c17133
0a2d5845
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
repo_add.go
cmd/helm/repo_add.go
+8
-4
No files found.
cmd/helm/repo_add.go
View file @
52a3cdb8
...
@@ -20,6 +20,8 @@ import (
...
@@ -20,6 +20,8 @@ import (
"context"
"context"
"fmt"
"fmt"
"io"
"io"
"path/filepath"
"strings"
"syscall"
"syscall"
"time"
"time"
...
@@ -135,8 +137,10 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
...
@@ -135,8 +137,10 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
return
fmt
.
Errorf
(
"Looks like %q is not a valid chart repository or cannot be reached: %s"
,
url
,
err
.
Error
())
return
fmt
.
Errorf
(
"Looks like %q is not a valid chart repository or cannot be reached: %s"
,
url
,
err
.
Error
())
}
}
// Lock the repository file for concurrent goroutines or processes synchronization
repoFile
:=
home
.
RepositoryFile
()
fileLock
:=
flock
.
New
(
home
.
RepositoryFile
())
// Acquire a file lock for process synchronization
fileLock
:=
flock
.
New
(
strings
.
Replace
(
repoFile
,
filepath
.
Ext
(
repoFile
),
".lock"
,
1
))
lockCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
30
*
time
.
Second
)
lockCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
30
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
locked
,
err
:=
fileLock
.
TryLockContext
(
lockCtx
,
time
.
Second
)
locked
,
err
:=
fileLock
.
TryLockContext
(
lockCtx
,
time
.
Second
)
...
@@ -149,12 +153,12 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
...
@@ -149,12 +153,12 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
// Re-read the repositories file before updating it as its content may have been changed
// Re-read the repositories file before updating it as its content may have been changed
// by a concurrent execution after the first read and before being locked
// by a concurrent execution after the first read and before being locked
f
,
err
=
repo
.
LoadRepositoriesFile
(
home
.
RepositoryFile
()
)
f
,
err
=
repo
.
LoadRepositoriesFile
(
repoFile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
f
.
Update
(
&
c
)
f
.
Update
(
&
c
)
return
f
.
WriteFile
(
home
.
RepositoryFile
()
,
0644
)
return
f
.
WriteFile
(
repoFile
,
0644
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment