Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
a910e1ee
Commit
a910e1ee
authored
May 03, 2021
by
Vladislav Vaintroub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-25584 Implement posix semantics file deletion for Windows 10
parent
abe6eb10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
6 deletions
+27
-6
mysys/my_delete.c
mysys/my_delete.c
+27
-6
No files found.
mysys/my_delete.c
View file @
a910e1ee
...
...
@@ -58,6 +58,7 @@ int my_delete(const char *name, myf MyFlags)
#if defined (_WIN32)
/*
Delete file.
...
...
@@ -65,15 +66,14 @@ int my_delete(const char *name, myf MyFlags)
where another program (or thread in the current program) has the the same file
open.
We're using 2 tricks to prevent the errors.
We're using several tricks to prevent the errors, such as
- Windows 10 "posix semantics" delete
1. A usual Win32's DeleteFile() can with ERROR_SHARED_VIOLATION,
because the file is opened in another application (often, antivirus or backup)
We avoid the error by using CreateFile() with FILE_FLAG_DELETE_ON_CLOSE, instead
- Avoid the error by using CreateFile() with FILE_FLAG_DELETE_ON_CLOSE, instead
of DeleteFile()
2.
If file which is deleted (delete on close) but has not entirely gone,
-
If file which is deleted (delete on close) but has not entirely gone,
because it is still opened by some app, an attempt to trcreate file with the
same name would result in yet another error. The workaround here is renaming
a file to unique name.
...
...
@@ -116,6 +116,27 @@ static int my_win_unlink(const char *name)
DBUG_RETURN
(
0
);
}
/*
Try Windows 10 method, delete with "posix semantics" (file is not visible, and creating
a file with the same name won't fail, even if it the fiile was open)
*/
struct
{
DWORD
_Flags
;
}
disp
=
{
0x3
};
/* 0x3 = FILE_DISPOSITION_FLAG_DELETE | FILE_DISPOSITION_FLAG_POSIX_SEMANTICS */
handle
=
CreateFile
(
name
,
DELETE
,
FILE_SHARE_READ
|
FILE_SHARE_WRITE
|
FILE_SHARE_DELETE
,
NULL
,
OPEN_EXISTING
,
0
,
NULL
);
if
(
handle
!=
INVALID_HANDLE_VALUE
)
{
BOOL
ok
=
SetFileInformationByHandle
(
handle
,
(
FILE_INFO_BY_HANDLE_CLASS
)
21
,
&
disp
,
sizeof
(
disp
));
CloseHandle
(
handle
);
if
(
ok
)
DBUG_RETURN
(
0
);
}
handle
=
CreateFile
(
name
,
DELETE
,
0
,
NULL
,
OPEN_EXISTING
,
FILE_FLAG_DELETE_ON_CLOSE
,
NULL
);
if
(
handle
!=
INVALID_HANDLE_VALUE
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment