~chipaca/snappy/snappy-tar-pack-mknod

« back to all changes in this revision

Viewing changes to policy/policy.go

  • Committer: Snappy Tarmac
  • Author(s): John R. Lenton
  • Date: 2015-05-05 22:32:10 UTC
  • mfrom: (435.1.5 copyfile)
  • Revision ID: snappy_tarmac-20150505223210-w7oz8tnd8y2xokwj
Moved two implementations of Copy into helpers with the linux implementation being based on sendfile. by chipaca approved by sergiusens

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import (
23
23
        "fmt"
24
 
        "io"
25
24
        "os"
26
25
        "path/filepath"
27
26
 
90
89
                        }
91
90
                case install:
92
91
                        // do the copy
93
 
                        fin, err := os.Open(file)
94
 
                        if err != nil {
95
 
                                return fmt.Errorf("unable to read %v: %v", file, err)
96
 
                        }
97
 
                        defer func() {
98
 
                                if cerr := fin.Close(); cerr != nil && err == nil {
99
 
                                        err = fmt.Errorf("when closing %v: %v", file, cerr)
100
 
                                }
101
 
                        }()
102
 
 
103
 
                        fout, err := os.Create(targetFile)
104
 
                        if err != nil {
105
 
                                return fmt.Errorf("unable to create %v: %v", targetFile, err)
106
 
                        }
107
 
                        defer func() {
108
 
                                if cerr := fout.Close(); cerr != nil && err == nil {
109
 
                                        err = fmt.Errorf("when closing %v: %v", targetFile, cerr)
110
 
                                }
111
 
                        }()
112
 
 
113
 
                        if _, err = io.Copy(fout, fin); err != nil {
114
 
                                return fmt.Errorf("unable to copy %v to %v: %v", file, targetFile, err)
115
 
                        }
116
 
                        if err = fout.Sync(); err != nil {
117
 
                                return fmt.Errorf("when syncing %v: %v", targetFile, err)
118
 
                        }
119
 
 
 
92
                        if err := helpers.CopyFile(file, targetFile, helpers.CopyFlagSync); err != nil {
 
93
                                return err
 
94
                        }
120
95
                default:
121
96
                        return fmt.Errorf("unknown operation %s", op)
122
97
                }