[Unison-hackers] osxsupport.c

Ben Willmore ben at opendarwin.org
Mon Sep 19 10:11:41 EDT 2005


As unison maintainer in Fink (mac os x), I inherited the included
patch against 2.10.2.  I wrongly assumed it had been incorporated into
newer versions.

Can anyone comment on the wisdom of including this?

Thanks,

Ben


diff -u -ruN unison.orig/unison-2.10.2/osxsupport.c
unison/unison-2.10.2/osxsupport.c
--- unison.orig/unison-2.10.2/osxsupport.c      2005-08-23
09:00:53.000000000 -0700
+++ unison/unison-2.10.2/osxsupport.c   2005-08-23 09:01:50.000000000 -0700
@@ -6,6 +6,8 @@
 #include <caml/alloc.h>
 #include <caml/memory.h>
 #ifdef __APPLE__
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/attr.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -115,6 +117,20 @@
   retcode = setattrlist(String_val (path), &attrList, attrBuf.finderInfo,
                         sizeof attrBuf.finderInfo, options);
 
+  if (retcode == -1 && errno == EACCES) {
+    /* Unlike with normal Unix attributes, we cannot set OS X attributes 
+       if file is read-only.  Try making it writable temporarily. */
+    struct stat st;
+    int r = stat(String_val(path), &st);
+    if (r == -1) uerror("setattrlist", path);
+    r = chmod(String_val(path), st.st_mode | S_IWUSR);
+    if (r == -1) uerror("setattrlist", path);
+    /* Try again */
+    retcode = setattrlist(String_val (path), &attrList, attrBuf.finderInfo,
+                          sizeof attrBuf.finderInfo, options);
+    /* Whether or not that worked, we should try to set the mode back. */
+    chmod(String_val(path), st.st_mode);
+  }
   if (retcode == -1) uerror("setattrlist", path);
 
   CAMLreturn (Val_unit);


More information about the Unison-hackers mailing list