[erlang-questions] Problem in file:rawopen/2

Matthias Lang matthias@REDACTED
Sun Feb 24 10:08:27 CET 2008

 > > Sumith Gamage writes:
 > > 
 > >  > I use following code segment to copy directory in Linux.
 > > 
 > >  >     {ok, OutFd} = file:rawopen(Dest, {binary, write}),
 > > 
 > >  > I used the same code in Windows it fails with the same even 
 > >  > with the same Erlang version (I tried with 5.5.5 & 5.6 both).
 > > 
 > >  > Kindly suggest me a workaround for this.

 Matthias>> file:rawopen/2 isn't documented.

 Matthias>> Looking at the library source, there's a comment above
 Matthias>> rawopen:

 Matthias>> %% Obsolete, undocumented, local node only, don't use!

    Kostis> Matt is of course right in pointing out these, but this
    Kostis> really begs the questions:

    Kostis> - Since this function is obsolete, why does it survive
    Kostis> across multiple OTP releases?

    Kostis> - Assuming the previous question has a good answer, why
    Kostis> aren't such functions marked as obsolete so that at least
    Kostis> the compiler warns for its uses?

Taking a few steps back at this problem, Sumith is trying to copy a
directory by opening it as a file and copying the contents. This is a
trick, i.e. it exploits knowledge about how directories are
implemented in some operating systems. He's then combining that first
trick with a second trick, namely using an undocumented function. That
has "will probably blow up in your face" written all over it.

Taking a guess, on Windows directories are implemented such that the
'a directory is a file' abstraction doesn't hold. Maybe someone who
actually knows something about windows can confirm.

Back to Kostis, who already knows the answer to "why is it still
there", but I'll bite anyway:

  ic/src/icenum.erl:    case file:rawopen(FName, {binary, write}) of
  ic/src/icstruct.erl:    case file:rawopen(FName, {binary, write}) of
  ic/src/icstruct.erl:        case file:rawopen(FName, {binary, write}) of
  ic/src/icstruct.erl:    case file:rawopen(FName, {binary, write}) of
  ic/src/icunion.erl:    case file:rawopen(FName, {binary, write}) of
  mnesia/src/mnesia_lib.erl:    case file:rawopen(Fname, read) of
  mnesia/src/mnesia_lib.erl:    case file:rawopen(From, {binary, read}) of
  mnesia/src/mnesia_lib.erl:          case file:rawopen(To, {binary, write}) of

A warning wouldn't hurt, though compiler-administered electric 
shocks would be more effective.


More information about the erlang-questions mailing list