github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libdokan/mounter.go (about) 1 // Copyright 2016 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package libdokan 6 7 import ( 8 "time" 9 10 "github.com/keybase/client/go/kbfs/dokan" 11 "github.com/keybase/client/go/logger" 12 ) 13 14 type mounter struct { 15 options StartOptions 16 c *dokan.MountHandle 17 log logger.Logger 18 } 19 20 func (m *mounter) Unmount() error { return m.c.Close() } 21 22 func (m *mounter) Mount() (err error) { 23 // Retry loop 24 for i := 8; true; i *= 2 { 25 m.c, err = dokan.Mount(&m.options.DokanConfig) 26 // break if success, no force or too many tries. 27 if err == nil || i > 128 { 28 break 29 } 30 m.log.Errorf("Failed to mount dokan filesystem (i=%d): %v", i, err) 31 // Sleep two times 800ms, 1.6s, 3.2s, ... 32 time.Sleep(time.Duration(i) * 100 * time.Millisecond) 33 if m.options.ForceMount { 34 err = dokan.Unmount(m.options.DokanConfig.Path) 35 if err != nil { 36 m.log.Errorf("Failed to unmount dokan filesystem (i=%d): %v", 37 i, err) 38 } 39 time.Sleep(time.Duration(i) * 100 * time.Millisecond) 40 } 41 } 42 return err 43 }