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
595afc5c
Commit
595afc5c
authored
May 17, 2017
by
Adam Reese
Committed by
GitHub
May 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2449 from rvbaz/write-index-atomic
Write repo file using atomicfile
parents
dd7357df
965cb7fd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
2 deletions
+25
-2
glide.lock
glide.lock
+2
-0
glide.yaml
glide.yaml
+1
-0
repo.go
pkg/repo/repo.go
+13
-1
repo_test.go
pkg/repo/repo_test.go
+9
-1
No files found.
glide.lock
View file @
595afc5c
...
...
@@ -102,6 +102,8 @@ imports:
version: ba18e35c5c1b36ef6334cad706eb681153d2d379
- name: github.com/exponent-io/jsonpath
version: d6023ce2651d8eafb5c75bb0c7167536102ec9f5
- name: github.com/facebookgo/atomicfile
version: 2de1f203e7d5e386a6833233882782932729f27e
- name: github.com/facebookgo/symwalk
version: 42004b9f322246749dd73ad71008b1f3160c0052
- name: github.com/ghodss/yaml
...
...
glide.yaml
View file @
595afc5c
...
...
@@ -41,6 +41,7 @@ import:
-
package
:
github.com/gobwas/glob
version
:
^0.2.1
-
package
:
github.com/evanphx/json-patch
-
package
:
github.com/facebookgo/atomicfile
-
package
:
github.com/facebookgo/symwalk
-
package
:
github.com/BurntSushi/toml
version
:
~0.3.0
...
...
pkg/repo/repo.go
View file @
595afc5c
...
...
@@ -23,6 +23,7 @@ import (
"os"
"time"
"github.com/facebookgo/atomicfile"
"github.com/ghodss/yaml"
)
...
...
@@ -134,9 +135,20 @@ func (r *RepoFile) Remove(name string) bool {
// WriteFile writes a repositories file to the given path.
func
(
r
*
RepoFile
)
WriteFile
(
path
string
,
perm
os
.
FileMode
)
error
{
f
,
err
:=
atomicfile
.
New
(
path
,
perm
)
if
err
!=
nil
{
return
err
}
data
,
err
:=
yaml
.
Marshal
(
r
)
if
err
!=
nil
{
return
err
}
return
ioutil
.
WriteFile
(
path
,
data
,
perm
)
_
,
err
=
f
.
File
.
Write
(
data
)
if
err
!=
nil
{
return
err
}
return
f
.
Close
()
}
pkg/repo/repo_test.go
View file @
595afc5c
...
...
@@ -201,10 +201,18 @@ func TestWriteFile(t *testing.T) {
t
.
Errorf
(
"failed to create test-file (%v)"
,
err
)
}
defer
os
.
Remove
(
repoFile
.
Name
())
if
err
:=
sampleRepository
.
WriteFile
(
repoFile
.
Name
(),
744
);
err
!=
nil
{
fileMode
:=
os
.
FileMode
(
0744
)
if
err
:=
sampleRepository
.
WriteFile
(
repoFile
.
Name
(),
fileMode
);
err
!=
nil
{
t
.
Errorf
(
"failed to write file (%v)"
,
err
)
}
info
,
_
:=
os
.
Stat
(
repoFile
.
Name
())
mode
:=
info
.
Mode
()
if
mode
!=
fileMode
{
t
.
Errorf
(
"incorrect file mode: %s (expected %s)"
,
mode
,
fileMode
)
}
repos
,
err
:=
LoadRepositoriesFile
(
repoFile
.
Name
())
if
err
!=
nil
{
t
.
Errorf
(
"failed to load file (%v)"
,
err
)
...
...
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