aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Clerc <jclerc@google.com>2017-02-15 09:33:30 +0100
committerJeremy Clerc <jclerc@google.com>2017-02-15 09:33:30 +0100
commit1d7c7f7b897ad203f8d873d6338edd7ec735f936 (patch)
tree1561e763b9a7b1a4ef65fc08a0c166075c435563
parent482f2871eaa8e5b8d093dfae2265796d2d6ab1e5 (diff)
downloadeasypki-1d7c7f7b897ad203f8d873d6338edd7ec735f936.tar.xz
Move file creation in its own defined func.
-rw-r--r--pkg/store/local.go43
1 files changed, 22 insertions, 21 deletions
diff --git a/pkg/store/local.go b/pkg/store/local.go
index 4a2520d..1895e83 100644
--- a/pkg/store/local.go
+++ b/pkg/store/local.go
@@ -355,29 +355,30 @@ func InitCADir(path string) error {
{Name: "index.txt.attr", Content: "unique_subject = no"},
}
for _, f := range files {
- err := func(path, content string) error {
- fh, err := os.Create(path)
- if err != nil {
- return fmt.Errorf("failed creating file %v: %v", path, err)
- }
- defer fh.Close()
-
- if content == "" {
- return nil
- }
-
- n, err := fmt.Fprintln(fh, content)
- if err != nil {
- return fmt.Errorf("failed wrinting %v in %v: %v", content, path, err)
- }
- if n == 0 {
- return fmt.Errorf("failed writing %v in %v: 0 bytes written", content, path)
- }
- return nil
- }(filepath.Join(path, f.Name), f.Content)
- if err != nil {
+ if err := createFile(filepath.Join(path, f.Name), f.Content); err != nil {
return err
}
}
return nil
}
+
+func createFile(path, content string) error {
+ fh, err := os.Create(path)
+ if err != nil {
+ return fmt.Errorf("failed creating file %v: %v", path, err)
+ }
+ defer fh.Close()
+
+ if content == "" {
+ return nil
+ }
+
+ n, err := fmt.Fprintln(fh, content)
+ if err != nil {
+ return fmt.Errorf("failed wrinting %v in %v: %v", content, path, err)
+ }
+ if n == 0 {
+ return fmt.Errorf("failed writing %v in %v: 0 bytes written", content, path)
+ }
+ return nil
+}