vuls: init at 0.27.0
[NixPkgs.git] / lib / fileset / mock-splitRoot.nix
blob3c18ab1b1afd2071646f8b6dad61be8dc340bf58
1 # This overlay implements mocking of the lib.path.splitRoot function
2 # It pretends that the last component named "mock-root" is the root:
4 # splitRoot /foo/mock-root/bar/mock-root/baz
5 # => {
6 #      root = /foo/mock-root/bar/mock-root;
7 #      subpath = "./baz";
8 #    }
9 self: super: {
10   path = super.path // {
11     splitRoot = path:
12       let
13         parts = super.path.splitRoot path;
14         components = self.path.subpath.components parts.subpath;
15         count = self.length components;
16         rootIndex = count - self.lists.findFirstIndex
17           (component: component == "mock-root")
18           (self.length components)
19           (self.reverseList components);
20         root = self.path.append parts.root (self.path.subpath.join (self.take rootIndex components));
21         subpath = self.path.subpath.join (self.drop rootIndex components);
22       in {
23         inherit root subpath;
24       };
25   };