lix-releng-staging/src
Guillaume Bouchard 5a34a473dd builtins.readFile: do not truncate content
This closes #3026 by allowing `builtins.readFile` to read a file with a
wrongly reported file size, for example, files in `/proc` may report a
file size of 0. Reading file in `/proc` is not a good enough motivation,
however I do think it just makes nix more robust by allowing more file
to be read.  Especially, I do considerer the previous behavior to be
dangerous because nix was previously reading truncated files. Examples
of file system which incorrectly report file size may be network file
system or dynamic file system (for performance reason, a dynamic file
system such as FUSE may generate the content of the file on demand).

```
nix-repl> builtins.readFile "/proc/version"
""
```

With this commit:

```
nix-repl> builtins.readFile "/proc/version"
"Linux version 5.6.7 (nixbld@localhost) (gcc version 9.3.0 (GCC)) #1-NixOS SMP Thu Apr 23 08:38:27 UTC 2020\n"
```

Here is a summary of the behavior changes:

- If the reported size is smaller, previous implementation
was silently returning a truncated file content. The new implementation
is returning the correct file content.

- If a file had a bigger reported file size, previous implementation was
failing with an exception, but the new implementation is returning the
correct file content. This change of behavior is coherent with this pull
request.

Open questions

- The behavior is unchanged for correctly reported file size, however
performances may vary because it uses the more complex sink interface.
Considering that sink is used a lot, I don't think this impacts the
performance a lot.
- `builtins.readFile` on an infinite file, such as `/dev/random` may
fill the memory.
- it does not support adding file to store, such as `${/proc/version}`.
2020-04-29 14:50:52 +02:00
..
build-remote Remove global -I flags 2020-03-30 15:30:19 +02:00
cpptoml bump cpptoml to v0.1.1 2019-05-29 17:01:39 +08:00
error-demo comments 2020-04-08 09:56:10 -06:00
libexpr Merge pull request #3502 from NixOS/more-pos 2020-04-18 14:05:21 +02:00
libfetchers Path fetcher: Fix store path name 2020-04-22 15:27:06 +02:00
libmain Merge pull request #3458 from zimbatm/nix-user-conf-dir 2020-04-15 13:00:28 +02:00
libstore Replace select() with poll() to allow waiting on more than FD_SETSIZE fds 2020-04-21 16:21:28 -07:00
libutil builtins.readFile: do not truncate content 2020-04-29 14:50:52 +02:00
nix rename to NIX_GCROOT 2020-04-28 11:18:54 -06:00
nix-build Remove global -I flags 2020-03-30 15:30:19 +02:00
nix-channel after flake rebase 2020-04-08 22:26:57 +02:00
nix-collect-garbage Remove global -I flags 2020-03-30 15:30:19 +02:00
nix-copy-closure Remove global -I flags 2020-03-30 15:30:19 +02:00
nix-daemon Remove global -I flags 2020-03-30 15:30:19 +02:00
nix-env Tweak warning message 2020-04-28 17:56:01 +02:00
nix-instantiate Remove global -I flags 2020-03-30 15:30:19 +02:00
nix-prefetch-url datatransfer.{cc,hh} -> filetransfer.{cc,hh} 2020-04-08 22:26:57 +02:00
nix-store Remove global -I flags 2020-03-30 15:30:19 +02:00
resolve-system-dependencies Fix macOS build 2020-03-30 17:00:40 +02:00