Hi all,
I''ve committed an alpha version of File.nopen (native open) to
win32-file. This is a wrapper for CreateFile(). A quick synopsis:
* File.nopen(file,access_mode,share_mode,creation_mode,flags)
*
* A ''native'' open method. This uses CreateFile() behind the
scenes
instead of
* the _open() function. This allows much greater flexibility when it
comes
* to Windows files. It also allows you to open directories, which
File.open
* cannot do on Windows.
*
* The access mode defaults to READ_DATA | WRITE_DATA
* The share mode defaults to SHARE_READ | SHARE_WRITE
* The creation mode defaults to OPEN_EXISTING
* The flags default to NORMAL
*
* To open a directory, pass File::BACKUP_SEMANTICS as the
''flags''
argument.
So, with this I can do:
dir = "C:\\TEST" # directory
fh = File.nopen(dir,nil,nil,nil,File::BACKUP_SEMANTICS)
p fh # Yup, it''s a File object
p fh.class # File
fh.close
I can also open a plain file and read the contents. So far, so good.
But, when I try to write to the file, I get an IOError claiming the file
isn''t opened for writing. Shouldn''t the WRITE_DATA flag have
given me
permission to write? I tried combinations of some other flags with no
luck.
Also, I noticed that if I try to use some of the new instance methods
like this:
fh = File.nopen("C:\\temp.txt",File::WRITE_ATTRIBUTES)
fh.hidden = true
fh.close
I get "test.rb:16:in `hidden='': cannot convert nil into String
(TypeError)"
Any ideas on these?
Please take a look and also let me know what you think in general of an
nopen() method.
Regards,
Dan
Just a quick followup:> I can also open a plain file and read the contents. So far, > so good. But, when I try to write to the file, I get an > IOError claiming the file isn''t opened for writing. > Shouldn''t the WRITE_DATA flag have given me permission to > write? I tried combinations of some other flags with no luck.For a second I thought it was this line causing the problems: fd = _open_osfhandle((long)h,O_RDONLY); But, changing that to O_RDWR had no effect. Dan
Hi,> > Hi all, > > I''ve committed an alpha version of File.nopen (native open) to > win32-file. This is a wrapper for CreateFile(). A quick synopsis: > > * File.nopen(file,access_mode,share_mode,creation_mode,flags) > * > * A ''native'' open method. This uses CreateFile() behind the scenes > instead of > * the _open() function. This allows much greater flexibility when it > comes > * to Windows files. It also allows you to open directories, which > File.open > * cannot do on Windows. > * > * The access mode defaults to READ_DATA | WRITE_DATA > * The share mode defaults to SHARE_READ | SHARE_WRITE > * The creation mode defaults to OPEN_EXISTING > * The flags default to NORMAL > * > * To open a directory, pass File::BACKUP_SEMANTICS as the ''flags'' > argument. > > So, with this I can do: > > dir = "C:\\TEST" # directory > fh = File.nopen(dir,nil,nil,nil,File::BACKUP_SEMANTICS) > p fh # Yup, it''s a File object > p fh.class # File > fh.close > > I can also open a plain file and read the contents. So far, so good. > But, when I try to write to the file, I get an IOError claiming the file > isn''t opened for writing. Shouldn''t the WRITE_DATA flag have given me > permission to write? I tried combinations of some other flags with no > luck. > > Also, I noticed that if I try to use some of the new instance methods > like this: > > fh = File.nopen("C:\\temp.txt",File::WRITE_ATTRIBUTES) > fh.hidden = true > fh.close > > I get "test.rb:16:in `hidden='': cannot convert nil into String > (TypeError)" > > Any ideas on these? > > Please take a look and also let me know what you think in general of an > nopen() method. >WARNING: You are gone too far into the ruby core :-) I think the Ruby developer should implement the win32 open function compatible with unix. We might take over nopen function to win32 expert ruby developer like NAKAMURA Usaku <usa@ruby-lang.org> or Nobuyoshi Nakada <nobu@ruby-lang.org>. Regards, Park Heesob --MIME Multi-part separator--
> > > WARNING: You are gone too far into the ruby core :-) > > I think the Ruby developer should implement the win32 open > function compatible with unix. We might take over nopen > function to win32 expert ruby developer like NAKAMURA Usaku > <usa@ruby-lang.org> or Nobuyoshi Nakada <nobu@ruby-lang.org>. > > Regards, > > Park HeesobHow would you make a native win32 open function Unix compatible? I don''t follow. Of course, I certainly wouldn''t mind if Nobu were to join Win32Utils. :) In other news, I''ve eliminated the path issue by aliasing File#path, and then redefining it. If the original File#path fails, it resorts to GetFullPathName(). Seems to work just fine. As for the write issue, it looks like it''s being caused by the rb_io_check_writable() function in io.c. I''ll dig deeper into this. - Dan