mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-09-14 05:20:11 +00:00

* [NOD-1223] Delete unused files/packages. * [NOD-1223] Move signal and limits to the os package. * [NOD-1223] Put database and dbaccess into the db package. * [NOD-1223] Fold the logs package into the logger package. * [NOD-1223] Rename domainmessage to appmessage. * [NOD-1223] Rename to/from DomainMessage to AppMessage. * [NOD-1223] Move appmessage to the app packge. * [NOD-1223] Move protocol to the app packge. * [NOD-1223] Move the network package to the infrastructure packge. * [NOD-1223] Rename cmd to executables. * [NOD-1223] Fix go.doc in the logger package.
45 lines
888 B
Go
45 lines
888 B
Go
package ff
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
// lockableFile represents a flat file on disk that has been opened for either
|
|
// read or read/write access. It also contains a read-write mutex to support
|
|
// multiple concurrent readers.
|
|
type lockableFile struct {
|
|
sync.RWMutex
|
|
file
|
|
|
|
isClosed bool
|
|
}
|
|
|
|
// file is an interface which acts very similar to a *os.File and is typically
|
|
// implemented by it. It exists so the test code can provide mock files for
|
|
// properly testing corruption and file system issues.
|
|
type file interface {
|
|
io.Closer
|
|
io.WriterAt
|
|
io.ReaderAt
|
|
Truncate(size int64) error
|
|
Sync() error
|
|
}
|
|
|
|
func (lf *lockableFile) Close() error {
|
|
if lf.isClosed {
|
|
return errors.Errorf("cannot close an already closed file")
|
|
}
|
|
lf.isClosed = true
|
|
|
|
lf.Lock()
|
|
defer lf.Unlock()
|
|
|
|
if lf.file == nil {
|
|
return nil
|
|
}
|
|
|
|
return errors.WithStack(lf.file.Close())
|
|
}
|