mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
cloud backends: fix SFTP error message for some write failures
Fixes #119 Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
37
vfs/vfs.go
37
vfs/vfs.go
@@ -23,7 +23,7 @@ type Fs interface {
|
||||
Stat(name string) (os.FileInfo, error)
|
||||
Lstat(name string) (os.FileInfo, error)
|
||||
Open(name string) (*os.File, *pipeat.PipeReaderAt, func(), error)
|
||||
Create(name string, flag int) (*os.File, *pipeat.PipeWriterAt, func(), error)
|
||||
Create(name string, flag int) (*os.File, *PipeWriter, func(), error)
|
||||
Rename(source, target string) error
|
||||
Remove(name string, isDir bool) error
|
||||
Mkdir(name string) error
|
||||
@@ -44,6 +44,41 @@ type Fs interface {
|
||||
Join(elem ...string) string
|
||||
}
|
||||
|
||||
// PipeWriter defines a wrapper for pipeat.PipeWriterAt.
|
||||
type PipeWriter struct {
|
||||
writer *pipeat.PipeWriterAt
|
||||
err error
|
||||
done chan bool
|
||||
}
|
||||
|
||||
// NewPipeWriter initializes a new PipeWriter
|
||||
func NewPipeWriter(w *pipeat.PipeWriterAt) *PipeWriter {
|
||||
return &PipeWriter{
|
||||
writer: w,
|
||||
err: nil,
|
||||
done: make(chan bool),
|
||||
}
|
||||
}
|
||||
|
||||
// Close waits for the upload to end, closes the pipeat.PipeWriterAt and returns an error if any.
|
||||
func (p *PipeWriter) Close() error {
|
||||
p.writer.Close() //nolint:errcheck // the returned error is always null
|
||||
<-p.done
|
||||
return p.err
|
||||
}
|
||||
|
||||
// Done unlocks other goroutines waiting on Close().
|
||||
// It must be called when the upload ends
|
||||
func (p *PipeWriter) Done(err error) {
|
||||
p.err = err
|
||||
p.done <- true
|
||||
}
|
||||
|
||||
// WriteAt is a wrapper for pipeat WriteAt
|
||||
func (p *PipeWriter) WriteAt(data []byte, off int64) (int, error) {
|
||||
return p.writer.WriteAt(data, off)
|
||||
}
|
||||
|
||||
// VirtualFolder defines a mapping between a SFTP/SCP virtual path and a
|
||||
// filesystem path outside the user home directory.
|
||||
// The specified paths must be absolute and the virtual path cannot be "/",
|
||||
|
||||
Reference in New Issue
Block a user