()
| 350 | } |
| 351 | |
| 352 | func (c Crontab) load() ([]string, int, error) { |
| 353 | |
| 354 | var crontabBytes []byte |
| 355 | |
| 356 | if c.IsUserCrontab { |
| 357 | if runtime.GOOS == "windows" { |
| 358 | return nil, 126, errors.New("on Windows, a crontab path argument is required") |
| 359 | } |
| 360 | |
| 361 | cmd := c.buildCrontabCommand("-l") |
| 362 | if b, err := cmd.CombinedOutput(); err == nil { |
| 363 | crontabBytes = b |
| 364 | } else { |
| 365 | if strings.Contains(string(b), "no crontab") { |
| 366 | return nil, 126, errors.New("no crontab for this user") |
| 367 | } else { |
| 368 | return nil, 126, errors.New("user crontab couldn't be read") |
| 369 | } |
| 370 | } |
| 371 | } else { |
| 372 | if _, err := os.Stat(c.Filename); os.IsNotExist(err) { |
| 373 | return nil, 66, errors.New(fmt.Sprintf("the file %s does not exist", c.Filename)) |
| 374 | } |
| 375 | |
| 376 | if b, err := ioutil.ReadFile(c.Filename); err == nil { |
| 377 | crontabBytes = b |
| 378 | } else { |
| 379 | return nil, 126, errors.New(fmt.Sprintf("the crontab file at %s could not be read; check permissions and try again", c.Filename)) |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | if len(crontabBytes) == 0 { |
| 384 | return nil, 126, errors.New("the crontab file is empty") |
| 385 | } |
| 386 | |
| 387 | return strings.Split(string(crontabBytes), "\n"), 0, nil |
| 388 | } |
| 389 | |
| 390 | // MarshalJSON implements custom JSON marshaling to include both Filename and DisplayName |
| 391 | func (c Crontab) MarshalJSON() ([]byte, error) { |
no test coverage detected