C# xattr 文件属性
我正在创建一个跨平台软件,我想知道是否有任何(简单)方法可以在 C# 中读取/写入 Unix (Mac OSX/Linux) 扩展文件属性。 我刚刚阅读了有关 xattr
命名空间的内容,但尚未找到有关此功能的 C# 实现或绑定的任何信息。
PS 到目前为止我发现的唯一的东西是 python-xattr 库,但我不想使用它,因为:
- 我不想强迫用户安装 Python (已经有 Mono/.NET 依赖项需要处理)
- 通过使用Python,我的性能会下降(C#是编译的,而Python是解释的)
- 我不想依赖/依赖外部工具(如果可能的话),因为它不安全
I'm creating a cross-platform software and I want to know if there is any (easy) way to read/write Unix (Mac OSX/Linux) extended file attributes in C#.
I've just read about xattr
namespaces, but I haven't found any information about C# implementation or bindings of this feature.
P.S. The only thing I found so far is python-xattr library, but I don't want to use it because:
- I don't want to obligate the users to install Python (there is already Mono/.NET dependency to deal with)
- By using Python I will have a performance decrease (C# is compiled, while Python is interpreted)
- I don't want to rely/depend on external tools (if it's possible), because it's not safe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用
Mono.Unix.Native.Syscall.*attr*
中的系统调用。nuget 程序集名为 Mono.Posix.NETStandard
请注意,名称-值对以名称空间为前缀。
根据man 7 xattr
You should use the syscalls in
Mono.Unix.Native.Syscall.*attr*
.The nuget assembly is called Mono.Posix.NETStandard
Note that the name of the name-value pair is prefixed with a namespace.
According to man 7 xattr
我认为 Mono.Unix.Native.Syscall.setxattr 将是一个更好的解决方案,它位于 Mono.Posix 模块中。
I think Mono.Unix.Native.Syscall.setxattr would be a better solution, which is in Mono.Posix module.
最终的解决方案可能如下,请告诉我你的想法是什么?
FileAttrsManager 是一个抽象类,用于创建 2 个派生类:
[ * ] http:\\www.microsoft.com/download/en/details.aspx?displaylang=en&id=8422
[ ** ] http:\\ironpython.codeplex.com
[ ** * ] http:\\pypi.python.org/pypi/xatt
扩展属性操作(如
SetPropery(string key, object value)
和GetProperty(string key)
code> 等)将在静态类 (FileAttrsProvider) 中进行管理,该静态类将 FileAttrsManager 对象初始化为两种派生类型之一,即:虽然派生类型取决于环境,原来的使用类型是为了确保自动调度 _reader 对象上的所有方法调用)。
The final solution might be the following, tell me what do you think?
FileAttrsManager is an abstract class, used to create 2 derived classes:
[ * ] http:\\www.microsoft.com/download/en/details.aspx?displaylang=en&id=8422
[ ** ] http:\\ironpython.codeplex.com
[ ** * ] http:\\pypi.python.org/pypi/xatt
Extended attributes operation (such as
SetPropery(string key, object value)
andGetProperty(string key)
etc) will be managed in a static class (FileAttrsProvider) that initializes a FileAttrsManager object to one of two derived types i.e.:While the derived type depends on the environment, the original type is used in order to ensure an automatic dispatch of all the methods call on _reader object).