lix/src/libutil
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
..
affinity.cc printMsg(lvlError, ...) -> printError(...) etc. 2016-09-21 16:54:53 +02:00
affinity.hh Run the daemon worker on the same CPU as the client 2013-08-07 14:02:04 +02:00
ansicolor.hh remove util.hh from deps 2020-03-27 10:55:09 -06:00
archive.cc Add O(1)-memory copyPath() function 2019-10-27 18:18:58 +01:00
archive.hh Add O(1)-memory copyPath() function 2019-10-27 18:18:58 +01:00
args.cc Initialize Command::_name 2019-12-05 20:21:22 +01:00
args.hh Initialize Command::_name 2019-12-05 20:21:22 +01:00
compression.cc Improve gzip error message 2019-12-13 19:05:26 +01:00
compression.hh Fix Brotli decompression in 'nix log' 2018-08-06 15:40:29 +02:00
config.cc Add priority setting to stores 2019-12-17 17:17:53 +01:00
config.hh Add priority setting to stores 2019-12-17 17:17:53 +01:00
error.cc move implementation to cc 2020-04-15 10:09:43 -06:00
error.hh iomanip no longer needed 2020-04-16 10:48:15 -06:00
finally.hh Add missing #include 2016-11-07 14:35:47 +01:00
hash.cc Allow content-addressable paths to have references 2019-10-21 17:47:24 +02:00
hash.hh Misc changes from the flakes branch 2020-03-24 14:34:47 +01:00
istringstream_nocopy.hh Move istringstream_nocopy to a separate file 2017-03-21 14:43:03 +01:00
json.cc Make std::uncaught_exception warning less noisy 2019-10-09 23:04:11 +02:00
json.hh Make std::uncaught_exception warning less noisy 2019-10-09 23:04:11 +02:00
lazy.hh Figure out the user's home directory if $HOME is not set 2017-05-05 17:08:23 +02:00
local.mk libarchive proof of concept 2019-12-07 22:35:14 +07:00
logging.cc Logger: Add method for writing to stdout 2020-04-16 18:03:38 +02:00
logging.hh Logger: Add method for writing to stdout 2020-04-16 18:03:38 +02:00
lru-cache.hh experimental/optional -> optional 2019-03-14 14:10:52 +01:00
monitor-fd.hh monitor-fds: Fix on macOS. 2018-02-14 18:26:37 -05:00
pool.hh RemoteStore: Close connection if an exception occurs 2018-10-16 23:36:15 +02:00
ref.hh Allow setting the state directory as a store parameter 2016-06-02 16:02:48 +02:00
rust-ffi.cc Merge branch 'libarchive' of https://github.com/yorickvP/nix 2019-12-19 14:47:18 +01:00
rust-ffi.hh Prevent uninitialized StorePath creation 2020-02-13 16:12:16 +01:00
serialise.cc experimental/optional -> optional 2019-03-14 14:10:52 +01:00
serialise.hh Drop remaining uses of external "tar" 2019-11-26 22:07:28 +01:00
sync.hh sync.hh: return cv_status instead of dropping it, in case useful. 2018-06-18 17:31:00 -05:00
tarfile.cc tarfile.cc: Restore timestamps 2019-12-19 15:09:54 +01:00
tarfile.hh libarchive proof of concept 2019-12-07 22:35:14 +07:00
thread-pool.cc Fix a hang in ThreadPool 2017-10-09 15:41:09 +02:00
thread-pool.hh Fix extra ; warnings involving MakeError 2019-11-10 11:24:47 -05:00
types.hh Merge branch 'error-format' of https://github.com/bburdette/nix 2020-04-22 15:29:10 +02:00
url.cc Backport libfetchers from the flakes branch 2020-04-07 09:03:14 +02:00
url.hh Backport libfetchers from the flakes branch 2020-04-07 09:03:14 +02:00
util.cc builtins.readFile: do not truncate content 2020-04-29 14:50:52 +02:00
util.hh Don't include error.hh in util.hh to prevent header bloat 2020-04-22 15:29:27 +02:00
xml-writer.cc Cleanup 2019-11-06 16:53:02 +01:00
xml-writer.hh Fix some random -Wconversion warnings 2018-05-02 13:56:34 +02:00