www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - bug of File.open

reply "Y.Tomino" <demoonlit inter7.jp> writes:
Hello.

I think FileMode.In means read-only.
But, It will create new file !
Maybe, File.open must use OPEN_EXISTING instead of OPEN_ALWAYS.

YT

====================================
private import std.stream;

int main()
{
	File f = new File("xxx", FileMode.In);
	return 0;
}
====================================
D:\Programming\tests\D>del xxx

D:\Programming\tests\D>dir xxx
 Volume in drive D is DATA
 Volume Serial Number is 1018-17F3

 Directory of D:\Programming\tests\D

File Not Found

D:\Programming\tests\D>dmd a
C:\Program Files\DM\dmd\bin\..\..\dm\bin\link.exe a,,,user32+kernel32/noi;

D:\Programming\tests\D>a

D:\Programming\tests\D>dir xxx
 Volume in drive D is DATA
 Volume Serial Number is 1018-17F3

 Directory of D:\Programming\tests\D

2004-08-21  06:31                    0 xxx
               1 File(s)              0 bytes
               0 Dir(s)   9,673,768,960 bytes free

D:\Programming\tests\D>
Aug 20 2004
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
In article <cg5r40$qrs$1 digitaldaemon.com>, Y.Tomino says...
Hello.

I think FileMode.In means read-only.
But, It will create new file !
Maybe, File.open must use OPEN_EXISTING instead of OPEN_ALWAYS.

I think this bug was first reported a while back. Ben Hinkle recently proposed an improved version of std.stream that I think includes a fix for this problem: digitalmars.D/9051 "4) changed File open/create flags and one behavior. First, added a FileMode.Trunc to say a file should be truncated when opened. Also made the behavior on Windows match the behavior on linux when calling new File("foo",FileMode.In) and the file didn't exist. On Windows it would create an empty file in read-mode and on Linux it would error. Now it will error on both platforms. To open or create a file in write-mode and zero out the length run new File("foo",FileMode.Out | FileMode.Trunc);" Hopefully, we can get Walter to take the time to include a better version of std.stream with the compiler soon.
YT

====================================
private import std.stream;

int main()
{
	File f = new File("xxx", FileMode.In);
	return 0;
}
====================================
D:\Programming\tests\D>del xxx

D:\Programming\tests\D>dir xxx
 Volume in drive D is DATA
 Volume Serial Number is 1018-17F3

 Directory of D:\Programming\tests\D

File Not Found

D:\Programming\tests\D>dmd a
C:\Program Files\DM\dmd\bin\..\..\dm\bin\link.exe a,,,user32+kernel32/noi;

D:\Programming\tests\D>a

D:\Programming\tests\D>dir xxx
 Volume in drive D is DATA
 Volume Serial Number is 1018-17F3

 Directory of D:\Programming\tests\D

2004-08-21  06:31                    0 xxx
               1 File(s)              0 bytes
               0 Dir(s)   9,673,768,960 bytes free

D:\Programming\tests\D>

jcc7
Aug 20 2004
parent reply "Y.Tomino" <demoonlit inter7.jp> writes:
Thanks.
I'm sorry, I have not seen it.

YT

J C Calvarese wrote:
 In article <cg5r40$qrs$1 digitaldaemon.com>, Y.Tomino says...
 
Hello.

I think FileMode.In means read-only.
But, It will create new file !
Maybe, File.open must use OPEN_EXISTING instead of OPEN_ALWAYS.

I think this bug was first reported a while back. Ben Hinkle recently proposed an improved version of std.stream that I think includes a fix for this problem: digitalmars.D/9051 "4) changed File open/create flags and one behavior. First, added a FileMode.Trunc to say a file should be truncated when opened. Also made the behavior on Windows match the behavior on linux when calling new File("foo",FileMode.In) and the file didn't exist. On Windows it would create an empty file in read-mode and on Linux it would error. Now it will error on both platforms. To open or create a file in write-mode and zero out the length run new File("foo",FileMode.Out | FileMode.Trunc);" Hopefully, we can get Walter to take the time to include a better version of std.stream with the compiler soon.
YT

====================================
private import std.stream;

int main()
{
	File f = new File("xxx", FileMode.In);
	return 0;
}
====================================
D:\Programming\tests\D>del xxx

D:\Programming\tests\D>dir xxx
Volume in drive D is DATA
Volume Serial Number is 1018-17F3

Directory of D:\Programming\tests\D

File Not Found

D:\Programming\tests\D>dmd a
C:\Program Files\DM\dmd\bin\..\..\dm\bin\link.exe a,,,user32+kernel32/noi;

D:\Programming\tests\D>a

D:\Programming\tests\D>dir xxx
Volume in drive D is DATA
Volume Serial Number is 1018-17F3

Directory of D:\Programming\tests\D

2004-08-21  06:31                    0 xxx
              1 File(s)              0 bytes
              0 Dir(s)   9,673,768,960 bytes free

D:\Programming\tests\D>

jcc7

Aug 21 2004
parent J C Calvarese <jcc7 cox.net> writes:
Y.Tomino wrote:
 Thanks.
 I'm sorry, I have not seen it.

You're welcome. I was just letting you know that others agree it's a bug. I know it's impossible for a person to keep track of all these issues. Hopefully, it'll get fixed soon.
 
 YT
 
 J C Calvarese wrote:
 
In article <cg5r40$qrs$1 digitaldaemon.com>, Y.Tomino says...


Hello.

I think FileMode.In means read-only.
But, It will create new file !
Maybe, File.open must use OPEN_EXISTING instead of OPEN_ALWAYS.

I think this bug was first reported a while back. Ben Hinkle recently proposed an improved version of std.stream that I think includes a fix for this problem: digitalmars.D/9051 "4) changed File open/create flags and one behavior. First, added a FileMode.Trunc to say a file should be truncated when opened. Also made the behavior on Windows match the behavior on linux when calling new File("foo",FileMode.In) and the file didn't exist. On Windows it would create an empty file in read-mode and on Linux it would error. Now it will error on both platforms. To open or create a file in write-mode and zero out the length run new File("foo",FileMode.Out | FileMode.Trunc);" Hopefully, we can get Walter to take the time to include a better version of std.stream with the compiler soon.
YT

====================================
private import std.stream;

int main()
{
	File f = new File("xxx", FileMode.In);
	return 0;
}
====================================
D:\Programming\tests\D>del xxx

D:\Programming\tests\D>dir xxx
Volume in drive D is DATA
Volume Serial Number is 1018-17F3

Directory of D:\Programming\tests\D

File Not Found

D:\Programming\tests\D>dmd a
C:\Program Files\DM\dmd\bin\..\..\dm\bin\link.exe a,,,user32+kernel32/noi;

D:\Programming\tests\D>a

D:\Programming\tests\D>dir xxx
Volume in drive D is DATA
Volume Serial Number is 1018-17F3

Directory of D:\Programming\tests\D

2004-08-21  06:31                    0 xxx
             1 File(s)              0 bytes
             0 Dir(s)   9,673,768,960 bytes free

D:\Programming\tests\D>

jcc7


-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Aug 22 2004
prev sibling parent "Vathix" <vathixSpamFix dprogramming.com> writes:
"Y.Tomino" <demoonlit inter7.jp> wrote in message
news:cg5r40$qrs$1 digitaldaemon.com...
 Hello.

 I think FileMode.In means read-only.
 But, It will create new file !
 Maybe, File.open must use OPEN_EXISTING instead of OPEN_ALWAYS.

 YT

I use std.file.exists(fn) before opening with File. It's a hack. I posted a fix a long time ago, but it never got used; but I hope Ben Hinkle's std.stream updates get incorporated to fix it.
Aug 21 2004