]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - file.go
nsscash: go fmt
[nsscash/nsscash.git] / file.go
diff --git a/file.go b/file.go
index 33d71c14c152c144dc4e0e3cf04e758c0cee4858..b77cbb692de37f02df499c7af5254e34b2bf8de4 100644 (file)
--- a/file.go
+++ b/file.go
@@ -31,10 +31,15 @@ import (
 )
 
 func handleFiles(cfg *Config, state *State) error {
+       // Split into fetch and deploy phase to prevent updates of only some
+       // files which might lead to inconsistent state; obviously this won't
+       // work during the deploy phase, but it helps if the web server fails
+       // to deliver some files
+
        for i, f := range cfg.Files {
                err := fetchFile(&cfg.Files[i], state)
                if err != nil {
-                       return errors.Wrapf(err, "%q (%s)", f.Url, f.Type)
+                       return errors.Wrapf(err, "%q (%v)", f.Url, f.Type)
                }
        }
 
@@ -46,7 +51,7 @@ func handleFiles(cfg *Config, state *State) error {
 
                err := deployFile(&cfg.Files[i])
                if err != nil {
-                       return errors.Wrapf(err, "%q (%s)", f.Url, f.Type)
+                       return errors.Wrapf(err, "%q (%v)", f.Url, f.Type)
                }
        }
 
@@ -135,7 +140,8 @@ func deployFile(file *File) error {
        defer os.Remove(f.Name())
        defer f.Close()
 
-       // Apply permissions/user/group from the target file
+       // Apply permissions/user/group from the target file, use Stat instead
+       // of Lstat as only the target's permissions are relevant
        stat, err := os.Stat(file.Path)
        if err != nil {
                // We do not create the path if it doesn't exist, because we