()
| 50 | var backupRequestChan chan backupRequest |
| 51 | |
| 52 | func init() { |
| 53 | // Both saveRequestChan and backupRequestChan need to be non-buffered |
| 54 | // so the save/backup goroutine receives both save and backup requests |
| 55 | // in the same order the main goroutine sends them. |
| 56 | saveRequestChan = make(chan saveRequest) |
| 57 | backupRequestChan = make(chan backupRequest) |
| 58 | |
| 59 | go func() { |
| 60 | duration := backupSeconds * float64(time.Second) |
| 61 | backupTicker := time.NewTicker(time.Duration(duration)) |
| 62 | |
| 63 | for { |
| 64 | select { |
| 65 | case sr := <-saveRequestChan: |
| 66 | size, err := sr.buf.safeWrite(sr.path, sr.withSudo, sr.newFile) |
| 67 | sr.saveResponseChan <- saveResponse{size, err} |
| 68 | case br := <-backupRequestChan: |
| 69 | handleBackupRequest(br) |
| 70 | case <-backupTicker.C: |
| 71 | periodicBackup() |
| 72 | } |
| 73 | } |
| 74 | }() |
| 75 | } |
| 76 | |
| 77 | func openFile(name string, withSudo bool) (wrappedFile, error) { |
| 78 | var err error |
nothing calls this directly
no test coverage detected