Git Product home page Git Product logo

Comments (6)

domenkozar avatar domenkozar commented on June 12, 2024

Invoked from Cabal:

$ git grep "getDirectoryContents "
Cabal/Distribution/PackageDescription/Check.hs:      getDirectoryContents = System.Directory.getDirectoryContents . relative,
Cabal/Distribution/PackageDescription/Check.hs:    getDirectoryContents :: FilePath -> m [FilePath],
Cabal/Distribution/PackageDescription/Check.hs:      files <- getDirectoryContents ops dir
Cabal/Distribution/Simple/GHC/Internal.hs:        objss <- mapM getDirectoryContents dirs
Cabal/Distribution/Simple/LHC.hs:        objss <- mapM getDirectoryContents dirs
Cabal/Distribution/Simple/Test.hs:    getDirectoryContents testLogDir
Cabal/Distribution/Simple/UHC.hs:          mapM (\ d -> getDirectoryContents d >>= filterM (isPkgDir (display compilerid) d))
Cabal/Distribution/Simple/Utils.hs:      (files, dirs') <- collect [] [] =<< getDirectoryContents (topdir </> dir)
Cabal/Distribution/Simple/Utils.hs:    files <- getDirectoryContents (dir </> dir')
Cabal/Distribution/Simple/Utils.hs: = do files <- getDirectoryContents dir
Cabal/Distribution/Simple/Utils.hs:    files <- getDirectoryContents dir

from unix.

nh2 avatar nh2 commented on June 12, 2024

From the man page on the readdir syscall on Linux;

EINVAL Result buffer is too small.

But this is on OSX, not sure if it's the same there.

I'm not sure how to look up when readdir() should return EINVAL on OSX. Their man page doesn't list any error codes.. According to https://apple.stackexchange.com/questions/239484/does-apple-provide-a-web-site-with-content-of-man-pages-for-the-command-line-c

Many of the Apple man pages do not keep up with the actual program options

Can we obtain the source code of the current version of readdir() in OSX?


Also, I found this golang commit from 2 years ago that says:

On OS X 10.10 Yosemite, if you have a directory that can be returned
in a single getdirentries64 call (for example, a directory with one file),
and you read from the directory at EOF twice, you get EOF both times:
        fd = open("dir")
        getdirentries64(fd) returns data
        getdirentries64(fd) returns 0 (EOF)
        getdirentries64(fd) returns 0 (EOF)

But if you remove the file in the middle between the two calls, the
second call returns an error instead.
        fd = open("dir")
        getdirentries64(fd) returns data
        getdirentries64(fd) returns 0 (EOF)
        remove("dir/file")
        getdirentries64(fd) returns ENOENT/EINVAL

Whether you get ENOENT or EINVAL depends on exactly what was
in the directory. It is deterministic, just data-dependent.

This only happens in small directories. A directory containing more data
than fits in a 4k getdirentries64 call will return EOF correctly.
(It's not clear if the criteria is that the directory be split across multiple
getdirentries64 calls or that it be split across multiple file system blocks.)

So it sounds like it's an OSX bug introduced in 10.10.

Further

C program reproducing the issue, also at http://swtch.com/~rsc/readdirbug.c:

@domenkozar Could you try this C program they mention?

At the end they write

I filed Apple Bug 17978656.

But apparently Apple bugs aren't public? Very useful :/

from unix.

domenkozar avatar domenkozar commented on June 12, 2024

The bug happens on macOS 10.12 (xcode 8.3) so it's still present. I can't try the C program on travis-ci easily, but I'll test in another Sierra box.

from unix.

hs-viktor avatar hs-viktor commented on June 12, 2024

Is this still an issue with current MacOS versions (Monterey or other recent)?

from unix.

andreasabel avatar andreasabel commented on June 12, 2024

Is this still an issue with current MacOS versions (Monterey or other recent)?

Is there a reproducer? (Otherwise I cannot test it.)

The C reproducer quoted above does not indicate a problem on Mac OS Mojave (10.14):

$ gcc readdirbug.c 
$ ./a.out 
mkdir /tmp/readdirbug
create /tmp/readdirbug/file1

opendir /tmp/readdirbug
readdir: found .
readdir: found ..
readdir: found file1
readdir: EOF
readdir: EOF
readdir: EOF
closedir

opendir /tmp/readdirbug
readdir: found .
readdir: found ..
readdir: found file1
readdir: EOF
rm /tmp/readdirbug/file1
readdir: EOF
readdir: EOF
closedir
ok - everything worked

I'd close this issue...

from unix.

hs-viktor avatar hs-viktor commented on June 12, 2024

This appears to be no longer applicable.

from unix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.