writeBatchFile writes a batch file out to disk see the dicussion on why it has to be done this way
(targetPath string, newPath string, oldPath string)
| 212 | // writeBatchFile writes a batch file out to disk |
| 213 | // see the dicussion on why it has to be done this way |
| 214 | func writeBatchFile(targetPath string, newPath string, oldPath string) error { |
| 215 | batchFilePath := filepath.Join(filepath.Dir(targetPath), batchFileName) |
| 216 | os.Remove(batchFilePath) //remove any failed updates before download |
| 217 | f, err := os.Create(batchFilePath) |
| 218 | if err != nil { |
| 219 | return err |
| 220 | } |
| 221 | defer f.Close() |
| 222 | cfdName := filepath.Base(targetPath) |
| 223 | oldName := filepath.Base(oldPath) |
| 224 | |
| 225 | data := batchData{ |
| 226 | TargetPath: targetPath, |
| 227 | OldName: oldName, |
| 228 | NewPath: newPath, |
| 229 | OldPath: oldPath, |
| 230 | BinaryName: cfdName, |
| 231 | BatchName: batchFileName, |
| 232 | } |
| 233 | |
| 234 | t, err := template.New("batch").Parse(windowsUpdateCommandTemplate) |
| 235 | if err != nil { |
| 236 | return err |
| 237 | } |
| 238 | return t.Execute(f, data) |
| 239 | } |
| 240 | |
| 241 | // run each OS command for windows |
| 242 | func runWindowsBatch(batchFile string) error { |