GetCrontab returns a single Crontab object for the specified filename. The filename can be either a full path to a crontab file or a user crontab in the form "user: ".
(filename string)
| 898 | // GetCrontab returns a single Crontab object for the specified filename. |
| 899 | // The filename can be either a full path to a crontab file or a user crontab in the form "user:<username>". |
| 900 | func GetCrontab(filename string) (*Crontab, error) { |
| 901 | var username string |
| 902 | |
| 903 | if strings.HasPrefix(filename, "user:") { |
| 904 | username = strings.TrimPrefix(filename, "user:") |
| 905 | } else if u, err := user.Current(); err == nil { |
| 906 | username = u.Username |
| 907 | } |
| 908 | |
| 909 | crontabs := ReadCrontabFromFile(username, filename, []*Crontab{}) |
| 910 | if len(crontabs) == 0 { |
| 911 | return nil, fmt.Errorf("no crontab found at %s", filename) |
| 912 | } |
| 913 | return crontabs[0], nil |
| 914 | } |
| 915 | |
| 916 | // lightweightCrontab creates a copy of Crontab without the Lines field to prevent circular references |
| 917 | func (c *Crontab) lightweightCopy() Crontab { |
no test coverage detected