Skip to content

Commit

Permalink
waitForMount->Go & fix bug where it checked wrong location on Catalina (
Browse files Browse the repository at this point in the history
#20422)

* waitForMount->Go & fix bug where it checked wrong location on Catalina

* check for preferred mounts as well; and other feedback from strib

* there's nothing we can do about the timeout erorr so just ignore

* review feedback strib
  • Loading branch information
songgao committed Oct 20, 2019
1 parent 14a0432 commit a286206
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 21 deletions.
19 changes: 19 additions & 0 deletions go/protocol/keybase1/kbfsmount.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions go/service/kbfs_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
package service

import (
"os"
"path/filepath"
"time"

"golang.org/x/net/context"

"github.com/keybase/client/go/libkb"
Expand All @@ -27,6 +31,43 @@ func (h *KBFSMountHandler) GetCurrentMountDir(ctx context.Context) (res string,
return h.G().Env.GetMountDir()
}

const waitForDirectMountTimeout = 10 * time.Second
const waitForDirectMountPollInterval = time.Second

func (h *KBFSMountHandler) WaitForMounts(ctx context.Context) (active bool, err error) {
ctx, cancel := context.WithTimeout(ctx, waitForDirectMountTimeout)
defer cancel()
mount, err := h.GetCurrentMountDir(ctx)
if err != nil {
return false, err
}
directMountFileToCheck := filepath.Join(mount, ".kbfs_error")
ticker := time.NewTicker(waitForDirectMountPollInterval)
defer ticker.Stop()
directMountFound, preferredMountFound := false, false
for !directMountFound || !preferredMountFound {
select {
case <-ticker.C:
if !directMountFound {
fi, err := os.Stat(directMountFileToCheck)
if err == nil && !fi.IsDir() {
directMountFound = true
}
// Not check os.IsNotExist here because it can be permission
// error too. So just wait it out.
}
if !preferredMountFound {
if len(libkb.FindPreferredKBFSMountDirs()) > 0 {
preferredMountFound = true
}
}
case <-ctx.Done():
return false, nil
}
}
return true, nil
}

func (h *KBFSMountHandler) GetPreferredMountDirs(ctx context.Context) (res []string, err error) {
res = libkb.FindPreferredKBFSMountDirs()
directMount, err := h.G().Env.GetMountDir()
Expand Down
2 changes: 2 additions & 0 deletions protocol/avdl/keybase1/kbfsmount.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ protocol kbfsMount {
@lint("ignore")
string GetCurrentMountDir();
@lint("ignore")
boolean WaitForMounts();
@lint("ignore")
array<string> GetPreferredMountDirs();
@lint("ignore")
array<string> GetAllAvailableMountDirs();
Expand Down
1 change: 1 addition & 0 deletions protocol/bin/enabled-calls.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"keybase.1.install.installKBFS": {"promise": true},
"keybase.1.install.uninstallKBFS": {"promise": true},
"keybase.1.kbfsMount.GetCurrentMountDir": {"promise": true},
"keybase.1.kbfsMount.WaitForMounts": {"promise": true},
"keybase.1.kbfsMount.GetPreferredMountDirs": {"promise": true},
"keybase.1.kbfsMount.GetKBFSPathInfo": {"promise": true},
"keybase.1.login.accountDelete": {"promise": true},
Expand Down
5 changes: 5 additions & 0 deletions protocol/json/keybase1/kbfsmount.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions shared/actions/fs/platform-specific.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as I from 'immutable'
import * as ConfigGen from '../config-gen'
import * as FsGen from '../fs-gen'
import * as Saga from '../../util/saga'
import * as Config from '../../constants/config'
import * as RPCTypes from '../../constants/types/rpc-gen'
import * as Types from '../../constants/types/fs'
import * as Constants from '../../constants/fs'
Expand Down Expand Up @@ -145,24 +144,6 @@ const openPathInSystemFileManager = (state: TypedState, action: FsGen.OpenPathIn
}
}) as Promise<void>)

function waitForMount(attempt: number) {
return new Promise((resolve, reject) => {
// Read the KBFS path waiting for files to exist, which means it's mounted
// TODO: should handle current mount directory
fs.readdir(`${Config.defaultKBFSPath}${Config.defaultPrivatePrefix}`, (err, files) => {
if (!err && files.length > 0) {
resolve(true)
} else if (attempt > 15) {
reject(new Error(`${Config.defaultKBFSPath} is unavailable. Please try again.`))
} else {
setTimeout(() => {
waitForMount(attempt + 1).then(resolve, reject)
}, 1000)
}
})
})
}

const fuseStatusToUninstallExecPath = isWindows
? (status: RPCTypes.FuseStatus) => {
const field =
Expand Down Expand Up @@ -257,7 +238,7 @@ const driverEnableFuse = async (_: TypedState, action: FsGen.DriverEnablePayload
]
} else {
await RPCTypes.installInstallKBFSRpcPromise() // restarts kbfsfuse
await waitForMount(0)
await RPCTypes.kbfsMountWaitForMountsRpcPromise()
return FsGen.createRefreshDriverStatus()
}
}
Expand Down
5 changes: 5 additions & 0 deletions shared/constants/types/rpc-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const JustEnabled = ({onDismiss}: JustEnabledProps) => {
const displayingMountDir = preferredMountDirs.get(0) || ''
const dispatch = Container.useDispatch()
const open = displayingMountDir
? () => dispatch(FsGen.createOpenPathInSystemFileManager({path: displayingMountDir}))
? () => dispatch(FsGen.createOpenLocalPathInSystemFileManager({localPath: displayingMountDir}))
: undefined
return (
<Banner
Expand Down

0 comments on commit a286206

Please sign in to comment.