|
|
@ -77,8 +77,17 @@ func writelines(f *fileOpener, c chan []byte) {
|
|
|
|
// path.
|
|
|
|
// path.
|
|
|
|
type fileOpener struct {
|
|
|
|
type fileOpener struct {
|
|
|
|
*os.File
|
|
|
|
*os.File
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// name of the file to be opened
|
|
|
|
fname string
|
|
|
|
fname string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// file create flags to be passed to os.Open when opening the file.. If
|
|
|
|
|
|
|
|
// you don't include os.O_APPEND you're most likely doing it wrong.
|
|
|
|
flag int
|
|
|
|
flag int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// file permissions on file to be created, passed to os.Open. If you don't
|
|
|
|
|
|
|
|
// include os.O_CREATE in the flags then this is inconsequential since
|
|
|
|
|
|
|
|
// we're not going to create new files anyway.
|
|
|
|
mode os.FileMode
|
|
|
|
mode os.FileMode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -94,7 +103,10 @@ func (f *fileOpener) Open() error {
|
|
|
|
// closes and reopens the file found at the fileopener's specified path. If
|
|
|
|
// closes and reopens the file found at the fileopener's specified path. If
|
|
|
|
// the original file has moved, reopen will cause the fileopener to change which
|
|
|
|
// the original file has moved, reopen will cause the fileopener to change which
|
|
|
|
// inode it points to. If the original file has been moved or deleted, and a
|
|
|
|
// inode it points to. If the original file has been moved or deleted, and a
|
|
|
|
// new file has not been created in its place,
|
|
|
|
// new file has not been created in its place, the fileOpener *may* create a
|
|
|
|
|
|
|
|
// new file, depending on its initial flags. (spoiler alert: since we only use
|
|
|
|
|
|
|
|
// this once, and we do include the create flag, reopen will always create a
|
|
|
|
|
|
|
|
// file if none exists)
|
|
|
|
func (f *fileOpener) Reopen() error {
|
|
|
|
func (f *fileOpener) Reopen() error {
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
return fmt.Errorf("fileOpener unable to reopen file: %v", err)
|
|
|
|
return fmt.Errorf("fileOpener unable to reopen file: %v", err)
|
|
|
|