aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
AgeCommit message (Collapse)Author
2020-04-27Fix long paths permanently breaking GCAlyssa Ross
Suppose I have a path /nix/store/[hash]-[name]/a/a/a/a/a/[...]/a, long enough that everything after "/nix/store/" is longer than 4096 (MAX_PATH) bytes. Nix will happily allow such a path to be inserted into the store, because it doesn't look at all the nested structure. It just cares about the /nix/store/[hash]-[name] part. But, when the path is deleted, we encounter a problem. Nix will move the path to /nix/store/trash, but then when it's trying to recursively delete the trash directory, it will at some point try to unlink /nix/store/trash/[hash]-[name]/a/a/a/a/a/[...]/a. This will fail, because the path is too long. After this has failed, any store deletion operation will never work again, because Nix needs to delete the trash directory before recreating it to move new things to it. (I assume this is because otherwise a path being deleted could already exist in the trash, and then moving it would fail.) This means that if I can trick somebody into just fetching a tarball containing a path of the right length, they won't be able to delete store paths or garbage collect ever again, until the offending path is manually removed from /nix/store/trash. (And even fixing this manually is quite difficult if you don't understand the issue, because the absolute path that Nix says it failed to remove is also too long for rm(1).) This patch fixes the issue by making Nix's recursive delete operation use unlinkat(2). This function takes a relative path and a directory file descriptor. We ensure that the relative path is always just the name of the directory entry, and therefore its length will never exceed 255 bytes. This means that it will never even come close to AX_PATH, and Nix will therefore be able to handle removing arbitrarily deep directory hierachies. Since the directory file descriptor is used for recursion after being used in readDirectory, I made a variant of readDirectory that takes an already open directory stream, to avoid the directory being opened multiple times. As we have seen from this issue, the less we have to interact with paths, the better, and so it's good to reuse file descriptors where possible. I left _deletePath as succeeding even if the parent directory doesn't exist, even though that feels wrong to me, because without that early return, the linux-sandbox test failed. Reported-by: Alyssa Ross <hi@alyssa.is> Thanks-to: Puck Meerburg <puck@puckipedia.com> Tested-by: Puck Meerburg <puck@puckipedia.com> Reviewed-by: Puck Meerburg <puck@puckipedia.com>
2020-04-22Don't include error.hh in util.hh to prevent header bloatEelco Dolstra
2020-04-22Merge branch 'error-format' of https://github.com/bburdette/nixEelco Dolstra
2020-04-16iomanip no longer neededBen Burdette
2020-04-16Logger: Add method for writing to stdoutEelco Dolstra
Usually this just writes to stdout, but for ProgressBar, we need to clear the current line, write the line to stdout, and then redraw the progress bar. (cherry picked from commit 696c026006a6ac46adc990ed5cb0f31535bac076)
2020-04-16switch to structs, which don't need public:Ben Burdette
2020-04-15move implementation to ccBen Burdette
2020-04-15Merge branch 'initializer-style' into error-formatBen Burdette
2020-04-14add NIX_USER_CONF_FILESzimbatm
Motivation: maintain project-level configuration files. Document the whole situation a bit better so that it corresponds to the implementation, and add NIX_USER_CONF_FILES that allows overriding which user files Nix will load during startup.
2020-04-08DataTransfer -> FileTransferNikola Knezevic
2020-04-08actDownload -> actDataTransferNikola Knezevic
2020-04-08indentionBen Burdette
2020-04-08format -> fmtBen Burdette
2020-04-08commentsBen Burdette
2020-04-08return of NixCodeBen Burdette
2020-04-08initializer styleBen Burdette
2020-04-07columnRange -> columnBen Burdette
2020-04-07remove columnrange; switch to fmt in error.ccBen Burdette
2020-04-07Backport libfetchers from the flakes branchEelco Dolstra
This provides a pluggable mechanism for defining new fetchers. It adds a builtin function 'fetchTree' that generalizes existing fetchers like 'fetchGit', 'fetchMercurial' and 'fetchTarball'. 'fetchTree' takes a set of attributes, e.g. fetchTree { type = "git"; url = "https://example.org/repo.git"; ref = "some-branch"; rev = "abcdef..."; } The existing fetchers are just wrappers around this. Note that the input attributes to fetchTree are the same as flake input specifications and flake lock file entries. All fetchers share a common cache stored in ~/.cache/nix/fetcher-cache-v1.sqlite. This replaces the ad hoc caching mechanisms in fetchGit and download.cc (e.g. ~/.cache/nix/{tarballs,git-revs*}). This also adds support for Git worktrees (c169ea59049f861aaba429f48b828d0820b74d1d).
2020-04-06comment cleanupBen Burdette
2020-04-06constructor style basically workingBen Burdette
2020-04-06Merge branch 'master' into error-formatBen Burdette
2020-04-03handle Pos instead of individual file/line/columnrange argsBen Burdette
2020-04-03variadic args for hint formatBen Burdette
2020-04-02formatted with astyleBen Burdette
2020-04-02indentingBen Burdette
2020-04-01using std:: everywhere; fix a formatting error; add exception flagsBen Burdette
2020-04-01indentingBen Burdette
2020-04-01remove using std::*, switch to include guardBen Burdette
2020-03-31add some explanatory commentsBen Burdette
2020-03-31rename errors/warningsBen Burdette
2020-03-31enum styleBen Burdette
2020-03-30Backport 'nix dev-shell' from the flakes branchEelco Dolstra
This also adds a '--profile' option to 'nix build' (replacing 'nix-env --set').
2020-03-30build with makeBen Burdette
2020-03-27remove util.hh from depsBen Burdette
2020-03-27more cleanupBen Burdette
2020-03-27camelcase; optional hintBen Burdette
2020-03-25some colorsBen Burdette
2020-03-25programName as static member varBen Burdette
2020-03-24switch to one level of builder function, not subobject functionsBen Burdette
2020-03-24MkNixCode, MkErrLine approachBen Burdette
2020-03-24renamingBen Burdette
2020-03-24Misc changes from the flakes branchEelco Dolstra
2020-03-24Pretty-print 'nix why-depends' / 'nix-store -q --tree' outputEelco Dolstra
Extracted from 678301072f05b650dc15c5edb4c25f08f0d6cace.
2020-03-24absPath(): Use std::optionalEelco Dolstra
(cherry picked from commit 1bf9eb21b75f0d93d9c1633ea2e6fdf840047e79)
2020-03-24Add function for quoting stringsEelco Dolstra
(cherry picked from commit 7dcf5b011a0942ecf953f2b607c4c8d0e9e652c7)
2020-03-23error testBen Burdette
2020-03-22straightforward port of rust mockup codeBen Burdette
2020-02-13Prevent uninitialized StorePath creationEelco Dolstra
2020-02-01Show "warning:" in yellow instead of redEelco Dolstra