Skip to content

Conversation

smpdt
Copy link
Contributor

@smpdt smpdt commented Jun 4, 2025

Problem

When copying files in the bootstrap process with dereference_symlinks = true, we're incorrectly using the symlink's metadata to set permissions on the copied regular file, which results in the following error:

Warning: Failed to set file times for "/build/nix-build-rustc-1.86.0.drv-0/rustc-1.86.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-strip" (permissions: Permissions(FilePermissions { mode: 0o100000 (----------) })) error: Permission denied (os error 13)

Verbose Logs confirming the error:

TRACE: Found llvm-strip copy operation
  Source: /n/nix/tech/store/n34yzv2n50p6lbjmx089vjym121wbl4j-llvm-19.1.7/bin/llvm-strip
  Destination: /build/nix-build-rustc-1.86.0.drv-0/rustc-1.86.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-strip
  Source is_symlink (via symlink_metadata): true
  Source symlink_metadata permissions: 120000
  Source symlink_metadata file_type: FileType { is_file: false, is_dir: false, is_symlink: true, .. }

  Source is symlink pointing to: llvm-objcopy
  Source raw mode: 120000
  Source filetype: 120000

  Setting permissions: Permissions(FilePermissions { mode: 0o120000 (l---------) })
  Permission mode to set: 120000
  Raw permission bits: 120000
  File type bits being set: 120000
  Permission bits being set: 0

  WARNING: Attempting to set symlink file type (120000) on regular file!
  WARNING: Setting zero permission bits will make file inaccessible!
  Destination permissions after set_permissions: 100000 

Solution

After canonicalizing a symlink path, fetch the metadata of the target file instead of continuing to use the symlink's metadata. This ensures:

  • Correct file type detection
  • Proper permission bits for the target file
  • Maintains existing behavior for non-symlink cases

Testing

Verified fix resolves permission errors:

rustc> llvm-strip: Original metadata mode: 120000, is_symlink: true
rustc> llvm-strip: Target metadata mode after fix: 100555
rustc> llvm-strip: Final permissions mode: 100555

@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

r? @Kobzol

rustbot has assigned @Kobzol.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 4, 2025
@Kobzol
Copy link
Member

Kobzol commented Jun 4, 2025

Makes sense, thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 4, 2025

📌 Commit 9091a94 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 4, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 5, 2025
bootstrap: Fix file permissions when dereferencing symlinks

## Problem
When copying files in the bootstrap process with `dereference_symlinks = true`, we're incorrectly using the symlink's metadata to set permissions on the copied regular file, which results in the following error:
```
Warning: Failed to set file times for "/build/nix-build-rustc-1.86.0.drv-0/rustc-1.86.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-strip" (permissions: Permissions(FilePermissions { mode: 0o100000 (----------) })) error: Permission denied (os error 13)
```

Verbose Logs confirming the error:
```
TRACE: Found llvm-strip copy operation
  Source: /n/nix/tech/store/n34yzv2n50p6lbjmx089vjym121wbl4j-llvm-19.1.7/bin/llvm-strip
  Destination: /build/nix-build-rustc-1.86.0.drv-0/rustc-1.86.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-strip
  Source is_symlink (via symlink_metadata): true
  Source symlink_metadata permissions: 120000
  Source symlink_metadata file_type: FileType { is_file: false, is_dir: false, is_symlink: true, .. }

  Source is symlink pointing to: llvm-objcopy
  Source raw mode: 120000
  Source filetype: 120000

  Setting permissions: Permissions(FilePermissions { mode: 0o120000 (l---------) })
  Permission mode to set: 120000
  Raw permission bits: 120000
  File type bits being set: 120000
  Permission bits being set: 0

  WARNING: Attempting to set symlink file type (120000) on regular file!
  WARNING: Setting zero permission bits will make file inaccessible!
  Destination permissions after set_permissions: 100000
```

## Solution
After canonicalizing a symlink path, fetch the metadata of the target file instead of continuing to use the symlink's metadata. This ensures:
- Correct file type detection
- Proper permission bits for the target file
- Maintains existing behavior for non-symlink cases

## Testing
Verified fix resolves permission errors:
```
rustc> llvm-strip: Original metadata mode: 120000, is_symlink: true
rustc> llvm-strip: Target metadata mode after fix: 100555
rustc> llvm-strip: Final permissions mode: 100555
```
bors added a commit that referenced this pull request Jun 5, 2025
Rollup of 7 pull requests

Successful merges:

 - #141709 (jsondocck: Refactor directive handling)
 - #141974 (`tests/ui`: A New Order [4/N])
 - #141989 (rustdoc-json-type: Depend on `serde` and `serde_derive` seperately)
 - #142015 (Report the actual item that evaluation failed for)
 - #142026 (bootstrap: Fix file permissions when dereferencing symlinks)
 - #142032 (Fix parsing of frontmatters with inner hyphens)
 - #142036 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 19798d6 into rust-lang:master Jun 5, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 5, 2025
rust-timer added a commit that referenced this pull request Jun 5, 2025
Rollup merge of #142026 - smpdt:master, r=Kobzol

bootstrap: Fix file permissions when dereferencing symlinks

## Problem
When copying files in the bootstrap process with `dereference_symlinks = true`, we're incorrectly using the symlink's metadata to set permissions on the copied regular file, which results in the following error:
```
Warning: Failed to set file times for "/build/nix-build-rustc-1.86.0.drv-0/rustc-1.86.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-strip" (permissions: Permissions(FilePermissions { mode: 0o100000 (----------) })) error: Permission denied (os error 13)
```

Verbose Logs confirming the error:
```
TRACE: Found llvm-strip copy operation
  Source: /n/nix/tech/store/n34yzv2n50p6lbjmx089vjym121wbl4j-llvm-19.1.7/bin/llvm-strip
  Destination: /build/nix-build-rustc-1.86.0.drv-0/rustc-1.86.0-src/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-strip
  Source is_symlink (via symlink_metadata): true
  Source symlink_metadata permissions: 120000
  Source symlink_metadata file_type: FileType { is_file: false, is_dir: false, is_symlink: true, .. }

  Source is symlink pointing to: llvm-objcopy
  Source raw mode: 120000
  Source filetype: 120000

  Setting permissions: Permissions(FilePermissions { mode: 0o120000 (l---------) })
  Permission mode to set: 120000
  Raw permission bits: 120000
  File type bits being set: 120000
  Permission bits being set: 0

  WARNING: Attempting to set symlink file type (120000) on regular file!
  WARNING: Setting zero permission bits will make file inaccessible!
  Destination permissions after set_permissions: 100000
```

## Solution
After canonicalizing a symlink path, fetch the metadata of the target file instead of continuing to use the symlink's metadata. This ensures:
- Correct file type detection
- Proper permission bits for the target file
- Maintains existing behavior for non-symlink cases

## Testing
Verified fix resolves permission errors:
```
rustc> llvm-strip: Original metadata mode: 120000, is_symlink: true
rustc> llvm-strip: Target metadata mode after fix: 100555
rustc> llvm-strip: Final permissions mode: 100555
```
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 6, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#141709 (jsondocck: Refactor directive handling)
 - rust-lang/rust#141974 (`tests/ui`: A New Order [4/N])
 - rust-lang/rust#141989 (rustdoc-json-type: Depend on `serde` and `serde_derive` seperately)
 - rust-lang/rust#142015 (Report the actual item that evaluation failed for)
 - rust-lang/rust#142026 (bootstrap: Fix file permissions when dereferencing symlinks)
 - rust-lang/rust#142032 (Fix parsing of frontmatters with inner hyphens)
 - rust-lang/rust#142036 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jun 9, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#141709 (jsondocck: Refactor directive handling)
 - rust-lang/rust#141974 (`tests/ui`: A New Order [4/N])
 - rust-lang/rust#141989 (rustdoc-json-type: Depend on `serde` and `serde_derive` seperately)
 - rust-lang/rust#142015 (Report the actual item that evaluation failed for)
 - rust-lang/rust#142026 (bootstrap: Fix file permissions when dereferencing symlinks)
 - rust-lang/rust#142032 (Fix parsing of frontmatters with inner hyphens)
 - rust-lang/rust#142036 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
tgross35 pushed a commit to tgross35/compiler-builtins that referenced this pull request Jun 9, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#141709 (jsondocck: Refactor directive handling)
 - rust-lang/rust#141974 (`tests/ui`: A New Order [4/N])
 - rust-lang/rust#141989 (rustdoc-json-type: Depend on `serde` and `serde_derive` seperately)
 - rust-lang/rust#142015 (Report the actual item that evaluation failed for)
 - rust-lang/rust#142026 (bootstrap: Fix file permissions when dereferencing symlinks)
 - rust-lang/rust#142032 (Fix parsing of frontmatters with inner hyphens)
 - rust-lang/rust#142036 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
tautschnig pushed a commit to model-checking/verify-rust-std that referenced this pull request Jun 17, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#141709 (jsondocck: Refactor directive handling)
 - rust-lang#141974 (`tests/ui`: A New Order [4/N])
 - rust-lang#141989 (rustdoc-json-type: Depend on `serde` and `serde_derive` seperately)
 - rust-lang#142015 (Report the actual item that evaluation failed for)
 - rust-lang#142026 (bootstrap: Fix file permissions when dereferencing symlinks)
 - rust-lang#142032 (Fix parsing of frontmatters with inner hyphens)
 - rust-lang#142036 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants