Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to recover when Spotlight returns no results by searching /Applications folder #281

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ XcodeInstall automatically installs additional components so that it is immediat
commandline. Unfortunately, Xcode will load third-party plugins even in that situation, which leads
to a dialog popping up. Feel free to dupe [the radar][5]. 📡

XcodeInstall uses the Spotlight index to locate installed versions of Xcode. If you use it while
XcodeInstall normally relies on the Spotlight index to locate installed versions of Xcode. If you use it while
indexing is happening, it might show inaccurate results and it will not be able to see installed
versions on unindexed volumes.
versions on unindexed volumes.

To workaround the Spotlight limitation, XcodeInstall searches `/Applications` folder to locate Xcodes when Spotlight is disabled on the machine, or when Spotlight query for Xcode does not return any results. But it still won't work if your Xcodes are located under `/Applications` folder.

## Thanks

Expand Down
10 changes: 6 additions & 4 deletions lib/xcode/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,13 @@ def fetch_seedlist
end

def installed
unless (`mdutil -s /` =~ /disabled/).nil?
raise 'Please enable Spotlight indexing for /Applications.'
result = `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n")
if result.empty?
result = `find /Applications -name '*.app' -type d -maxdepth 1 -exec sh -c \
'if [ "$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" \
"{}/Contents/Info.plist" 2>/dev/null)" == "com.apple.dt.Xcode" ]; then echo "{}"; fi' ';'`.split("\n")
end

`mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n")
result
end

def parse_seedlist(seedlist)
Expand Down