From 6f2100c2f98fe5f7bf5d689f16c303dbfcfddb6a Mon Sep 17 00:00:00 2001 From: Boris Remizov Date: Tue, 3 Apr 2018 16:27:56 +0300 Subject: [PATCH 1/4] Failover in case of Spotlight disabled --- lib/xcode/install.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index e5d738af..6e1a4a6d 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -381,11 +381,13 @@ def fetch_seedlist end def installed - unless (`mdutil -s /` =~ /disabled/).nil? - raise 'Please enable Spotlight indexing for /Applications.' + if `mdutil -s /` =~ /disabled/ + `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") + else + `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n") end - - `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n") end def parse_seedlist(seedlist) From 38d49d65a8aab74ed78646a46bc792ae0719b937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Tue, 24 Apr 2018 12:18:40 +0300 Subject: [PATCH 2/4] Find Xcodes via `find` if spotlight returns empty --- lib/xcode/install.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 6e1a4a6d..5ad9917e 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -381,12 +381,11 @@ def fetch_seedlist end def installed - if `mdutil -s /` =~ /disabled/ - `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") - else - `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n") + 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 end From f878692ffb3ada3fdd0c2703947a0bdf01d1a283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Tue, 24 Apr 2018 14:55:48 +0300 Subject: [PATCH 3/4] Return value correctly --- lib/xcode/install.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/xcode/install.rb b/lib/xcode/install.rb index 5ad9917e..29d0f0cc 100644 --- a/lib/xcode/install.rb +++ b/lib/xcode/install.rb @@ -387,6 +387,7 @@ def installed 'if [ "$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" \ "{}/Contents/Info.plist" 2>/dev/null)" == "com.apple.dt.Xcode" ]; then echo "{}"; fi' ';'`.split("\n") end + result end def parse_seedlist(seedlist) From 662cfc3fb7d9216b14f09532b4d76869e893302d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Sun, 27 May 2018 09:07:55 +0300 Subject: [PATCH 4/4] [README] Explain Spotlight failure workaround --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41f745af..501ebc2e 100644 --- a/README.md +++ b/README.md @@ -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