From 5b77b2f27dbb91f07770e6eeb583d4ebe32ff031 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 4 Dec 2024 08:18:12 +0100 Subject: [PATCH] make linter happy Signed-off-by: Christian Richter --- backend/webdav/tus-errors.go | 28 +++++++++++++++++++--------- backend/webdav/tus-upload.go | 13 ++++++++----- backend/webdav/tus-uploader.go | 4 ++-- backend/webdav/tus.go | 2 +- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/backend/webdav/tus-errors.go b/backend/webdav/tus-errors.go index 4e44276c4..43ff0de8e 100644 --- a/backend/webdav/tus-errors.go +++ b/backend/webdav/tus-errors.go @@ -6,15 +6,25 @@ import ( ) var ( - ErrChuckSize = errors.New("tus chunk size must be greater than zero") - ErrNilLogger = errors.New("tus logger can't be nil") - ErrNilStore = errors.New("tus store can't be nil if Resume is enable") - ErrNilUpload = errors.New("tus upload can't be nil") - ErrLargeUpload = errors.New("tus upload body is to large") - ErrVersionMismatch = errors.New("tus protocol version mismatch") - ErrOffsetMismatch = errors.New("tus upload offset mismatch") - ErrUploadNotFound = errors.New("tus upload not found") - ErrResumeNotEnabled = errors.New("tus resuming not enabled") + // ErrChuckSize is returned when the chunk size is zero + ErrChuckSize = errors.New("tus chunk size must be greater than zero") + // ErrNilConfig is returned when the logger is nil + ErrNilLogger = errors.New("tus logger can't be nil") + // ErrNilStore is returned when the store is nil + ErrNilStore = errors.New("tus store can't be nil if resume is enable") + // ErrNilUpload is returned when the upload is nil + ErrNilUpload = errors.New("tus upload can't be nil") + // ErrLargeUpload is returned when the upload body is to large + ErrLargeUpload = errors.New("tus upload body is to large") + // ErrVersionMismatch is returned when the tus protocol version is mismatching + ErrVersionMismatch = errors.New("tus protocol version mismatch") + // ErrOffsetMismatch is returned when the tus upload offset is mismatching + ErrOffsetMismatch = errors.New("tus upload offset mismatch") + // ErrUploadNotFound is returned when the tus upload is not found + ErrUploadNotFound = errors.New("tus upload not found") + // ErrResumeNotEnabled is returned when the tus resuming is not enabled + ErrResumeNotEnabled = errors.New("tus resuming not enabled") + // ErrFingerprintNotSet is returned when the tus fingerprint is not set ErrFingerprintNotSet = errors.New("tus fingerprint not set") ) diff --git a/backend/webdav/tus-upload.go b/backend/webdav/tus-upload.go index 9a957f5b6..4b4cc2272 100644 --- a/backend/webdav/tus-upload.go +++ b/backend/webdav/tus-upload.go @@ -26,22 +26,22 @@ func (u *Upload) updateProgress(offset int64) { u.offset = offset } -// Returns whether this upload is finished or not. +// Finished returns whether this upload is finished or not. func (u *Upload) Finished() bool { return u.offset >= u.size } -// Returns the progress in a percentage. +// Progress returns the progress in a percentage. func (u *Upload) Progress() int64 { return (u.offset * 100) / u.size } -// Returns the current upload offset. +// Offset returns the current upload offset. func (u *Upload) Offset() int64 { return u.offset } -// Returns the size of the upload body. +// Size returns the size of the upload body. func (u *Upload) Size() int64 { return u.size } @@ -67,7 +67,10 @@ func NewUpload(reader io.Reader, size int64, metadata Metadata, fingerprint stri if !ok { buf := new(bytes.Buffer) - buf.ReadFrom(reader) + _, err := buf.ReadFrom(reader) + if err != nil { + return nil + } stream = bytes.NewReader(buf.Bytes()) } diff --git a/backend/webdav/tus-uploader.go b/backend/webdav/tus-uploader.go index e0caa79f9..bad2ef637 100644 --- a/backend/webdav/tus-uploader.go +++ b/backend/webdav/tus-uploader.go @@ -25,7 +25,7 @@ type Uploader struct { overridePatchMethod bool } -// Subscribes to progress updates. +// NotifyUploadProgress subscribes to progress updates. func (u *Uploader) NotifyUploadProgress(c chan Upload) { u.uploadSubs = append(u.uploadSubs, c) } @@ -106,7 +106,7 @@ func (u *Uploader) uploadChunk(ctx context.Context, body io.Reader, size int64, // Upload uploads the entire body to the server. func (u *Uploader) Upload(ctx context.Context, options ...fs.OpenOption) error { - var cnt int = 1 + cnt := 1 fs.Debug(u.fs, "Uploaded starts") for u.offset < u.upload.size && !u.aborted { diff --git a/backend/webdav/tus.go b/backend/webdav/tus.go index e94d24f31..8868e5449 100644 --- a/backend/webdav/tus.go +++ b/backend/webdav/tus.go @@ -64,7 +64,7 @@ func (f *Fs) shouldRetryCreateUpload(ctx context.Context, resp *http.Response, e return f.shouldRetry(ctx, resp, err) } -// CreateUpload creates a new upload to the server. +// CreateUploader creates a new upload to the server. func (o *Object) CreateUploader(ctx context.Context, u *Upload, options ...fs.OpenOption) (*Uploader, error) { if u == nil { return nil, ErrNilUpload