Skip to content

Conversation

@zhan7236
Copy link
Contributor

Which issue does this PR close?

Part of #4842.

Rationale for this change

Issue #4842 tracks adding user defined metadata support for various services. This PR implements user metadata support for the fs service using extended attributes (xattr) on Unix systems.

What changes are included in this PR?

  • Add xattr crate dependency for Unix platforms
  • Enable write_with_user_metadata capability in the fs backend
  • Implement get_user_metadata() and set_user_metadata() methods using xattr
  • Update FsWriter to store and write user metadata when closing files
  • Update fs_stat() to read user metadata from xattr

User metadata is stored as extended attributes with the prefix user.opendal. on the filesystem.

Are there any user-facing changes?

Yes. Users can now use op.write_with("path", data).user_metadata(metadata) to store custom metadata with files on the fs service (Unix only).

AI Usage Statement

This PR was developed with assistance from GitHub Copilot using Claude Opus 4.5.

@zhan7236 zhan7236 requested a review from Xuanwo as a code owner December 18, 2025 12:38
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. releases-note/feat The PR implements a new feature or has a title that begins with "feat" labels Dec 18, 2025
@zhan7236 zhan7236 force-pushed the feat/services-fs-user-metadata branch from 50425a7 to 57bf31e Compare December 18, 2025 18:06

/// Get user metadata from extended attributes on Unix systems.
///
/// OpenDAL stores user metadata in xattr with the prefix "user.opendal.".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add our own prefix. We should be able to read xattr set by other applications.

#[cfg(unix)]
pub fn set_user_metadata(path: &Path, user_metadata: &HashMap<String, String>) -> Result<()> {
for (key, value) in user_metadata {
let attr_name = format!("{}{}", XATTR_PREFIX, key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same, please don't prefix for users input.

- Add xattr crate dependency for Unix platforms
- Enable write_with_user_metadata capability in the fs backend
- Implement get_user_metadata() and set_user_metadata() methods using xattr
- Update FsWriter to store and write user metadata when closing files
- Update fs_stat() to read user metadata from xattr

User metadata is stored as extended attributes with the "user." prefix
on the filesystem, following the standard Linux xattr naming convention.
This allows interoperability with other applications that use xattr.
@zhan7236 zhan7236 force-pushed the feat/services-fs-user-metadata branch from 57bf31e to 7e63eef Compare December 19, 2025 04:29
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Dec 19, 2025
Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 19, 2025
@Xuanwo Xuanwo merged commit e5ef650 into apache:main Dec 19, 2025
323 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer releases-note/feat The PR implements a new feature or has a title that begins with "feat" size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants