showMOTD will output the message of the day from the given filename to dest, if the file exists. https://github.com/openssh/openssh-portable/blob/25bd659cc72268f2858c5415740c442ee950049f/session.c#L784
(fs afero.Fs, dest io.Writer, filename string)
| 1315 | // |
| 1316 | // https://github.com/openssh/openssh-portable/blob/25bd659cc72268f2858c5415740c442ee950049f/session.c#L784 |
| 1317 | func showMOTD(fs afero.Fs, dest io.Writer, filename string) error { |
| 1318 | if filename == "" { |
| 1319 | return nil |
| 1320 | } |
| 1321 | |
| 1322 | f, err := fs.Open(filename) |
| 1323 | if err != nil { |
| 1324 | if xerrors.Is(err, os.ErrNotExist) { |
| 1325 | // This is not an error, there simply isn't a MOTD to show. |
| 1326 | return nil |
| 1327 | } |
| 1328 | return xerrors.Errorf("open MOTD: %w", err) |
| 1329 | } |
| 1330 | defer f.Close() |
| 1331 | |
| 1332 | return writeWithCarriageReturn(f, dest) |
| 1333 | } |
| 1334 | |
| 1335 | // writeWithCarriageReturn writes each line with a carriage return to ensure |
| 1336 | // that each line starts at the beginning of the terminal. |
no test coverage detected