Skip to content

$! not set properly for unlink on < 5.18 #78

@toddr

Description

@toddr

I found a bug today switching Test::MockFile over to github actions.

https://github.com/cpanel/Test-MockFile/runs/418056154?check_suite_focus=true

You can see the test failure here:

2020-01-30T21:04:02.1945833Z t/touch.t .. 
2020-01-30T21:04:02.1947864Z # Seeded srand with seed '20200130' from local date.
2020-01-30T21:04:02.1955248Z # -------------- REAL MODE --------------
2020-01-30T21:04:02.1956268Z ok 1 - /tmp/OkmKzp4LAr is there
2020-01-30T21:04:02.1957157Z ok 2 - unlink on a dir fails
2020-01-30T21:04:02.1958021Z not ok 3 - unlink /dir is non-zero (0)
2020-01-30T21:04:02.1958467Z 
2020-01-30T21:04:02.1959272Z # Failed test 'unlink /dir is non-zero (0)'
2020-01-30T21:04:02.1960789Z # at t/touch.t line 20.
2020-01-30T21:04:02.1961664Z # -------------- MOCK MODE --------------
2020-01-30T21:04:02.1962537Z ok 4 - unlink /link works.
2020-01-30T21:04:02.1963361Z ok 5 - /link is now gone
2020-01-30T21:04:02.1964188Z not ok 6 -    ... and throws a $!
2020-01-30T21:04:02.1964668Z 
2020-01-30T21:04:02.1965141Z # Failed test '   ... and throws a $!'
2020-01-30T21:04:02.1965452Z # at t/touch.t line 35.
2020-01-30T21:04:02.1965915Z # +-----+----+-------+
2020-01-30T21:04:02.1966217Z # | GOT | OP | CHECK |
2020-01-30T21:04:02.1966670Z # +-----+----+-------+
2020-01-30T21:04:02.1966992Z # | 21  | eq | 0     |
2020-01-30T21:04:02.1967450Z # +-----+----+-------+
2020-01-30T21:04:02.1967938Z ok 7 - touch /dir doesn't work.
2020-01-30T21:04:02.1968441Z ok 8 - touch /link doesn't work.
2020-01-30T21:04:02.1968925Z ok 9 - Set mtime to 1970
2020-01-30T21:04:02.1969398Z ok 10 - Set ctime to 1970
2020-01-30T21:04:02.1969887Z ok 11 - Set atime to 1970
2020-01-30T21:04:02.1970385Z ok 12 - Touch a missing file.
2020-01-30T21:04:02.1970873Z ok 13 - mtime is set.
2020-01-30T21:04:02.1971343Z ok 14 - ctime is set.
2020-01-30T21:04:02.1971822Z ok 15 - atime is set.
2020-01-30T21:04:02.1972644Z ok 16 - /file exists with -e
2020-01-30T21:04:02.1973184Z ok 17 - /file is removed via unlink method
2020-01-30T21:04:02.1973697Z ok 18 - /file is missing via contents check
2020-01-30T21:04:02.1976357Z ok 19 - /file is missing via size method
2020-01-30T21:04:02.1976755Z ok 20 - /file is removed via -e check
2020-01-30T21:04:02.1977039Z ok 21 - Set file to have stuff in it.
2020-01-30T21:04:02.1977313Z ok 22 - Touch an existing file.
2020-01-30T21:04:02.1977577Z ok 23 - mtime is set to 1234.
2020-01-30T21:04:02.1977849Z ok 24 - ctime is set to 1234.
2020-01-30T21:04:02.1978135Z ok 25 - atime is set to 1234.
2020-01-30T21:04:02.1978243Z 1..25
2020-01-30T21:04:02.1978332Z Dubious, test returned 2 (wstat 512, 0x200)
2020-01-30T21:04:02.1978438Z Failed 2/25 subtests 
2020-01-30T21:04:02.1978488Z 
2020-01-30T21:04:02.1978590Z Test Summary Report
2020-01-30T21:04:02.1978846Z -------------------
2020-01-30T21:04:02.1978953Z t/touch.t (Wstat: 512 Tests: 25 Failed: 2)
2020-01-30T21:04:02.1979047Z   Failed tests:  3, 6

The issue appears to be that $! is not set when unlink is tried on a directory.

I simplified this problem to do: mkdir -p /tmp/foo; ls -ld /tmp/foo; perl -E'CORE::unlink "/tmp/foo"; print $! + 0; print "\n"'; ls -ld /tmp/foo

On everything above 5.18, I get:

drwxr-xr-x 2 root root 4096 Jan 30 21:45 /tmp/foo
21
drwxr-xr-x 2 root root 4096 Jan 30 21:45 /tmp/foo

On everything at and below 5.18, I get:

drwxr-xr-x 2 root root 4096 Jan 30 21:45 /tmp/foo
0
drwxr-xr-x 2 root root 4096 Jan 30 21:45 /tmp/foo

For whatever reason, perl is broken subtly on the older perls OR jesse is a problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions