Permalink
Browse files

Keep (installed) auth server up-to-date

The recent move to 64 bit broke the (binary) protocol used between TextMate and the server for authenticated reads/writes (since size_t is now 64 bit).

This fixes issue #354.
  • Loading branch information...
1 parent 022e296 commit 49ae19c527210830d825e56dc08ee7e613800367 @sorbits sorbits committed Aug 31, 2012
@@ -8,7 +8,7 @@
OAK_DEBUG_VAR(AuthServer);
-static double const AppVersion = 1.0;
+static double const AppVersion = 1.1;
static size_t const AppRevision = APP_REVISION;
extern char* optarg;
@@ -7,6 +7,6 @@
#define kAuthPlistPath "/Library/LaunchDaemons/com.macromates.auth_server.plist"
#define kAuthRightName "com.macromates.textmate.openfile"
#define kAuthServerMajor 3
-#define kAuthServerMinor 0
+#define kAuthServerMinor 1
#endif /* end of include guard: AUTH_CONSTANTS_H_7R7B65WN */
@@ -1,6 +1,8 @@
#include "server.h"
#include "constants.h"
#include <io/path.h>
+#include <io/exec.h>
+#include <regexp/regexp.h>
#include <OakSystem/application.h>
#include <oak/debug.h>
@@ -34,9 +36,28 @@ static bool install_auth_tool (osx::authorization_t const& auth)
return res;
}
+static double version_of_tool (std::string const& toolPath)
+{
+ std::string res = io::exec(toolPath, "--version", NULL);
+ if(regexp::match_t const& m = regexp::search("\\A[^\\s]+ ([\\d.]+)", res.data(), res.data() + res.size()))
+ return strtod(res.c_str() + m.begin(1), NULL);
+ return 0;
+}
+
+static bool auth_server_too_old ()
+{
+ if(path::exists(kAuthToolPath))
+ {
+ double oldVersion = version_of_tool(kAuthToolPath);
+ double newVersion = version_of_tool(oak::application_t::path("Contents/Resources/PrivilegedTool"));
+ return oldVersion < newVersion;
+ }
+ return true;
+}
+
connection_t connect_to_auth_server (osx::authorization_t const& auth, bool retry)
{
- if(!path::exists(kAuthToolPath) || !path::exists(kAuthPlistPath))
+ if(!path::exists(kAuthToolPath) || !path::exists(kAuthPlistPath) || auth_server_too_old())
{
if(!install_auth_tool(auth))
return connection_t();
@@ -1,4 +1,4 @@
SOURCES = src/*.cc
TEST_SOURCES = tests/t_*.cc
EXPORT = src/*.h
-LINK += io text OakSystem
+LINK += io text regexp OakSystem

0 comments on commit 49ae19c

Please sign in to comment.