[PATCH v2 2/5] ntdll: Check for an existing file on the server side.

Zebediah Figura z.figura12 at gmail.com
Tue Mar 10 22:38:23 CDT 2020


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/ntdll/file.c   | 16 ++--------------
 server/fd.c         | 10 ++++++++--
 server/protocol.def |  1 +
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 5ecf293820e..f59e737baa5 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -2778,18 +2778,12 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
             if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
                 break;
 
-            if (!info->ReplaceIfExists && io->u.Status == STATUS_SUCCESS)
-            {
-                RtlFreeAnsiString( &unix_name );
-                io->u.Status = STATUS_OBJECT_NAME_COLLISION;
-                break;
-            }
-
             SERVER_START_REQ( set_fd_name_info )
             {
                 req->handle   = wine_server_obj_handle( handle );
                 req->rootdir  = wine_server_obj_handle( attr.RootDirectory );
                 req->link     = FALSE;
+                req->replace  = info->ReplaceIfExists;
                 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
                 io->u.Status = wine_server_call( req );
             }
@@ -2821,18 +2815,12 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
             if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
                 break;
 
-            if (!info->ReplaceIfExists && io->u.Status == STATUS_SUCCESS)
-            {
-                RtlFreeAnsiString( &unix_name );
-                io->u.Status = STATUS_OBJECT_NAME_COLLISION;
-                break;
-            }
-
             SERVER_START_REQ( set_fd_name_info )
             {
                 req->handle   = wine_server_obj_handle( handle );
                 req->rootdir  = wine_server_obj_handle( attr.RootDirectory );
                 req->link     = TRUE;
+                req->replace  = info->ReplaceIfExists;
                 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
                 io->u.Status  = wine_server_call( req );
             }
diff --git a/server/fd.c b/server/fd.c
index 5d80e218b97..c2cb3c96ac6 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -2325,7 +2325,7 @@ static void set_fd_disposition( struct fd *fd, int unlink )
 
 /* set new name for the fd */
 static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
-                         data_size_t len, int create_link )
+                         data_size_t len, int create_link, int replace )
 {
     struct inode *inode;
     struct stat st;
@@ -2367,6 +2367,12 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
 
     if (!stat( name, &st ))
     {
+        if (!replace)
+        {
+            set_error( STATUS_OBJECT_NAME_COLLISION );
+            goto failed;
+        }
+
         /* can't replace directories or special files */
         if (!S_ISREG( st.st_mode ))
         {
@@ -2695,7 +2701,7 @@ DECL_HANDLER(set_fd_name_info)
 
     if ((fd = get_handle_fd_obj( current->process, req->handle, 0 )))
     {
-        set_fd_name( fd, root_fd, get_req_data(), get_req_data_size(), req->link );
+        set_fd_name( fd, root_fd, get_req_data(), get_req_data_size(), req->link, req->replace );
         release_object( fd );
     }
     if (root_fd) release_object( root_fd );
diff --git a/server/protocol.def b/server/protocol.def
index 6c44b2b43f5..722993e59c7 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -3809,6 +3809,7 @@ struct handle_info
     obj_handle_t handle;          /* handle to a file or directory */
     obj_handle_t rootdir;         /* root directory */
     int          link;            /* link instead of renaming */
+    int          replace;         /* replace an existing file? */
     VARARG(filename,string);      /* new file name */
 @END
 
-- 
2.25.1




More information about the wine-devel mailing list