[swift-corelibs-dev] Opinions wanted: Special Handling of /proc FileSystem on Linux?

Carl Brown1 Carl.Brown1 at ibm.com
Thu Jan 12 13:40:17 CST 2017




Hi,

I run the Austin Swift meetup group, and a question came up about the /proc
filesystem on Linux:

The question involved the inability to get any useful information from Data
(contentsOf: URL(fileURLWithPath: "/proc/sys/fs/file-max")).

It turns out that Data(contentsOf:) does a stat() on the inode of the file
you give it, and then runs alloc()/read() for the specified number of
bytes. This works fine on normal files on normal file systems. But all the
files in /proc have a 0 length specified by their inodes, and you have to
actually read them until EOF to find out how much is there.

So the question is: Is that something the *Programmer* should be
responsible for knowing, or should *Foundation* be responsible for handling
that correctly?

I can see a case that we'd want to avoid embedding things this OS-specific
in Foundation, but on the other hand, I know that this is very confusing
for Darwin developers moving to Linux and expecting Data(contentsOf:) to
"Just work."

So I thought I'd ask the community and see if there was a consensus.

Thanks,

-Carl

--
Carl Brown
Swift at IBM
Carl.Brown1 at IBM.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20170112/1c61b600/attachment.html>


More information about the swift-corelibs-dev mailing list