Spotlight Indexing of Google Drive File Stream Disabled on Restart

Here's a step by step workaround for Google Drive v49 (might not work in future versions):

  1. Quit Google Drive (click on the Google Drive icon in the menu bar, then click on the cogwheel, then click Quit).
  2. Save this file somewhere as change_gdrive_smb_port.py (ex: curl -LO https://gist.githubusercontent.com/emersonford/85cc74f7f90c81d1b75c3c246124591d/raw/442834222e2aaa2be61badb6e84f53183ee10624/change_gdrive_smb_port.py).
  3. Read over the script yourself so you know it's safe to run.
  4. 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.
  5. Relaunch Google Drive.
  6. Run the mdutil -i on command the script spits out.
  7. 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 core_feature_config from ~/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 core_feature_config...

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!

Technical explanation


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
...
mac_smb_port: -1
...

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.


I know that most of you are interested in solving the problem when streaming Google Drive's content ("Stream Files" option on in 'Settings', see @kortina's screenshot).

But for those of you (like me) who ended up reading this post because Spotlight won't index your Drive folder despite using the "Mirror Files" option, the solution is simple: follow these directions and reboot.

Edit: here's the instructions:

Go to System Preferences/ Spotlight. Click the Privacy tab. Drag the Google Drive folder to the list of locations that Spotlight is prevented from searching. Wait a moment and then click the remove button (–) to remove it from the list. Quit System Preferences. Spotlight will now start indexing the folder, which you can verify looking at the active processes in Activity Monitor. When it's done, give your Mac a nice reboot.

Worked for me, will work for you!


This was driving me insane as well, and I was prepared to try setting up a cron to run the workaround python script from @emersonford (which looks great and thank you btw), but I think I may have found a better solution for my needs.

I noticed in GoogleDrive preferences under Google Drive > My Drive syncing options if you change from Stream to Mirror, and then choose a local folder (I did ~/gd), spotlight appears to index all the files!

Change from Streaming to Mirror

I just now turned this on and it appears to work so far, fingers crossed it continues.