[Unison-hackers] osxsupport.c

Benjamin Pierce bcpierce at cis.upenn.edu
Mon Sep 19 10:16:57 EDT 2005


I won't comment on the code now because I didn't write it and don't  
have a good feeling for the circumstances under which a crash could  
leave a read-only file in a writeable state, but a general comment  
would be that having different flavors of Unison behave differently  
on the very same OS is sure to be a bad thing: the patch should  
definitely either be thrown away or get incorporated into the main  
sources.

    - B


On Sep 19, 2005, at 10:11 AM, Ben Willmore wrote:

> 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);
> _______________________________________________
> Unison-hackers mailing list
> Unison-hackers at lists.seas.upenn.edu
> http://lists.seas.upenn.edu/mailman/listinfo/unison-hackers
>



More information about the Unison-hackers mailing list