chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

1
vendor/xattr/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"a385d56bed0ff3981de450ee495d2bc0a3e3344a33a5bd05da0fe0a48e92bc05",".github/workflows/android.yml":"675ff1e59972f97b417ae538f39701cb829e20b404fd93fdd4fc0c8381c98b12",".github/workflows/freebsd.yml":"f2bd2dbdc3f0b8d915e18e7223a98e14d1c98c8b86e73c9ed0683af951d88c41",".github/workflows/linux.yml":"9792b2f5a1984d0d8b976f7abf21bb4444e3c69963ccd713b3fea09263684cd4",".github/workflows/macos.yml":"ac1bd80d0229a0fd61f605ec5290079cdaa10253e9fe34c666eff6cb8827d529",".github/workflows/netbsd.yml":"d901c926b1bbdc570cdb3ab7428c7695f1d2dcac72af9e50b55649a1dd36f35e",".github/workflows/run-on-host.sh":"1a96781236b34e9bb4df9245a0b6d5fe9ebe7c460e9521b556b57485bf8f6251",".github/workflows/unsupported.yml":"dc0db7980dfc1dbf4c3941b7cf9f03a55326f188a892322974953a5c5af447a7","Cargo.lock":"4e6bdab133dc904f88a42c30e7af3a90d92ca3bfb4b0d89e23e10375f22f3e12","Cargo.toml":"c3b3272c455209e0a33f3146a134da0709f4ab175a027a70238c785d73e0b0b1","Cargo.toml.orig":"2c383b6f62d7cbad2326819ce03e5a5b511c0d9ca8f48c8db483149fe589a08f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"8b427f5bc501764575e52ba4f9d95673cf8f6d80a86d0d06599852e1a9a20a36","README.md":"a207638e1dbbd93ad245c0cdcb15a904aa043dfe65adce5a111c791abbbf2165","src/error.rs":"4e8b8e248aac111b056bed44692be0397daf9c34a39829309e58dbf12e0dc7a6","src/lib.rs":"da098a27c3a46b8d630fa11755ec7eeeab8a38c15f04d986dd7b46e6aafabffd","src/sys/bsd.rs":"ab507c904cb8056dc4259b46764cd2765906d7326c82078443b62b0d45e8ce28","src/sys/linux_macos.rs":"41fc8181c512fd6523e015a570cc69278b2f64cb3f9762c722975ab1e3f4b70c","src/sys/mod.rs":"7cd21e443464561a806e811493f88cb05d83232f413f3dcf1784947255afb184","src/sys/unsupported.rs":"a45b961406ee442b6bbd91959cdfa2ea940817baa84f789dd3e30dc4618c7117","src/util.rs":"08fb254cb9d4d95552c5e6994a8485bc8e68f770f3ba7cc1b4f5aa746584ae9b","tests/main.rs":"8b35ae52fbd4dce81ea53d313bf3b2109f2ad962d58e741f8954acccc7ef4228"},"package":"32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156"}

6
vendor/xattr/.cargo_vcs_info.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "3e1914f5dac41437db1fed74f6284fd84cb26b26"
},
"path_in_vcs": ""
}

View File

@@ -0,0 +1,62 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
name: android
env:
NDK_VERSION: "r26d"
ANDROID_VERSION: "12.0.0"
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-linux-android
- name: Setup Android Environment
run: |
NDK_URL="https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip"
NDK_DIR="${HOME}/android-ndk-${NDK_VERSION}"
# Download and extract NDK
echo "Downloading NDK from $NDK_URL"
wget -q "$NDK_URL" -O android-ndk.zip
unzip -q android-ndk.zip -d "$HOME"
# Set ANDROID_NDK_ROOT environment variable
echo "ANDROID_NDK_ROOT=$NDK_DIR" >> $GITHUB_ENV
# Setup & start redroid container
sudo apt-get install -y linux-modules-extra-$(uname -r) android-tools-adb
sudo modprobe binder_linux devices=binder,hwbinder,vndbinder
docker run -itd --rm --privileged \
--mount "type=bind,src=$(pwd),dst=/data/host$(pwd),ro" \
--mount "type=bind,src=/tmp,dst=/data/host/tmp,ro" \
--mount "type=bind,src=$(pwd)/.github/workflows/run-on-host.sh,dst=/system/xbin/run-on-host,ro" \
--name redroid-test \
-p 5555:5555 \
redroid/redroid:${ANDROID_VERSION}_64only-latest
# Start ADB server and connect to our redroid container
adb start-server
timeout 60 bash -c 'until adb connect localhost:5555; do sleep 2; done'
# Configure Android environment
echo "CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER=adb -s localhost:5555 shell run-on-host" >> $GITHUB_ENV
echo "CC_X86_64_linux_android=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang" >> $GITHUB_ENV
echo "AR_x86_64_linux_android=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" >> $GITHUB_ENV
echo "CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_RUSTFLAGS=-C link-arg=-Wl,--as-needed" >> $GITHUB_ENV
- run: cargo build --verbose --target x86_64-linux-android
- run: cargo test --verbose --target x86_64-linux-android -- --nocapture
- name: Stop the redroid container
run: docker stop redroid-test || true

View File

@@ -0,0 +1,37 @@
# Run cargo tests in a FreeBSD VM. This needs to run on one of the GitHub macos runners, because
# they are currently the only ones to support virtualization.
#
# See https://github.com/vmactions/freebsd-vm
on:
push:
branches:
- master
pull_request:
branches:
- master
name: freebsd
jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run tests in FreeBSD VM
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
pkg install -y curl
curl https://sh.rustup.rs -sSf --output rustup.sh
sh rustup.sh -y --profile minimal --default-toolchain stable
export PATH="${HOME}/.cargo/bin:$PATH"
echo "~~~~ rustc --version ~~~~"
rustc --version
run: |
export PATH="${HOME}/.cargo/bin:$PATH"
ls -la
cargo build --verbose
cargo test --verbose

View File

@@ -0,0 +1,19 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
name: linux
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --verbose
- run: cargo test --verbose

View File

@@ -0,0 +1,19 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
name: macos
jobs:
build:
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --verbose
- run: cargo test --verbose

View File

@@ -0,0 +1,36 @@
# Run cargo tests in a NetBSD VM. This needs to run on one of the GitHub macos runners, because
# they are currently the only ones to support virtualization.
#
# See https://github.com/vmactions/netbsd-vm
#
# The standard filesystem on NetBSD installs, ffs, doesn't support extended attributes. The
# filesystem type needs to be set fo FFSv2ea (on NetBSD 10 or later) for this to be enabled.
# See http://wikimirror.netbsd.de/tutorials/acls_and_extended_attributes_on_ffs/
# Disabled until NetBSD 10 is released and available via vmactions
on: workflow_dispatch
name: netbsd
jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run tests in NetBSD VM
uses: vmactions/netbsd-vm@v1
with:
usesh: true
prepare: |
/usr/sbin/pkg_add curl
curl https://sh.rustup.rs -sSf --output rustup.sh
sh rustup.sh -y --profile minimal --default-toolchain stable
export PATH="${HOME}/.cargo/bin:$PATH"
echo "~~~~ rustc --version ~~~~"
rustc --version
run: |
export PATH="${HOME}/.cargo/bin:$PATH"
ls -la
cargo build --verbose
cargo test --verbose

View File

@@ -0,0 +1,7 @@
#!/system/bin/sh
CMD="$1"
shift
cd /data/local/tmp || exit 1
exec "/data/host$CMD" "$@"

View File

@@ -0,0 +1,20 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
name: unsupported
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-illumos
- run: cargo build --verbose --target x86_64-unknown-illumos

141
vendor/xattr/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,141 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bitflags"
version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
[[package]]
name = "cfg-if"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "errno"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "getrandom"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.175"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
[[package]]
name = "linux-raw-sys"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rustix"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "tempfile"
version = "3.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84fa4d11fadde498443cca10fd3ac23c951f0dc59e080e9f4b93d4df4e4eea53"
dependencies = [
"fastrand",
"getrandom",
"once_cell",
"rustix",
"windows-sys",
]
[[package]]
name = "wasi"
version = "0.14.7+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
dependencies = [
"wasip2",
]
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "windows-link"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
[[package]]
name = "windows-sys"
version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa"
dependencies = [
"windows-link",
]
[[package]]
name = "wit-bindgen"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "xattr"
version = "1.6.1"
dependencies = [
"libc",
"rustix",
"tempfile",
]

58
vendor/xattr/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,58 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "xattr"
version = "1.6.1"
authors = ["Steven Allen <steven@stebalien.com>"]
build = false
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "unix extended filesystem attributes"
documentation = "https://docs.rs/xattr"
readme = "README.md"
keywords = [
"xattr",
"filesystem",
"unix",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/Stebalien/xattr"
[features]
default = ["unsupported"]
unsupported = []
[lib]
name = "xattr"
path = "src/lib.rs"
[[test]]
name = "main"
path = "tests/main.rs"
[dev-dependencies.tempfile]
version = "3"
[target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos", target_os = "hurd"))'.dependencies.rustix]
version = "1.0.0"
features = [
"fs",
"std",
]
default-features = false
[target.'cfg(any(target_os = "freebsd", target_os = "netbsd"))'.dependencies.libc]
version = "0.2.150"

201
vendor/xattr/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
vendor/xattr/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,25 @@
Copyright (c) 2015 Steven Allen
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

19
vendor/xattr/README.md vendored Normal file
View File

@@ -0,0 +1,19 @@
xattr
=====
A small library for setting, getting, and listing extended attributes.
Supported Platforms: Android, Linux, MacOS, FreeBSD, and NetBSD.
API Documentation: https://docs.rs/xattr/latest/xattr/
Unsupported Platforms
--------------------------
This library includes no-op support for unsupported Unix platforms. That is, it will
build on *all* Unix platforms but always fail on unsupported Unix platforms.
1. You can turn this off by disabling the default `unsupported` feature. If you
do so, this library will fail to compile on unsupported platforms.
2. Alternatively, you can detect unsupported platforms at runtime by checking
the `xattr::SUPPORTED_PLATFORM` boolean.

28
vendor/xattr/src/error.rs vendored Normal file
View File

@@ -0,0 +1,28 @@
use std::error::Error;
use std::fmt;
/// The error type returned on unsupported platforms.
///
/// On unsupported platforms, all operations will fail with an `io::Error` with
/// a kind `io::ErrorKind::Unsupported` and an `UnsupportedPlatformError` error as the inner error.
/// While you *could* check the inner error, it's probably simpler just to check
/// `xattr::SUPPORTED_PLATFORM`.
///
/// This error mostly exists for pretty error messages.
#[derive(Copy, Clone, Debug)]
pub struct UnsupportedPlatformError;
impl Error for UnsupportedPlatformError {
fn description(&self) -> &str {
"unsupported platform"
}
}
impl fmt::Display for UnsupportedPlatformError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"unsupported platform, please file a bug at `https://github.com/Stebalien/xattr'"
)
}
}

168
vendor/xattr/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,168 @@
#![allow(clippy::comparison_chain)]
//! A pure-Rust library to manage extended attributes.
//!
//! It provides support for manipulating extended attributes
//! (`xattrs`) on modern Unix filesystems. See the `attr(5)`
//! manpage for more details.
//!
//! An extension trait [`FileExt`] is provided to directly work with
//! standard `File` objects and file descriptors.
//!
//! If the path argument is a symlink, the get/set/list/remove functions
//! operate on the symlink itself. To operate on the symlink target, use
//! the _deref variant of these functions.
//!
//! ```rust
//! let mut xattrs = xattr::list("/").unwrap().peekable();
//!
//! if xattrs.peek().is_none() {
//! println!("no xattr set on root");
//! return;
//! }
//!
//! println!("Extended attributes:");
//! for attr in xattrs {
//! println!(" - {:?}", attr);
//! }
//! ```
mod error;
mod sys;
mod util;
use std::ffi::OsStr;
use std::fs::File;
use std::os::unix::io::{AsRawFd, BorrowedFd};
use std::path::Path;
use std::{fmt, io};
pub use error::UnsupportedPlatformError;
pub use sys::{XAttrs, SUPPORTED_PLATFORM};
/// Get an extended attribute for the specified file.
pub fn get<N, P>(path: P, name: N) -> io::Result<Option<Vec<u8>>>
where
P: AsRef<Path>,
N: AsRef<OsStr>,
{
util::extract_noattr(sys::get_path(path.as_ref(), name.as_ref(), false))
}
/// Get an extended attribute for the specified file (dereference symlinks).
pub fn get_deref<N, P>(path: P, name: N) -> io::Result<Option<Vec<u8>>>
where
P: AsRef<Path>,
N: AsRef<OsStr>,
{
util::extract_noattr(sys::get_path(path.as_ref(), name.as_ref(), true))
}
/// Set an extended attribute on the specified file.
pub fn set<N, P>(path: P, name: N, value: &[u8]) -> io::Result<()>
where
P: AsRef<Path>,
N: AsRef<OsStr>,
{
sys::set_path(path.as_ref(), name.as_ref(), value, false)
}
/// Set an extended attribute on the specified file (dereference symlinks).
pub fn set_deref<N, P>(path: P, name: N, value: &[u8]) -> io::Result<()>
where
P: AsRef<Path>,
N: AsRef<OsStr>,
{
sys::set_path(path.as_ref(), name.as_ref(), value, true)
}
/// Remove an extended attribute from the specified file.
pub fn remove<N, P>(path: P, name: N) -> io::Result<()>
where
P: AsRef<Path>,
N: AsRef<OsStr>,
{
sys::remove_path(path.as_ref(), name.as_ref(), false)
}
/// Remove an extended attribute from the specified file (dereference symlinks).
pub fn remove_deref<N, P>(path: P, name: N) -> io::Result<()>
where
P: AsRef<Path>,
N: AsRef<OsStr>,
{
sys::remove_path(path.as_ref(), name.as_ref(), true)
}
/// List extended attributes attached to the specified file.
///
/// Note: this may not list *all* attributes. Speficially, it definitely won't list any trusted
/// attributes unless you are root and it may not list system attributes.
pub fn list<P>(path: P) -> io::Result<XAttrs>
where
P: AsRef<Path>,
{
sys::list_path(path.as_ref(), false)
}
/// List extended attributes attached to the specified file (dereference symlinks).
pub fn list_deref<P>(path: P) -> io::Result<XAttrs>
where
P: AsRef<Path>,
{
sys::list_path(path.as_ref(), true)
}
/// Extension trait to manipulate extended attributes on `File`-like objects.
pub trait FileExt: AsRawFd {
/// Get an extended attribute for the specified file.
fn get_xattr<N>(&self, name: N) -> io::Result<Option<Vec<u8>>>
where
N: AsRef<OsStr>,
{
// SAFETY: Implement I/O safety later.
let fd = unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) };
util::extract_noattr(sys::get_fd(fd, name.as_ref()))
}
/// Set an extended attribute on the specified file.
fn set_xattr<N>(&self, name: N, value: &[u8]) -> io::Result<()>
where
N: AsRef<OsStr>,
{
let fd = unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) };
sys::set_fd(fd, name.as_ref(), value)
}
/// Remove an extended attribute from the specified file.
fn remove_xattr<N>(&self, name: N) -> io::Result<()>
where
N: AsRef<OsStr>,
{
let fd = unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) };
sys::remove_fd(fd, name.as_ref())
}
/// List extended attributes attached to the specified file.
///
/// Note: this may not list *all* attributes. Speficially, it definitely won't list any trusted
/// attributes unless you are root and it may not list system attributes.
fn list_xattr(&self) -> io::Result<XAttrs> {
let fd = unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) };
sys::list_fd(fd)
}
}
impl FileExt for File {}
impl fmt::Debug for XAttrs {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Waiting on https://github.com/rust-lang/rust/issues/117729 to stabilize...
struct AsList<'a>(&'a XAttrs);
impl<'a> fmt::Debug for AsList<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.0.clone()).finish()
}
}
f.debug_tuple("XAttrs").field(&AsList(self)).finish()
}
}

328
vendor/xattr/src/sys/bsd.rs vendored Normal file
View File

@@ -0,0 +1,328 @@
//! FreeBSD and NetBSD xattr support.
use libc::{c_int, c_void, size_t, EPERM};
use std::ffi::{CString, OsStr, OsString};
use std::mem::MaybeUninit;
use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::os::unix::io::{AsRawFd, BorrowedFd};
use std::path::Path;
use std::ptr;
use std::{io, slice};
use libc::{
extattr_delete_fd, extattr_delete_file, extattr_delete_link, extattr_get_fd, extattr_get_file,
extattr_get_link, extattr_list_fd, extattr_list_file, extattr_list_link, extattr_set_fd,
extattr_set_file, extattr_set_link, EXTATTR_NAMESPACE_SYSTEM, EXTATTR_NAMESPACE_USER,
};
pub const ENOATTR: i32 = libc::ENOATTR;
pub const ERANGE: i32 = libc::ERANGE;
const EXTATTR_NAMESPACE_USER_STRING: &str = "user";
const EXTATTR_NAMESPACE_SYSTEM_STRING: &str = "system";
const EXTATTR_NAMESPACE_NAMES: [&str; 3] = [
"empty",
EXTATTR_NAMESPACE_USER_STRING,
EXTATTR_NAMESPACE_SYSTEM_STRING,
];
fn path_to_c(path: &Path) -> io::Result<CString> {
match CString::new(path.as_os_str().as_bytes()) {
Ok(name) => Ok(name),
Err(_) => Err(io::Error::new(io::ErrorKind::NotFound, "file not found")),
}
}
#[inline]
fn cvt(res: libc::ssize_t) -> io::Result<usize> {
if res < 0 {
Err(io::Error::last_os_error())
} else {
Ok(res as usize)
}
}
#[inline]
fn slice_parts(buf: &mut [MaybeUninit<u8>]) -> (*mut c_void, size_t) {
if buf.is_empty() {
(ptr::null_mut(), 0)
} else {
(buf.as_mut_ptr().cast(), buf.len() as size_t)
}
}
fn allocate_loop<F: Fn(*mut c_void, size_t) -> libc::ssize_t>(f: F) -> io::Result<Vec<u8>> {
crate::util::allocate_loop(
|buf| unsafe {
let (ptr, len) = slice_parts(buf);
let new_len = cvt(f(ptr, len))?;
if new_len < len {
Ok(slice::from_raw_parts_mut(ptr.cast(), new_len))
} else {
// If the length of the value isn't strictly smaller than the length of the value
// read, there may be more to read. Fake an ERANGE error so we can try again with a
// bigger buffer.
Err(io::Error::from_raw_os_error(crate::sys::ERANGE))
}
},
// Estimate size + 1 because, on freebsd, the only way to tell if we've read the entire
// value is read a value smaller than the buffer we passed.
|| Ok(cvt(f(ptr::null_mut(), 0))? + 1),
)
}
/// An iterator over a set of extended attributes names.
#[derive(Default, Clone)]
pub struct XAttrs {
user_attrs: Box<[u8]>,
system_attrs: Box<[u8]>,
offset: usize,
}
impl Iterator for XAttrs {
type Item = OsString;
fn next(&mut self) -> Option<OsString> {
if self.user_attrs.is_empty() && self.system_attrs.is_empty() {
return None;
}
if self.offset == self.user_attrs.len() + self.system_attrs.len() {
return None;
}
let data = if self.offset < self.system_attrs.len() {
&self.system_attrs[self.offset..]
} else {
&self.user_attrs[self.offset - self.system_attrs.len()..]
};
let siz = data[0] as usize;
self.offset += siz + 1;
if self.offset < self.system_attrs.len() {
Some(prefix_namespace(
OsStr::from_bytes(&data[1..siz + 1]),
EXTATTR_NAMESPACE_SYSTEM,
))
} else {
Some(prefix_namespace(
OsStr::from_bytes(&data[1..siz + 1]),
EXTATTR_NAMESPACE_USER,
))
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
if self.user_attrs.len() + self.system_attrs.len() == self.offset {
(0, Some(0))
} else {
(1, None)
}
}
}
// This could use libc::extattr_string_to_namespace, but it's awkward because
// that requires nul-terminated strings, which Rust's std is loathe to provide.
fn name_to_ns(name: &OsStr) -> io::Result<(c_int, CString)> {
let mut groups = name.as_bytes().splitn(2, |&b| b == b'.').take(2);
let nsname = match groups.next() {
Some(s) => s,
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"couldn't find namespace",
))
}
};
let propname = match groups.next() {
Some(s) => s,
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"couldn't find attribute",
))
}
};
let ns_int = match EXTATTR_NAMESPACE_NAMES
.iter()
.position(|&s| s.as_bytes() == nsname)
{
Some(i) => i,
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"no matching namespace",
))
}
};
Ok((ns_int as c_int, CString::new(propname)?))
}
fn prefix_namespace(attr: &OsStr, ns: c_int) -> OsString {
let nsname = EXTATTR_NAMESPACE_NAMES[ns as usize].as_bytes();
let attr = attr.as_bytes();
let mut v = Vec::with_capacity(nsname.len() + attr.len() + 1);
v.extend_from_slice(nsname);
v.extend_from_slice(b".");
v.extend_from_slice(attr);
OsString::from_vec(v)
}
pub fn get_fd(fd: BorrowedFd<'_>, name: &OsStr) -> io::Result<Vec<u8>> {
let (ns, name) = name_to_ns(name)?;
unsafe { allocate_loop(|ptr, len| extattr_get_fd(fd.as_raw_fd(), ns, name.as_ptr(), ptr, len)) }
}
pub fn set_fd(fd: BorrowedFd<'_>, name: &OsStr, value: &[u8]) -> io::Result<()> {
let (ns, name) = name_to_ns(name)?;
let ret = unsafe {
extattr_set_fd(
fd.as_raw_fd(),
ns,
name.as_ptr(),
value.as_ptr() as *const c_void,
value.len() as size_t,
)
};
if ret == -1 {
Err(io::Error::last_os_error())
} else {
Ok(())
}
}
pub fn remove_fd(fd: BorrowedFd<'_>, name: &OsStr) -> io::Result<()> {
let (ns, name) = name_to_ns(name)?;
let ret = unsafe { extattr_delete_fd(fd.as_raw_fd(), ns, name.as_ptr()) };
if ret != 0 {
Err(io::Error::last_os_error())
} else {
Ok(())
}
}
pub fn list_fd(fd: BorrowedFd<'_>) -> io::Result<XAttrs> {
let sysvec = unsafe {
let res = allocate_loop(|ptr, len| {
extattr_list_fd(fd.as_raw_fd(), EXTATTR_NAMESPACE_SYSTEM, ptr, len)
});
// On FreeBSD, system attributes require root privileges to view. However,
// to mimic the behavior of listxattr in linux and osx, we need to query
// them anyway and return empty results if we get EPERM
match res {
Ok(v) => v,
Err(err) => {
if err.raw_os_error() == Some(EPERM) {
Vec::new()
} else {
return Err(err);
}
}
}
};
let uservec = unsafe {
allocate_loop(|ptr, len| extattr_list_fd(fd.as_raw_fd(), EXTATTR_NAMESPACE_USER, ptr, len))?
};
Ok(XAttrs {
system_attrs: sysvec.into_boxed_slice(),
user_attrs: uservec.into_boxed_slice(),
offset: 0,
})
}
pub fn get_path(path: &Path, name: &OsStr, deref: bool) -> io::Result<Vec<u8>> {
let (ns, name) = name_to_ns(name)?;
let path = path_to_c(path)?;
let extattr_get_func = if deref {
extattr_get_file
} else {
extattr_get_link
};
unsafe {
allocate_loop(|ptr, len| extattr_get_func(path.as_ptr(), ns, name.as_ptr(), ptr, len))
}
}
pub fn set_path(path: &Path, name: &OsStr, value: &[u8], deref: bool) -> io::Result<()> {
let (ns, name) = name_to_ns(name)?;
let path = path_to_c(path)?;
let extattr_set_func = if deref {
extattr_set_file
} else {
extattr_set_link
};
let ret = unsafe {
extattr_set_func(
path.as_ptr(),
ns,
name.as_ptr(),
value.as_ptr() as *const c_void,
value.len() as size_t,
)
};
if ret == -1 {
Err(io::Error::last_os_error())
} else {
Ok(())
}
}
pub fn remove_path(path: &Path, name: &OsStr, deref: bool) -> io::Result<()> {
let (ns, name) = name_to_ns(name)?;
let path = path_to_c(path)?;
let extattr_delete_func = if deref {
extattr_delete_file
} else {
extattr_delete_link
};
let ret = unsafe { extattr_delete_func(path.as_ptr(), ns, name.as_ptr()) };
if ret != 0 {
Err(io::Error::last_os_error())
} else {
Ok(())
}
}
pub fn list_path(path: &Path, deref: bool) -> io::Result<XAttrs> {
let path = path_to_c(path)?;
let extattr_list_func = if deref {
extattr_list_file
} else {
extattr_list_link
};
let sysvec = unsafe {
let res = allocate_loop(|ptr, len| {
extattr_list_func(path.as_ptr(), EXTATTR_NAMESPACE_SYSTEM, ptr, len)
});
// On FreeBSD, system attributes require root privileges to view. However,
// to mimic the behavior of listxattr in linux and osx, we need to query
// them anyway and return empty results if we get EPERM
match res {
Ok(v) => v,
Err(err) => {
if err.raw_os_error() == Some(EPERM) {
Vec::new()
} else {
return Err(err);
}
}
}
};
let uservec = unsafe {
allocate_loop(|ptr, len| {
extattr_list_func(path.as_ptr(), EXTATTR_NAMESPACE_USER, ptr, len)
})?
};
Ok(XAttrs {
system_attrs: sysvec.into_boxed_slice(),
user_attrs: uservec.into_boxed_slice(),
offset: 0,
})
}

120
vendor/xattr/src/sys/linux_macos.rs vendored Normal file
View File

@@ -0,0 +1,120 @@
use std::ffi::{OsStr, OsString};
use std::io;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::BorrowedFd;
use std::path::Path;
use rustix::fs as rfs;
#[cfg(not(target_os = "macos"))]
pub const ENOATTR: i32 = rustix::io::Errno::NODATA.raw_os_error();
#[cfg(target_os = "macos")]
pub const ENOATTR: i32 = rustix::io::Errno::NOATTR.raw_os_error();
pub const ERANGE: i32 = rustix::io::Errno::RANGE.raw_os_error();
/// An iterator over a set of extended attributes names.
#[derive(Default, Clone)]
pub struct XAttrs {
data: Box<[u8]>,
offset: usize,
}
// Yes, I could avoid these allocations on linux/macos. However, if we ever want to be freebsd
// compatible, we need to be able to prepend the namespace to the extended attribute names.
// Furthermore, borrowing makes the API messy.
impl Iterator for XAttrs {
type Item = OsString;
fn next(&mut self) -> Option<OsString> {
let data = &self.data[self.offset..];
if data.is_empty() {
None
} else {
// always null terminated (unless empty).
let end = data.iter().position(|&b| b == 0u8).unwrap();
self.offset += end + 1;
Some(OsStr::from_bytes(&data[..end]).to_owned())
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
if self.data.len() == self.offset {
(0, Some(0))
} else {
(1, None)
}
}
}
/// A macro to abstract away some of the boilerplate when calling `allocate_loop` with rustix
/// functions. Unfortunately, we can't write this as a helper function because I need to call
/// generic rustix function with two different types.
macro_rules! allocate_loop {
(|$buf:ident| $($e:tt)*) => {
crate::util::allocate_loop(
|$buf| Ok($($e)*?.0),
|| {
let $buf: &mut [u8] = &mut [];
Ok($($e)*?)
},
)
};
}
pub fn get_fd(fd: BorrowedFd<'_>, name: &OsStr) -> io::Result<Vec<u8>> {
allocate_loop!(|buf| rfs::fgetxattr(fd, name, buf))
}
pub fn set_fd(fd: BorrowedFd<'_>, name: &OsStr, value: &[u8]) -> io::Result<()> {
rfs::fsetxattr(fd, name, value, rfs::XattrFlags::empty())?;
Ok(())
}
pub fn remove_fd(fd: BorrowedFd<'_>, name: &OsStr) -> io::Result<()> {
rfs::fremovexattr(fd, name)?;
Ok(())
}
pub fn list_fd(fd: BorrowedFd<'_>) -> io::Result<XAttrs> {
let vec = allocate_loop!(|buf| rfs::flistxattr(fd, buf))?;
Ok(XAttrs {
data: vec.into_boxed_slice(),
offset: 0,
})
}
pub fn get_path(path: &Path, name: &OsStr, deref: bool) -> io::Result<Vec<u8>> {
if deref {
allocate_loop!(|buf| rfs::getxattr(path, name, buf))
} else {
allocate_loop!(|buf| rfs::lgetxattr(path, name, buf))
}
}
pub fn set_path(path: &Path, name: &OsStr, value: &[u8], deref: bool) -> io::Result<()> {
let setxattr_func = if deref { rfs::setxattr } else { rfs::lsetxattr };
setxattr_func(path, name, value, rfs::XattrFlags::empty())?;
Ok(())
}
pub fn remove_path(path: &Path, name: &OsStr, deref: bool) -> io::Result<()> {
if deref {
rfs::removexattr(path, name)
} else {
rfs::lremovexattr(path, name)
}?;
Ok(())
}
pub fn list_path(path: &Path, deref: bool) -> io::Result<XAttrs> {
let vec = if deref {
allocate_loop!(|buf| rfs::listxattr(path, buf))
} else {
allocate_loop!(|buf| rfs::llistxattr(path, buf))
}?;
Ok(XAttrs {
data: vec.into_boxed_slice(),
offset: 0,
})
}

34
vendor/xattr/src/sys/mod.rs vendored Normal file
View File

@@ -0,0 +1,34 @@
macro_rules! platforms {
($($($platform:expr);* => $module:ident),*) => {
$(
#[cfg(any($(target_os = $platform),*))]
#[cfg_attr(not(any($(target_os = $platform),*)), allow(dead_code))]
mod $module;
#[cfg(any($(target_os = $platform),*))]
pub use self::$module::*;
)*
#[cfg(all(feature = "unsupported", not(any($($(target_os = $platform),*),*))))]
#[cfg_attr(any($($(target_os = $platform),*),*), allow(dead_code))]
mod unsupported;
#[cfg(all(feature = "unsupported", not(any($($(target_os = $platform),*),*))))]
pub use self::unsupported::*;
/// A constant indicating whether or not the target platform is supported.
///
/// To make programmer's lives easier, this library builds on all platforms.
/// However, all function calls on unsupported platforms will return
/// `io::Error`s.
///
/// Note: If you would like compilation to simply fail on unsupported platforms,
/// turn of the `unsupported` feature.
pub const SUPPORTED_PLATFORM: bool = cfg!(any($($(target_os = $platform),*),*));
}
}
platforms! {
"android"; "linux"; "macos"; "hurd" => linux_macos,
"freebsd"; "netbsd" => bsd
}

80
vendor/xattr/src/sys/unsupported.rs vendored Normal file
View File

@@ -0,0 +1,80 @@
use std::ffi::{OsStr, OsString};
use std::io;
use std::os::unix::io::BorrowedFd;
use std::path::Path;
use crate::UnsupportedPlatformError;
pub const ENOATTR: i32 = 0;
pub const ERANGE: i32 = 0;
/// An iterator over a set of extended attributes names.
#[derive(Clone, Default)]
pub struct XAttrs;
impl Iterator for XAttrs {
type Item = OsString;
fn next(&mut self) -> Option<OsString> {
None
}
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
pub fn get_fd(_: BorrowedFd<'_>, _: &OsStr) -> io::Result<Vec<u8>> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn set_fd(_: BorrowedFd<'_>, _: &OsStr, _: &[u8]) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn remove_fd(_: BorrowedFd<'_>, _: &OsStr) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn list_fd(_: BorrowedFd<'_>) -> io::Result<XAttrs> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn get_path(_: &Path, _: &OsStr, _: bool) -> io::Result<Vec<u8>> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn set_path(_: &Path, _: &OsStr, _: &[u8], _: bool) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn remove_path(_: &Path, _: &OsStr, _: bool) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}
pub fn list_path(_: &Path, _: bool) -> io::Result<XAttrs> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
UnsupportedPlatformError,
))
}

57
vendor/xattr/src/util.rs vendored Normal file
View File

@@ -0,0 +1,57 @@
use std::io;
use std::mem::MaybeUninit;
pub fn extract_noattr(result: io::Result<Vec<u8>>) -> io::Result<Option<Vec<u8>>> {
result.map(Some).or_else(|e| {
if e.raw_os_error() == Some(crate::sys::ENOATTR) {
Ok(None)
} else {
Err(e)
}
})
}
/// Calls `get_value` to with a buffer and `get_size` to estimate the size of the buffer if/when
/// `get_value` returns ERANGE.
#[allow(dead_code)]
pub fn allocate_loop<F, S>(mut get_value: F, mut get_size: S) -> io::Result<Vec<u8>>
where
F: for<'a> FnMut(&'a mut [MaybeUninit<u8>]) -> io::Result<&'a mut [u8]>,
S: FnMut() -> io::Result<usize>,
{
// Start by assuming the return value is <= 4KiB. If it is, we can do this in one syscall.
const INITIAL_BUFFER_SIZE: usize = 4096;
match get_value(&mut [MaybeUninit::<u8>::uninit(); INITIAL_BUFFER_SIZE]) {
Ok(val) => return Ok(val.to_vec()),
Err(e) if e.raw_os_error() != Some(crate::sys::ERANGE) => return Err(e),
_ => {}
}
// If that fails, we ask for the size and try again with a buffer of the correct size.
let mut vec: Vec<u8> = Vec::new();
loop {
vec.reserve_exact(get_size()?);
match get_value(vec.spare_capacity_mut()) {
Ok(initialized) => {
unsafe {
let len = initialized.len();
assert_eq!(
initialized.as_ptr(),
vec.as_ptr(),
"expected the same buffer"
);
vec.set_len(len);
}
// Only shrink to fit if we've over-allocated by MORE than one byte. Unfortunately,
// on FreeBSD, we have to over-allocate by one byte to determine if we've read all
// the attributes.
if vec.capacity() > vec.len() + 1 {
vec.shrink_to_fit();
}
return Ok(vec);
}
Err(e) if e.raw_os_error() != Some(crate::sys::ERANGE) => return Err(e),
_ => {} // try again
}
}
}

View File

View File

@@ -0,0 +1 @@
{"name":"xattr","vers":"1.6.1","deps":[{"name":"tempfile","req":"^3","features":[],"optional":false,"default_features":true,"target":null,"kind":"dev","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"rustix","req":"^1.0.0","features":["fs","std"],"optional":false,"default_features":false,"target":"cfg(any(target_os = \"android\", target_os = \"linux\", target_os = \"macos\", target_os = \"hurd\"))","kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"libc","req":"^0.2.150","features":[],"optional":false,"default_features":true,"target":"cfg(any(target_os = \"freebsd\", target_os = \"netbsd\"))","kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false}],"features":{"default":["unsupported"],"unsupported":[]},"features2":null,"cksum":"cc24dabeefc2867f5f721014c5f2c82848f844ed67cac8555059843d0226650f","yanked":null,"links":null,"rust_version":null,"v":2}

Binary file not shown.

Binary file not shown.

249
vendor/xattr/tests/main.rs vendored Normal file
View File

@@ -0,0 +1,249 @@
use std::collections::BTreeSet;
use std::ffi::OsStr;
use xattr::FileExt;
use tempfile::{tempfile, tempfile_in, NamedTempFile};
#[test]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "macos",
target_os = "android"
))]
fn test_fd() {
use std::os::unix::ffi::OsStrExt;
let tmp = tempfile().unwrap();
assert!(tmp.get_xattr("user.test").unwrap().is_none());
assert_eq!(
tmp.list_xattr()
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
tmp.set_xattr("user.test", b"my test").unwrap();
assert_eq!(tmp.get_xattr("user.test").unwrap().unwrap(), b"my test");
assert_eq!(
tmp.list_xattr()
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.collect::<Vec<_>>(),
vec![OsStr::new("user.test")]
);
tmp.remove_xattr("user.test").unwrap();
assert!(tmp.get_xattr("user.test").unwrap().is_none());
assert_eq!(
tmp.list_xattr()
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
}
#[test]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "macos",
target_os = "android"
))]
fn test_path() {
use std::os::unix::ffi::OsStrExt;
let tmp = NamedTempFile::new().unwrap();
assert!(xattr::get(tmp.path(), "user.test").unwrap().is_none());
assert_eq!(
xattr::list(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
xattr::set(tmp.path(), "user.test", b"my test").unwrap();
assert_eq!(
xattr::get(tmp.path(), "user.test").unwrap().unwrap(),
b"my test"
);
assert_eq!(
xattr::list(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.collect::<Vec<_>>(),
vec![OsStr::new("user.test")]
);
xattr::remove(tmp.path(), "user.test").unwrap();
assert!(xattr::get(tmp.path(), "user.test").unwrap().is_none());
assert_eq!(
xattr::list(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
}
#[test]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "macos",
target_os = "android"
))]
fn test_missing() {
assert!(xattr::get("/var/empty/does-not-exist", "user.test").is_err());
}
#[test]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "macos",
target_os = "android"
))]
fn test_debug() {
use std::os::unix::ffi::OsStrExt;
// Only works on "real" filesystems.
let tmp = tempfile().unwrap();
tmp.set_xattr("user.myattr", b"value").unwrap();
let mut attrs = tmp.list_xattr().unwrap();
let debugstr = format!("{:?}", attrs);
// Debug is idempotent
assert_eq!(debugstr, format!("{:?}", attrs));
// It produces the right value. We can't just assert that it's equal to the expected value as
// the system may have added additional attributes (selinux, etc.). See #68.
assert!(debugstr.starts_with("XAttrs(["));
assert!(debugstr.ends_with("])"));
assert!(debugstr.contains(r#""user.myattr""#));
// It doesn't affect the underlying iterator.
assert_eq!(
"user.myattr",
attrs.find(|x| x.as_bytes().starts_with(b"user.")).unwrap()
);
// drain it.
let _ = attrs.by_ref().count();
// An empty iterator produces the right value.
assert_eq!(r#"XAttrs([])"#, format!("{:?}", attrs));
}
#[test]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "macos",
target_os = "android"
))]
fn test_multi() {
use std::os::unix::ffi::OsStrExt;
// Only works on "real" filesystems.
let tmp = tempfile().unwrap();
let mut items: BTreeSet<_> = [
OsStr::new("user.test1"),
OsStr::new("user.test2"),
OsStr::new("user.test3"),
]
.iter()
.cloned()
.collect();
for it in &items {
tmp.set_xattr(it, b"value").unwrap();
}
for it in tmp
.list_xattr()
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
{
assert!(items.remove(&*it));
}
assert!(items.is_empty());
}
// This test is skipped on android because the /data/tmp filesystem doesn't support >4kib of
// extended attributes.
#[test]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
fn test_large() {
use std::ffi::OsString;
use std::os::unix::ffi::OsStrExt;
// On Linux, this only works in tmpfs!
let tmp = if cfg!(target_os = "linux") {
tempfile_in("/dev/shm")
} else {
tempfile()
}
.unwrap();
let mut items: BTreeSet<OsString> = (0..100)
.map(|i| format!("user.test{i:0100}").into())
.collect();
for it in &items {
tmp.set_xattr(it, b"value").unwrap();
}
for it in tmp
.list_xattr()
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
{
assert!(items.remove(&*it));
}
assert!(items.is_empty());
}
// Tests the deref API variants - regression test for
// https://github.com/Stebalien/xattr/issues/57
#[test]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "macos",
target_os = "android"
))]
fn test_path_deref() {
use std::os::unix::ffi::OsStrExt;
// Only works on "real" filesystems.
let tmp = NamedTempFile::new().unwrap();
assert!(xattr::get_deref(tmp.path(), "user.test").unwrap().is_none());
assert_eq!(
xattr::list_deref(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
xattr::set_deref(tmp.path(), "user.test", b"my test").unwrap();
assert_eq!(
xattr::get_deref(tmp.path(), "user.test").unwrap().unwrap(),
b"my test"
);
assert_eq!(
xattr::list_deref(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.collect::<Vec<_>>(),
vec![OsStr::new("user.test")]
);
xattr::remove_deref(tmp.path(), "user.test").unwrap();
assert!(xattr::get_deref(tmp.path(), "user.test").unwrap().is_none());
assert_eq!(
xattr::list_deref(tmp.path())
.unwrap()
.filter(|x| x.as_bytes().starts_with(b"user."))
.count(),
0
);
}