Repository navigation
fix(file): restore extended attributes before the final mode - #325
Merged
Merged
Conversation
) A read-only replacement (0400) denies setxattr, so restoring the captured attributes after fchmod reported every one of them as unrestored. On macOS that covered com.apple.provenance, which the system gives every new file, so a clean 0400 replace always carried a warning. Apply the attributes while the replacement is still writable, then the mode (after chown, which clears setuid and setgid), then the ACL (which chmod rewrites). The mode matrix now attaches a user attribute before the final chmod, so the ordering is asserted on every host rather than only where macOS supplies the attribute for free.
Thatgfsj
previously approved these changes
Oct 20, 2026
Thatgfsj
left a comment
Collaborator
There was a problem hiding this comment.
除了ops-files里面修改的是与之前的测试有关的内容,简单查看并无问题,仅仅新加函数+拆分函数,别的内容均不影响主功能
This was referenced Oct 21, 2026
T-Auto
marked this pull request as ready for review
October 21, 2026 06:11
# Conflicts: # docs/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #324
What was wrong
ops_replace的发布方式是写入新 inode 再 rename 覆盖目标,因此它先捕获旧 inode 的元数据、之后再重新应用。PreservedMetadata::restore的应用顺序是 chown → fchmod(最终模式)→ ACL → xattrs,而替换文件一旦被fchmod成0400就不再可写,末尾的setxattr因此返回EACCES。test/file-metadata.test.mjs把它表现为一次"干净替换"上不该出现的警告:六种模式里只有
0400失败(绕过套件、直接对已构建的 worker 逐个跑):根因用独立的
libc探针确认过:模式0400下,对替换文件的 fd 调用fsetxattr与基于路径的setxattr都返回Permission denied (os error 13)——即使写入与现有值完全相同的内容。macOS 26+ 会给每个新建文件打上
com.apple.provenance,因此在这些系统上0400替换的警告是无条件的。同一顺序在任何平台上都会静默丢掉源文件携带的user.*属性,只是那些平台没有这个"人人都有"的属性来把它暴露出来。复现:
npm run build:ptc && node test/run.mjs file-metadata。The change
native/crates/ops-files/src/file.rs:扩展属性改在替换文件仍可写时应用;模式仍放在chown之后(成功的 chown 会清除 setuid/setgid);ACL 仍放在最后(chmod会重写 ACL 的 mask 项)。test/file-metadata.test.mjs:模式矩阵在最终chmod之前挂一个user.dsh-ops属性,并断言它被原样恢复,使该顺序在所有平台都受断言约束,而不只依赖 macOS 免费提供的属性。docs/CHANGELOG.md:## [Unreleased]双语条目。刻意没做:严重性分级一字未动——模式仍是"不可恢复即失败、不发布任何东西",ACL 仍是"不可恢复即失败",属主与其余扩展属性仍是尽力而为并在
metadataWarnings里报告。本次只移动顺序,不改变哪一项是可选的。Validation
pull_request事件触发的CI requiredrun:fork PR,未停在action_required,聚合检查CI required已success;URL 见下方代码块npm run verify的实际输出(见下方代码块)docs/CHANGELOG.md的## [Unreleased]已加条目package.json的版本与optionalDependencies撤销验证:把
file.rs的恢复顺序改回原样并重跑npm run build:ptc,同一套件立刻变红:修复后(本 PR HEAD
9249d2a):2 个跳过是 TUI 套件,需要
DSH_OPS_TUI_ROOT指向 dsh-TUI 检出,与本改动无关。Environment
maincommit:8222631npm ci --ignore-scripts);native worker 由npm run build:ptc本地构建1.97.1(rustup 默认工具链,与 CI 及docs/CONTRIBUTING.md固定的版本一致),cargo 1.97.1 / rustc 1.97.1