Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkdir($file) succeeds if $file exists and is a regular file #5193

Closed
p6rt opened this issue Mar 23, 2016 · 9 comments
Closed

mkdir($file) succeeds if $file exists and is a regular file #5193

p6rt opened this issue Mar 23, 2016 · 9 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 23, 2016

Migrated from rt.perl.org#127772 (status was 'open')

Searchable as RT127772$

@p6rt
Copy link
Author

p6rt commented Mar 23, 2016

From @hoelzro

To reproduce​:

  $ touch /tmp/my-fake-directory
  $ perl6 -e 'say ?mkdir("/tmp/my-fake-directory")'
  True

I understand that we want to succeed in the common case that that directory already exists, but I'm wondering if that's the correct behavior and whether we should leave handling that case up to the user.

@p6rt
Copy link
Author

p6rt commented Mar 23, 2016

From @lizmat

On 23 Mar 2016, at 14​:16, Rob Hoelz (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Rob Hoelz
# Please include the string​: [perl #​127772]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127772 >

To reproduce​:

$ touch /tmp/my-fake-directory
$ perl6 -e 'say ?mkdir("/tmp/my-fake-directory")'
True

I understand that we want to succeed in the common case that that directory already exists, but I'm wondering if that's the correct behavior and whether we should leave handling that case up to the user.

FWIW, I think this is really a problem in the lower level nqp​::mkdir() always returning True.

@p6rt
Copy link
Author

p6rt commented Mar 23, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 23, 2016

From 1parrota@gmail.com

If a name's already in use, what's the right response to an attempt to
over-write it?
For a regular file, if it's write-enabled, doing so might be the right
response, since that's consistent with the current behaviour.
For a directory, attempting to re-use an existing name is more likely
to be an error, regardless of the nature of the named file. In that
case it should fail, and indicate that it has done so.

On 3/23/16, Elizabeth Mattijsen <liz@​dijkmat.nl> wrote​:

On 23 Mar 2016, at 14​:16, Rob Hoelz (via RT)
<perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Rob Hoelz
# Please include the string​: [perl #​127772]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127772 >

To reproduce​:

$ touch /tmp/my-fake-directory
$ perl6 -e 'say ?mkdir("/tmp/my-fake-directory")'
True

I understand that we want to succeed in the common case that that
directory already exists, but I'm wondering if that's the correct behavior
and whether we should leave handling that case up to the user.

FWIW, I think this is really a problem in the lower level nqp​::mkdir()
always returning True.

@p6rt
Copy link
Author

p6rt commented Mar 23, 2016

From @hoelzro

On 2016-03-23 09​:20​:42, 1parrota@​gmail.com wrote​:

If a name's already in use, what's the right response to an attempt to
over-write it?

Personally, I think we should propagate this error to the user and let them handle it.

For a regular file, if it's write-enabled, doing so might be the right
response, since that's consistent with the current behaviour.

Let's say I have a regular file, "output.log", which has a lot of useful information, and I try to mkdir("output.log"). If it blows away the file in order to make output.log into a directory, I would consider that seriously LTA. While I think that trying to be convenient to the user is a good thing, I think offering too much convenience to the user can do more harm than help.

For a directory, attempting to re-use an existing name is more likely
to be an error, regardless of the nature of the named file. In that
case it should fail, and indicate that it has done so.

On 3/23/16, Elizabeth Mattijsen <liz@​dijkmat.nl> wrote​:

On 23 Mar 2016, at 14​:16, Rob Hoelz (via RT)
<perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Rob Hoelz
# Please include the string​: [perl #​127772]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127772 >

To reproduce​:

$ touch /tmp/my-fake-directory
$ perl6 -e 'say ?mkdir("/tmp/my-fake-directory")'
True

I understand that we want to succeed in the common case that that
directory already exists, but I'm wondering if that's the correct
behavior
and whether we should leave handling that case up to the user.

FWIW, I think this is really a problem in the lower level
nqp​::mkdir()
always returning True.

@p6rt
Copy link
Author

p6rt commented Sep 19, 2017

From ngaywood@gmail.com

I'd like to see the same behavior that occurs in perl5. That is​:

  DB<3> mkdir "existingfile" or warn "$!\n"
File exists
DB<4> mkdir "/" or warn "$!\n"
File exists
DB<5> mkdir "/root/noway" or warn "$!\n"
Permission denied
  DB<6> mkdir "newdir" or warn "$!\n"

  DB<7> mkdir "newdir" or warn "$!\n"
File exists

@p6rt p6rt added the IO label Jan 5, 2020
@usev6
Copy link

usev6 commented Apr 11, 2021

Some more discussion about mkdir's behaviour can be found here: rakudo/rakudo#1357

@usev6
Copy link

usev6 commented Apr 11, 2021

I also think that mkdir($file) should signal a failure if there is already a file with that name.

It doesn't do this on current MoarVM:

$ : >a-file; ./rakudo-m -e 'my $res := mkdir("a-file"); dd $res'; ls -l a-file
IO::Path.new("a-file", :SPEC(IO::Spec::Unix), :CWD("/path/to/pwd"))
-rw-r--r--  1 christian  christian  0 Apr 11 19:05 a-file

On the JVM backend mkdir returns a failure:

$ : >a-file; ./rakudo-j -e 'my $res := mkdir("a-file"); dd $res'; ls -l a-file
Failure.new(exception => X::IO::Mkdir.new(path => "/path/to/pwd/a-file", mode => 511, os-error => "File /path/to/pwd/a-file already exists"), backtrace => Backtrace.new)
-rw-r--r--  1 christian  christian  0 Apr 11 19:10 a-file

@usev6
Copy link

usev6 commented Nov 23, 2022

I believe this has been fixed by now:

$ : >a-file; ./rakudo-m -e 'my $res := mkdir("a-file"); dd $res'; ls -l a-file
Failure.new(exception => X::IO::Mkdir.new(path => "/path/to/pwd/a-file", mode => 511, os-error => "Failed to mkdir: File exists"), backtrace => Backtrace.new)
-rw-r--r--  1 christian  christian  0 Nov 23 19:50 a-file

Fix for MoarVM: MoarVM/MoarVM#1507 (with two follow ups: MoarVM/MoarVM@6ef4dd3cb1 and MoarVM/MoarVM#1727).

Tests have been added to Rakudo (rakudo/rakudo#4408) and Roast (Raku/roast#736).

So I think it is fine to close this issue as resolved.

@usev6 usev6 closed this as completed Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants