2021-12-09 18:36:11 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package ulfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2022-01-06 19:55:46 +00:00
|
|
|
"storj.io/storj/cmd/uplink/ulloc"
|
2021-12-09 18:36:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// read handles
|
|
|
|
//
|
|
|
|
|
|
|
|
// osMultiReadHandle implements MultiReadHandle for *os.Files.
|
2022-05-10 19:31:20 +01:00
|
|
|
func newOSMultiReadHandle(fh LocalBackendFile) (MultiReadHandle, error) {
|
2021-12-09 18:36:11 +00:00
|
|
|
fi, err := fh.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
return NewGenericMultiReadHandle(fh, ObjectInfo{
|
|
|
|
Loc: ulloc.NewLocal(fh.Name()),
|
|
|
|
IsPrefix: false,
|
|
|
|
Created: fi.ModTime(), // TODO: os specific crtime
|
|
|
|
ContentLength: fi.Size(),
|
|
|
|
}), nil
|
|
|
|
}
|
2021-12-09 19:03:42 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// write handles
|
|
|
|
//
|
|
|
|
|
2022-05-10 19:31:20 +01:00
|
|
|
type fileGenericWriter struct {
|
|
|
|
fs LocalBackend
|
|
|
|
raw LocalBackendFile
|
|
|
|
}
|
2021-12-09 19:03:42 +00:00
|
|
|
|
2022-05-10 19:31:20 +01:00
|
|
|
func (f *fileGenericWriter) WriteAt(b []byte, off int64) (int, error) { return f.raw.WriteAt(b, off) }
|
|
|
|
func (f *fileGenericWriter) Commit() error { return f.raw.Close() }
|
2021-12-09 19:03:42 +00:00
|
|
|
func (f *fileGenericWriter) Abort() error {
|
|
|
|
return errs.Combine(
|
2022-05-10 19:31:20 +01:00
|
|
|
f.raw.Close(),
|
|
|
|
f.fs.Remove(f.raw.Name()),
|
2021-12-09 19:03:42 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:31:20 +01:00
|
|
|
func newOSMultiWriteHandle(fs LocalBackend, fh LocalBackendFile) MultiWriteHandle {
|
|
|
|
return NewGenericMultiWriteHandle(&fileGenericWriter{
|
|
|
|
fs: fs,
|
|
|
|
raw: fh,
|
|
|
|
})
|
2021-12-09 19:03:42 +00:00
|
|
|
}
|