Commit 13e68cd
committed
Set ownership on symlinks created by build actions during their execution
In commit 410ea5c
"Set ownership on files created by build actions during their execution"
files got correct ownership associated with them. This commit adds the
same feature to symlinks.
One use case is to allow hardlinking symlinks, which requires the owner
of the symlink to be correct.
The following test was performed with Bazel:
```starlark
--- rules.bzl ---
def _impl(ctx):
file = ctx.actions.declare_file("file")
symlink = ctx.actions.declare_symlink("symlink")
args = ctx.actions.args()
args.add_all([file, symlink])
ctx.actions.run_shell(
outputs = [file, symlink],
command = """
exec 2>&1
set +ex
touch $1
ln -s file $2
ln $2 $2.hardlink
ls -la $(dirname $1)
""",
arguments = [args],
)
return [
DefaultInfo(files = depset([file, symlink])),
OutputGroupInfo(
file = depset([file]),
),
]
hardlink_a_symlink_rule = rule(
implementation = _impl,
)
--- BUILD.bazel ---
load(":rules.bzl", "hardlink_a_symlink_rule")
hardlink_a_symlink_rule(name = "hardlink_a_symlink")
filegroup(
name = "hardlink_a_symlink_file",
srcs = [":hardlink_a_symlink"],
output_group = "file",
)
genrule(
name = "hardlink_input_symlink",
srcs = [":hardlink_a_symlink", ":hardlink_a_symlink_file"],
outs = ["symlink.another_hardlink"],
cmd = """
exec 2>&1
set +ex
cd $$(dirname $(location :hardlink_a_symlink_file))
ln symlink symlink.another_hardlink
ls -la
""",
)
--- Output ---
$ bazel build :hardlink_input_symlink
INFO: From Action file:
total 0
drwxrwxrwx 1 fredrik fredrik 0 Feb 5 21:12 .
drwxrwxrwx 1 fredrik fredrik 0 Feb 5 21:12 ..
-rw-rw-rw- 1 fredrik fredrik 0 Feb 5 21:12 file
lrwxrwxrwx 9999 fredrik fredrik 4 Jan 1 2000 symlink -> file
lrwxrwxrwx 9999 fredrik fredrik 4 Jan 1 2000 symlink.hardlink -> file
INFO: From Executing genrule //:hardlink_input_symlink:
total 0
drwxrwxrwx 1 fredrik fredrik 0 Feb 5 21:12 .
drwxrwxrwx 1 fredrik fredrik 0 Feb 5 21:12 ..
-r-xr-xr-x 9999 root root 0 Jan 1 2000 file
lrwxrwxrwx 9999 fredrik fredrik 4 Jan 1 2000 symlink -> file
lrwxrwxrwx 9999 fredrik fredrik 4 Jan 1 2000 symlink.another_hardlink -> file
```
References:
https://sourceforge.net/p/fuse/mailman/message/35004606/
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=800179c9b8a1e796e441674776d11cd4c05d61d7
torvalds/linux@800179c1 parent 79a33f1 commit 13e68cd
File tree
6 files changed
+61
-21
lines changed- cmd/bb_worker
- pkg
- builder
- filesystem/virtual
6 files changed
+61
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
222 | 226 | | |
223 | | - | |
| 227 | + | |
224 | 228 | | |
225 | 229 | | |
226 | 230 | | |
227 | 231 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
346 | 353 | | |
347 | 354 | | |
348 | 355 | | |
| |||
391 | 398 | | |
392 | 399 | | |
393 | 400 | | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
| 401 | + | |
398 | 402 | | |
399 | 403 | | |
400 | 404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | | - | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | | - | |
23 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
24 | 34 | | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
28 | | - | |
| 38 | + | |
| 39 | + | |
29 | 40 | | |
30 | 41 | | |
31 | 42 | | |
| |||
48 | 59 | | |
49 | 60 | | |
50 | 61 | | |
| 62 | + | |
51 | 63 | | |
52 | 64 | | |
53 | 65 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
532 | | - | |
| 532 | + | |
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
539 | 540 | | |
540 | 541 | | |
541 | 542 | | |
| |||
1121 | 1122 | | |
1122 | 1123 | | |
1123 | 1124 | | |
1124 | | - | |
| 1125 | + | |
1125 | 1126 | | |
1126 | 1127 | | |
1127 | 1128 | | |
| |||
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| 407 | + | |
407 | 408 | | |
408 | 409 | | |
409 | | - | |
| 410 | + | |
410 | 411 | | |
411 | 412 | | |
412 | 413 | | |
| |||
424 | 425 | | |
425 | 426 | | |
426 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
427 | 449 | | |
428 | 450 | | |
429 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| |||
0 commit comments