Write directly to .reg files under symlinks

Bill Medland billmedland at mercuryspeed.com
Tue Dec 17 16:40:43 CST 2002


Bill Medland (medbi01 at accpac.com)
If a .reg function is accessed through a symlink then write
directly to the file rather than replacing it with a temp
file.  This preserves ownership and permissions.

Index: wine/server/registry.c
===================================================================
RCS file: /home/wine/wine/server/registry.c,v
retrieving revision 1.45
diff -u -r1.45 registry.c
--- wine/server/registry.c	10 Dec 2002 22:56:44 -0000	1.45
+++ wine/server/registry.c	17 Dec 2002 22:36:11 -0000
@@ -1583,7 +1583,7 @@
 static int save_branch( struct key *key, const char *path )
 {
     char *p, *real, *tmp = NULL;
-    int fd, count = 0, ret = 0;
+    int fd, count = 0, ret = 0, by_symlink;
     FILE *f;
 
     if (!(key->flags & KEY_DIRTY))
@@ -1594,6 +1594,10 @@
 
     /* get the real path */
 
+    {
+        struct stat st;
+        by_symlink = !(lstat (path, &st) != 0 || !S_ISLNK (st.st_mode));
+    }
     if (!(real = malloc( PATH_MAX ))) return 0;
     if (!realpath( path, real ))
     {
@@ -1607,9 +1611,11 @@
     if ((fd = open( path, O_WRONLY )) != -1)
     {
         struct stat st;
-        /* if file is not a regular file or has multiple links,
+        /* if file is not a regular file or has multiple links or is accessed
+         * via symbolic links,
            write directly into it; otherwise use a temp file */
-        if (!fstat( fd, &st ) && (!S_ISREG(st.st_mode) || st.st_nlink > 1))
+        if ((!fstat( fd, &st ) && (!S_ISREG(st.st_mode) || st.st_nlink > 1)) ||
+            by_symlink)
         {
             ftruncate( fd, 0 );
             goto save;
-- 
Bill Medland
ACCPAC International, Inc.



More information about the wine-patches mailing list