@@ -25,7 +25,7 @@ import (
2525)
2626
2727const (
28- minSleep = 100 * time .Millisecond
28+ minSleep = 10 * time .Millisecond
2929 maxSleep = 2 * time .Second
3030 decayConstant = 2 // bigger for slower decay, exponential
3131)
@@ -207,7 +207,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
207207 return nil , err
208208 }
209209 stat , err := cn .smbShare .Stat (f .toSambaPath (dir ))
210- f .putConnection (& cn )
210+ f .putConnection (& cn , err )
211211 if err != nil {
212212 // ignore stat error here
213213 return f , nil
@@ -268,7 +268,7 @@ func (f *Fs) findObjectSeparate(ctx context.Context, share, path string) (fs.Obj
268268 return nil , err
269269 }
270270 stat , err := cn .smbShare .Stat (f .toSambaPath (path ))
271- f .putConnection (& cn )
271+ f .putConnection (& cn , err )
272272 if err != nil {
273273 return nil , translateError (err , false )
274274 }
@@ -290,7 +290,7 @@ func (f *Fs) Mkdir(ctx context.Context, dir string) (err error) {
290290 return err
291291 }
292292 err = cn .smbShare .MkdirAll (f .toSambaPath (path ), 0o755 )
293- f .putConnection (& cn )
293+ f .putConnection (& cn , err )
294294 return err
295295}
296296
@@ -305,7 +305,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error {
305305 return err
306306 }
307307 err = cn .smbShare .Remove (f .toSambaPath (path ))
308- f .putConnection (& cn )
308+ f .putConnection (& cn , err )
309309 return err
310310}
311311
@@ -375,7 +375,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (_ fs.Objec
375375 return nil , err
376376 }
377377 err = cn .smbShare .Rename (f .toSambaPath (srcPath ), f .toSambaPath (dstPath ))
378- f .putConnection (& cn )
378+ f .putConnection (& cn , err )
379379 if err != nil {
380380 return nil , translateError (err , false )
381381 }
@@ -412,7 +412,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
412412 if err != nil {
413413 return err
414414 }
415- defer f .putConnection (& cn )
415+ defer f .putConnection (& cn , err )
416416
417417 _ , err = cn .smbShare .Stat (dstPath )
418418 if os .IsNotExist (err ) {
@@ -430,7 +430,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
430430 if err != nil {
431431 return nil , err
432432 }
433- defer f .putConnection (& cn )
433+ defer f .putConnection (& cn , err )
434434
435435 if share == "" {
436436 shares , err := cn .smbSession .ListSharenames ()
@@ -474,7 +474,7 @@ func (f *Fs) About(ctx context.Context) (_ *fs.Usage, err error) {
474474 return nil , err
475475 }
476476 stat , err := cn .smbShare .Statfs (dir )
477- f .putConnection (& cn )
477+ f .putConnection (& cn , err )
478478 if err != nil {
479479 return nil , err
480480 }
@@ -556,7 +556,7 @@ func (f *Fs) ensureDirectory(ctx context.Context, share, _path string) error {
556556 return err
557557 }
558558 err = cn .smbShare .MkdirAll (f .toSambaPath (dir ), 0o755 )
559- f .putConnection (& cn )
559+ f .putConnection (& cn , err )
560560 return err
561561}
562562
@@ -604,7 +604,7 @@ func (o *Object) SetModTime(ctx context.Context, t time.Time) (err error) {
604604 if err != nil {
605605 return err
606606 }
607- defer o .fs .putConnection (& cn )
607+ defer o .fs .putConnection (& cn , err )
608608
609609 err = cn .smbShare .Chtimes (reqDir , t , t )
610610 if err != nil {
@@ -650,24 +650,25 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
650650 }
651651 fl , err := cn .smbShare .OpenFile (filename , os .O_RDONLY , 0 )
652652 if err != nil {
653- o .fs .putConnection (& cn )
653+ o .fs .putConnection (& cn , err )
654654 return nil , fmt .Errorf ("failed to open: %w" , err )
655655 }
656656 pos , err := fl .Seek (offset , io .SeekStart )
657657 if err != nil {
658- o .fs .putConnection (& cn )
658+ o .fs .putConnection (& cn , err )
659659 return nil , fmt .Errorf ("failed to seek: %w" , err )
660660 }
661661 if pos != offset {
662- o .fs .putConnection (& cn )
663- return nil , fmt .Errorf ("failed to seek: wrong position (expected=%d, reported=%d)" , offset , pos )
662+ err = fmt .Errorf ("failed to seek: wrong position (expected=%d, reported=%d)" , offset , pos )
663+ o .fs .putConnection (& cn , err )
664+ return nil , err
664665 }
665666
666667 in = readers .NewLimitedReadCloser (fl , limit )
667668 in = & boundReadCloser {
668669 rc : in ,
669670 close : func () error {
670- o .fs .putConnection (& cn )
671+ o .fs .putConnection (& cn , nil )
671672 return nil
672673 },
673674 }
@@ -697,7 +698,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
697698 return err
698699 }
699700 defer func () {
700- o .fs .putConnection (& cn )
701+ o .fs .putConnection (& cn , err )
701702 }()
702703
703704 fl , err := cn .smbShare .OpenFile (filename , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , 0o644 )
@@ -757,7 +758,7 @@ func (o *Object) Remove(ctx context.Context) (err error) {
757758 }
758759
759760 err = cn .smbShare .Remove (filename )
760- o .fs .putConnection (& cn )
761+ o .fs .putConnection (& cn , err )
761762
762763 return err
763764}
0 commit comments