fmShareDenyNone behaviour incorrect
Original Reporter info from Mantis: CCRDude @ccrdude
-
Reporter name:
Original Reporter info from Mantis: CCRDude @ccrdude
- Reporter name:
Description:
Whoever implemented do_open in rtl\win\sysfile.inc did make the same mistake as Borland did in SysUtils.pas: fmshareDenyNone does not include the delete flag for NT-Based systems!
The name "fmShareDenyNone" kind of implies that no action would be denied. But do_open is wrong there - it only uses "shflags := file_Share_Read + file_Share_Write", but ignores file_Share_Delete. Thus, what is called "denied none" does actually deny removal of files while open.
Microsofts documentation on CreateFile etc., including file modes:
http://msdn2.microsoft.com/en-us/library/aa363858.aspx
To test this, try the following code on an NT-based system:
--------------------------------------------
var fs: TFileStream;
begin
fs := TFileStream.Create('c:\filestreamtest.txt', fmOpenRead or fmShareDenyNone);
if not DeleteFile('c:\filestreamtest.txt') then
WriteLn('FPC says none, but denies removal anyway!');
fs.Free;
end.
----------------------------------------------
It fails, printing the error message.
What is missing in sysfile.inc, line 245 would be something like:
if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 4)
then shflags := file_Share_Read + file_Share_Write + file_Share_Delete
else shflags := file_Share_Read + file_Share_Write;
(because, IMPORTANT: the flag may NOT be set on 9x based systems)
Additional information:
Same bug reported by me in Borlands RTL:
http://qc.codegear.com/wc/qcmain.aspx?d=45628
While I have tested the Delphi fix for two weeks all over my code, the attached patch is just an untested suggestion (since I've not set up my code testing system to build the RTL as well on doing a new build).
(also not sure if this really is 2.1.5 ... my last 2.1.5 download did report version 2.0.4)
Mantis conversion info:
- Mantis ID: 8898
- Version: 2.2.0
- Fixed in version: 2.4.0
- Fixed in revision: 13522 (#65690b9e)