Here's a step by step workaround for Google Drive v49 (might not work in future versions):
- Quit Google Drive (click on the Google Drive icon in the menu bar, then click on the cogwheel, then click Quit).
- Save this file somewhere as
curl -LO https://gist.githubusercontent.com/emersonford/85cc74f7f90c81d1b75c3c246124591d/raw/442834222e2aaa2be61badb6e84f53183ee10624/change_gdrive_smb_port.py).
- Read over the script yourself so you know it's safe to run.
- Run this script with
python3 change_gdrive_smb_port.py. It will give you some prompts when it has found an account and to what port to change that account's SMB port to. These ports should be unused ports on your system.
- Relaunch Google Drive.
- Run the
mdutil -i on command the script spits out.
- Give Spotlight some time to index everything in Google Drive. It should now stay enabled!
If my script happens to break Google Drive or if you want to reset this change, all you need to do is remove
~/Library/Application Support/Google/DriveFS/<ACCOUNT_NUM> and restart Google Drive.
EDIT: This isn't as permanent as I thought. It looks like Google can remotely push changes to the "feature_config" file, which they've been doing once a day by the looks of it. When they push out changes, it ends up overwriting the changes my script made to
At a minimum, you can always rerun the script and restart Google Drive (chain it together with
pkill "Google Drive" && sleep 5 && echo "yes\n[PORT_NUM]" | python3 change_gdrive_smb_port.py && open /Applications/Google\ Drive.app). It's not great, but it preserves the Spotlight index database so you don't have to wait / waste CPU cycles on reindexing everytime.
I'll update this again if I find a workaround!
Google Drive used to use a custom FUSE implementation called DriveFS on macOS which appears to have had Spotlight indexing support built in. It appears -- and this is all speculation on my part as I'm not a Google employee -- they had a lot of trouble bringing this over to the new M1 Macs based on this article. Even without that, FUSE implementations tend to be really hairy to maintain, so I wouldn't blame them for wanting to move off of it.
I assume that as part of their Google Drive streaming for everyone roll-out, they wanted to ensure everyone could run Google Drive without mucking with kernel extensions, so they appear to have migrated the Google Drive filesystem to a Samba server implementation, then mount that with macOS's built in Samba client (hence why you now see 'localhost' mounted in Network). Kind of clever if you ask me!
Now, the problem with this for Spotlight is two-fold. First, Apple now defaults to disabling Spotlight on network drives (likely with good reason), thus you now have to manually enable Spotlight on Google Drive.
Second, Google Drive sets the Samba server's port binding to -1, which means the OS picks a random available port for you. I'm not sure when this changed, but Spotlight no longer places its index in the root folder with the name
Spotlight-V100. All Spotlight indexes are now stored in
/var/db/Spotlight-V100; further, for network drives, that index is named something like
smb%3A%2F%2FDRIVE@localhost%3A59999%2FGoogle%2520Drive. If you look closely, the port number of the network drive is part of the Spotlight index name. This is why Spotlight indexing seems to disable itself after some time. When Google Drive remounts the FS (sometimes randomly, sometimes on network disconnects), it's likely it got a new port from the OS to bind to. So to Spotlight, this looks like an entirely different network drive you haven't enabled Spotlight indexing on, thus you have to not only reenable indexing, but also wait for Spotlight to index everything all over again.
I dug around the logs (in
~/Library/Application Support/Google/DriveFS/Logs) and noticed this in the start up section:
2021-07-22T18:12:33.759ZI [6139763:CrBrowserMain] global_features_manager.cc:266:CompositeAll Composited global features *WITHOUT* overrides: drive_dot: true
so it seems changing the SMB port to a static port is a preference, just got to figure out where. It took me a little bit to find this as it doesn't appear to be a plist setting, but using
strings, I was able to deduce it was in
core_feature_config which I discovered to be a binary file in the protobuf format. So just had to find the right field and replace the
mac_smb_port value with what I wanted (with the right protobuf encoding). Once I figured that out with the right script, Spotlight has been stable for me since!
Don't anticipate this will be an issue for much longer though, so if you aren't comfortable using my script and are willing to wait, I think you can sit tight. Either the Google Drive folks will add a static port number (or setting) to fix this issue or they'll migrate to using the built-in File Provider API (which I discovered you can enable right now by changing a different flag in
core_feature_config), which will likely have better Spotlight support built in.