diff --git a/internal/lib/os/file_posix.go b/internal/lib/os/file_posix.go index 03f1806c..684ff5be 100644 --- a/internal/lib/os/file_posix.go +++ b/internal/lib/os/file_posix.go @@ -16,13 +16,10 @@ import ( // be canceled and return immediately with an ErrClosed error. // Close will return an error if it has already been called. func (f *File) Close() error { - /* - if f == nil { - return ErrInvalid - } - return f.file.close() - */ - panic("todo: os.(*File).Close") + if f == nil { + return ErrInvalid + } + return f.close() } // pread reads len(b) bytes from the File starting at byte offset off. diff --git a/internal/lib/os/file_unix.go b/internal/lib/os/file_unix.go index 918890a0..fc75f0c1 100644 --- a/internal/lib/os/file_unix.go +++ b/internal/lib/os/file_unix.go @@ -250,6 +250,27 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) { return f, nil } +func (file *File) close() error { + return syscall.Close(int(file.fd)) + /* TODO(xsw): + if file.dirinfo != nil { + file.dirinfo.close() + file.dirinfo = nil + } + var err error + if e := file.pfd.Close(); e != nil { + if e == poll.ErrFileClosing { + e = ErrClosed + } + err = &PathError{Op: "close", Path: file.name, Err: e} + } + + // no need for a finalizer anymore + runtime.SetFinalizer(file, nil) + return err + */ +} + func tempDir() string { dir := Getenv("TMPDIR") if dir == "" {