server: Allow renaming a file to the same name.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
ee136f9832
commit
6971fd2d61
|
@ -2123,8 +2123,8 @@ static void test_file_rename_information(void)
|
||||||
|
|
||||||
U(io).Status = 0xdeadbeef;
|
U(io).Status = 0xdeadbeef;
|
||||||
res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
|
res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
|
||||||
todo_wine ok( U(io).Status == STATUS_SUCCESS, "got io status %#x\n", U(io).Status );
|
ok( U(io).Status == STATUS_SUCCESS, "got io status %#x\n", U(io).Status );
|
||||||
todo_wine ok( res == STATUS_SUCCESS, "got status %x\n", res );
|
ok( res == STATUS_SUCCESS, "got status %x\n", res );
|
||||||
ok( GetFileAttributesW( oldpath ) != INVALID_FILE_ATTRIBUTES, "file should exist\n" );
|
ok( GetFileAttributesW( oldpath ) != INVALID_FILE_ATTRIBUTES, "file should exist\n" );
|
||||||
|
|
||||||
CloseHandle( handle );
|
CloseHandle( handle );
|
||||||
|
@ -2782,8 +2782,8 @@ static void test_file_link_information(void)
|
||||||
fli->ReplaceIfExists = TRUE;
|
fli->ReplaceIfExists = TRUE;
|
||||||
U(io).Status = 0xdeadbeef;
|
U(io).Status = 0xdeadbeef;
|
||||||
res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
|
res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
|
||||||
todo_wine ok( U(io).Status == STATUS_SUCCESS, "got io status %#x\n", U(io).Status );
|
ok( U(io).Status == STATUS_SUCCESS, "got io status %#x\n", U(io).Status );
|
||||||
todo_wine ok( res == STATUS_SUCCESS, "got status %x\n", res );
|
ok( res == STATUS_SUCCESS, "got status %x\n", res );
|
||||||
ok( GetFileAttributesW( oldpath ) != INVALID_FILE_ATTRIBUTES, "file should exist\n" );
|
ok( GetFileAttributesW( oldpath ) != INVALID_FILE_ATTRIBUTES, "file should exist\n" );
|
||||||
|
|
||||||
CloseHandle( handle );
|
CloseHandle( handle );
|
||||||
|
|
21
server/fd.c
21
server/fd.c
|
@ -2328,7 +2328,7 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
|
||||||
data_size_t len, int create_link, int replace )
|
data_size_t len, int create_link, int replace )
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct stat st;
|
struct stat st, st2;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
if (!fd->inode || !fd->unix_name)
|
if (!fd->inode || !fd->unix_name)
|
||||||
|
@ -2336,6 +2336,12 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
|
||||||
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (fd->unix_fd == -1)
|
||||||
|
{
|
||||||
|
set_error( fd->no_fd_status );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!len || ((nameptr[0] == '/') ^ !root))
|
if (!len || ((nameptr[0] == '/') ^ !root))
|
||||||
{
|
{
|
||||||
set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
|
set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
|
||||||
|
@ -2358,8 +2364,7 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* when creating a hard link, source cannot be a dir */
|
/* when creating a hard link, source cannot be a dir */
|
||||||
if (create_link && fd->unix_fd != -1 &&
|
if (create_link && !fstat( fd->unix_fd, &st ) && S_ISDIR( st.st_mode ))
|
||||||
!fstat( fd->unix_fd, &st ) && S_ISDIR( st.st_mode ))
|
|
||||||
{
|
{
|
||||||
set_error( STATUS_FILE_IS_A_DIRECTORY );
|
set_error( STATUS_FILE_IS_A_DIRECTORY );
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -2367,6 +2372,13 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
|
||||||
|
|
||||||
if (!stat( name, &st ))
|
if (!stat( name, &st ))
|
||||||
{
|
{
|
||||||
|
if (!fstat( fd->unix_fd, &st2 ) && st.st_ino == st2.st_ino && st.st_dev == st2.st_dev)
|
||||||
|
{
|
||||||
|
if (create_link && !replace) set_error( STATUS_OBJECT_NAME_COLLISION );
|
||||||
|
free( name );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!replace)
|
if (!replace)
|
||||||
{
|
{
|
||||||
set_error( STATUS_OBJECT_NAME_COLLISION );
|
set_error( STATUS_OBJECT_NAME_COLLISION );
|
||||||
|
@ -2394,8 +2406,7 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
|
||||||
|
|
||||||
/* link() expects that the target doesn't exist */
|
/* link() expects that the target doesn't exist */
|
||||||
/* rename() cannot replace files with directories */
|
/* rename() cannot replace files with directories */
|
||||||
if (create_link || (fd->unix_fd != -1 &&
|
if (create_link || S_ISDIR( st2.st_mode ))
|
||||||
!fstat( fd->unix_fd, &st ) && S_ISDIR( st.st_mode )))
|
|
||||||
{
|
{
|
||||||
if (unlink( name ))
|
if (unlink( name ))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue