subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bre...@apache.org
Subject svn commit: r1573096 - /subversion/trunk/subversion/libsvn_subr/sysinfo.c
Date Fri, 28 Feb 2014 22:11:00 GMT
Author: breser
Date: Fri Feb 28 22:11:00 2014
New Revision: 1573096

URL: http://svn.apache.org/r1573096
Log:
Stop using a deprecated (as of OS X 10.9) function to get OS X version.

CFURLCreateDataAndPropertiesFromResource() is not listed as being deprecated.
It still works but this code goes to a lot of effor to use OS X's
CoreFoundation framework to read the plist when we have our own functions
for reading files.  I think it's much better for our maintenance purposes to
use our functions for as much as we can.

* subversion/libsvn_subr/sysinfo.c
  (write_to_cfmutabledata): svn_write_fn_t implementation that feeds data into
    a CFMutableDataRef (Core Foundation's version of streams).

  (system_version_plist): Use our stream interface to read the plist files
    and wire it up to a stream that feeds the data to a CFMutableDataRef
    so we can still let OS X's property list code do the parsing for us.
    Also fix a small comment typo.

Modified:
    subversion/trunk/subversion/libsvn_subr/sysinfo.c

Modified: subversion/trunk/subversion/libsvn_subr/sysinfo.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sysinfo.c?rev=1573096&r1=1573095&r2=1573096&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sysinfo.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sysinfo.c Fri Feb 28 22:11:00 2014
@@ -901,64 +901,72 @@ win32_shared_libs(apr_pool_t *pool)
 
 
 #ifdef SVN_HAVE_MACOS_PLIST
+static svn_error_t *
+write_to_cfmutabledata(void *baton, const char *data, apr_size_t *len)
+{
+  CFMutableDataRef *resource = (CFMutableDataRef *) baton;
+
+  CFDataAppendBytes(*resource, (UInt8 *)data, *len);
+
+  return SVN_NO_ERROR;
+}
+
 /* Load the SystemVersion.plist or ServerVersion.plist file into a
    property list. Set SERVER to TRUE if the file read was
    ServerVersion.plist. */
 static CFDictionaryRef
 system_version_plist(svn_boolean_t *server, apr_pool_t *pool)
 {
-  static const UInt8 server_version[] =
+  static const char server_version[] =
     "/System/Library/CoreServices/ServerVersion.plist";
-  static const UInt8 system_version[] =
+  static const char system_version[] =
     "/System/Library/CoreServices/SystemVersion.plist";
-
+  svn_stream_t *read_stream, *write_stream;
+  svn_error_t *err;
   CFPropertyListRef plist = NULL;
-  CFDataRef resource = NULL;
+  CFMutableDataRef resource = CFDataCreateMutable(kCFAllocatorDefault, 0);
   CFStringRef errstr = NULL;
-  CFURLRef url = NULL;
-  SInt32 errcode;
-
-  url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
-                                                server_version,
-                                                sizeof(server_version) - 1,
-                                                FALSE);
-  if (!url)
-    return NULL;
 
-  if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
-                                                url, &resource,
-                                                NULL, NULL, &errcode))
+  /* Try to open the plist files to get the data */
+  err = svn_stream_open_readonly(&read_stream, server_version, pool, pool);
+  if (err)
     {
-      CFRelease(url);
-      url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
-                                                    system_version,
-                                                    sizeof(system_version) - 1,
-                                                    FALSE);
-      if (!url)
-        return NULL;
-
-      if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
-                                                    url, &resource,
-                                                    NULL, NULL, &errcode))
+      if (!APR_STATUS_IS_ENOENT(err->apr_err))
         {
-          CFRelease(url);
+          svn_error_clear(err);
           return NULL;
         }
       else
         {
-          CFRelease(url);
+          svn_error_clear(err);
+          err = svn_stream_open_readonly(&read_stream, system_version,
+                                         pool, pool);
+          if (err)
+            {
+              svn_error_clear(err);
+              return NULL;
+            }
+
           *server = FALSE;
         }
     }
   else
     {
-      CFRelease(url);
       *server = TRUE;
     }
 
+  write_stream = svn_stream_create(&resource, pool);
+  svn_stream_set_write(write_stream, write_to_cfmutabledata);
+  err = svn_stream_copy3(read_stream, write_stream, NULL, NULL, pool);
+  if (err) 
+    {
+      svn_error_clear(err);
+      return NULL;
+    }
+
   /* ### CFPropertyListCreateFromXMLData is obsolete, but its
          replacement CFPropertyListCreateWithData is only available
-         from Mac OS 1.6 onward. */
+         from Mac OS 10.6 onward. */
   plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource,
                                           kCFPropertyListImmutable,
                                           &errstr);



Mime
View raw message