opendal 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +89 -56
- data/Cargo.toml +1 -1
- data/DEPENDENCIES.rust.tsv +55 -41
- data/LICENSE +201 -0
- data/LICENSE-MPL-2.0.txt +373 -0
- data/NOTICE +5 -0
- data/core/CHANGELOG.md +175 -0
- data/core/Cargo.lock +225 -298
- data/core/Cargo.toml +100 -94
- data/core/DEPENDENCIES.rust.tsv +44 -73
- data/core/benches/metadata/README.md +21 -0
- data/core/benches/metadata/main.rs +541 -0
- data/core/benches/vs_fs/Cargo.toml +1 -1
- data/core/benches/vs_s3/Cargo.toml +1 -1
- data/core/core/Cargo.toml +7 -2
- data/core/core/src/blocking/delete.rs +5 -1
- data/core/core/src/blocking/operator.rs +12 -0
- data/core/core/src/blocking/read/std_reader.rs +25 -0
- data/core/core/src/docs/concepts.rs +70 -94
- data/core/core/src/docs/internals/accessor.rs +62 -293
- data/core/core/src/docs/internals/layer.rs +43 -59
- data/core/core/src/docs/internals/mod.rs +21 -23
- data/core/core/src/docs/mod.rs +10 -6
- data/core/core/src/docs/performance/concurrent_write.md +92 -55
- data/core/core/src/docs/performance/http_optimization.md +120 -104
- data/core/core/src/docs/performance/mod.rs +8 -6
- data/core/core/src/docs/rfcs/5485_conditional_reader.md +4 -0
- data/core/core/src/docs/rfcs/7182_restore_api.md +139 -557
- data/core/core/src/docs/rfcs/7945_limited_read.md +210 -0
- data/core/core/src/docs/rfcs/7948_s3_provider_presets.md +254 -0
- data/core/core/src/docs/rfcs/8109_writer_copy_from.md +330 -0
- data/core/core/src/docs/rfcs/8145_conflict_error_kind.md +210 -0
- data/core/core/src/docs/rfcs/8147_write_if_not_changed.md +233 -0
- data/core/core/src/docs/rfcs/8188_compose_api.md +292 -0
- data/core/core/src/docs/rfcs/8194_compact_metadata_and_operation_args.md +444 -0
- data/core/core/src/docs/rfcs/README.md +14 -3
- data/core/core/src/docs/rfcs/mod.rs +46 -22
- data/core/core/src/docs/specs/README.md +34 -0
- data/core/core/src/docs/specs/conditional-operations.md +156 -0
- data/core/core/src/docs/specs/metadata.md +63 -0
- data/core/core/src/docs/specs/mod.rs +26 -0
- data/core/core/src/docs/upgrade.md +114 -1
- data/core/core/src/layers/capability_override.rs +15 -2
- data/core/core/src/layers/complete.rs +347 -43
- data/core/core/src/layers/correctness_check.rs +718 -51
- data/core/core/src/layers/error_context.rs +76 -2
- data/core/core/src/layers/simulate.rs +91 -28
- data/core/core/src/lib.rs +1 -0
- data/core/core/src/raw/accessor.rs +91 -15
- data/core/core/src/raw/enum_utils.rs +7 -0
- data/core/core/src/raw/http_util/header.rs +22 -17
- data/core/core/src/raw/oio/compose/api.rs +92 -0
- data/core/core/src/raw/oio/compose/mod.rs +19 -0
- data/core/core/src/raw/oio/copy/api.rs +3 -3
- data/core/core/src/raw/oio/copy/block_copy.rs +32 -4
- data/core/core/src/raw/oio/copy/multipart_copy.rs +36 -7
- data/core/core/src/raw/oio/entry.rs +48 -22
- data/core/core/src/raw/oio/list/flat_list.rs +1 -1
- data/core/core/src/raw/oio/list/hierarchy_list.rs +3 -2
- data/core/core/src/raw/oio/mod.rs +3 -0
- data/core/core/src/raw/oio/read/position_read.rs +1 -1
- data/core/core/src/raw/oio/write/api.rs +40 -0
- data/core/core/src/raw/oio/write/append_write.rs +4 -4
- data/core/core/src/raw/oio/write/block_write.rs +2 -2
- data/core/core/src/raw/oio/write/multipart_write.rs +181 -48
- data/core/core/src/raw/oio/write/position_write.rs +1 -1
- data/core/core/src/raw/operation.rs +6 -0
- data/core/core/src/raw/ops.rs +1191 -456
- data/core/core/src/raw/rps.rs +11 -0
- data/core/core/src/raw/time.rs +14 -3
- data/core/core/src/services/memory/backend.rs +5 -10
- data/core/core/src/services/memory/lister.rs +4 -4
- data/core/core/src/services/memory/writer.rs +7 -6
- data/core/core/src/types/buffer.rs +102 -12
- data/core/core/src/types/bytes_range.rs +20 -1
- data/core/core/src/types/capability.rs +65 -0
- data/core/core/src/types/compact.rs +329 -0
- data/core/core/src/types/compose/composer.rs +183 -0
- data/core/core/src/types/compose/input.rs +57 -0
- data/core/core/src/types/compose/mod.rs +23 -0
- data/core/core/src/types/context/read.rs +16 -11
- data/core/core/src/types/context/write.rs +150 -2
- data/core/core/src/types/copy.rs +5 -3
- data/core/core/src/types/delete/deleter.rs +20 -12
- data/core/core/src/types/delete/input.rs +22 -64
- data/core/core/src/types/delete/mod.rs +0 -1
- data/core/core/src/types/entry.rs +8 -14
- data/core/core/src/types/error.rs +28 -11
- data/core/core/src/types/metadata.rs +709 -322
- data/core/core/src/types/mod.rs +9 -1
- data/core/core/src/types/operator/operator.rs +278 -29
- data/core/core/src/types/operator/operator_futures.rs +466 -105
- data/core/core/src/types/options.rs +631 -158
- data/core/core/src/types/read/futures_async_reader.rs +663 -50
- data/core/core/src/types/read/reader.rs +23 -5
- data/core/core/src/types/write/futures_async_writer.rs +27 -0
- data/core/core/src/types/write/writer.rs +47 -5
- data/core/http-transports/reqwest/Cargo.toml +1 -1
- data/core/layers/async-backtrace/Cargo.toml +2 -2
- data/core/layers/async-backtrace/src/lib.rs +21 -2
- data/core/layers/await-tree/Cargo.toml +2 -2
- data/core/layers/await-tree/src/lib.rs +25 -2
- data/core/layers/capability-check/Cargo.toml +2 -2
- data/core/layers/capability-check/src/lib.rs +98 -10
- data/core/layers/chaos/Cargo.toml +2 -2
- data/core/layers/chaos/src/lib.rs +18 -3
- data/core/layers/concurrent-limit/Cargo.toml +3 -3
- data/core/layers/concurrent-limit/src/lib.rs +53 -13
- data/core/layers/dtrace/Cargo.toml +2 -2
- data/core/layers/dtrace/src/lib.rs +29 -2
- data/core/layers/fastmetrics/Cargo.toml +3 -3
- data/core/layers/fastrace/Cargo.toml +2 -2
- data/core/layers/fastrace/src/lib.rs +28 -2
- data/core/layers/foyer/Cargo.toml +2 -2
- data/core/layers/foyer/src/full.rs +16 -19
- data/core/layers/foyer/src/lib.rs +67 -14
- data/core/layers/hotpath/Cargo.toml +2 -2
- data/core/layers/hotpath/src/lib.rs +20 -2
- data/core/layers/immutable-index/Cargo.toml +2 -2
- data/core/layers/immutable-index/src/lib.rs +48 -24
- data/core/layers/logging/Cargo.toml +2 -2
- data/core/layers/logging/src/lib.rs +46 -2
- data/core/layers/metrics/Cargo.toml +3 -3
- data/core/layers/mime-guess/Cargo.toml +2 -2
- data/core/layers/mime-guess/src/lib.rs +31 -4
- data/core/layers/observe-metrics-common/Cargo.toml +2 -2
- data/core/layers/observe-metrics-common/src/lib.rs +55 -2
- data/core/layers/otelmetrics/Cargo.toml +3 -3
- data/core/layers/oteltrace/Cargo.toml +2 -2
- data/core/layers/oteltrace/src/lib.rs +27 -2
- data/core/layers/prometheus/Cargo.toml +3 -3
- data/core/layers/prometheus-client/Cargo.toml +3 -3
- data/core/layers/retry/Cargo.toml +4 -4
- data/core/layers/retry/src/lib.rs +76 -19
- data/core/layers/route/Cargo.toml +3 -3
- data/core/layers/route/src/lib.rs +34 -7
- data/core/layers/tail-cut/Cargo.toml +2 -2
- data/core/layers/tail-cut/src/lib.rs +28 -2
- data/core/layers/throttle/Cargo.toml +2 -2
- data/core/layers/throttle/src/lib.rs +19 -2
- data/core/layers/timeout/Cargo.toml +3 -3
- data/core/layers/timeout/src/lib.rs +38 -13
- data/core/layers/tracing/Cargo.toml +2 -2
- data/core/layers/tracing/src/lib.rs +24 -3
- data/core/services/aliyun-drive/Cargo.toml +2 -2
- data/core/services/aliyun-drive/src/backend.rs +34 -24
- data/core/services/aliyun-drive/src/core.rs +143 -54
- data/core/services/aliyun-drive/src/lister.rs +19 -18
- data/core/services/aliyun-drive/src/reader.rs +4 -1
- data/core/services/aliyun-drive/src/writer.rs +3 -3
- data/core/services/alluxio/Cargo.toml +1 -1
- data/core/services/alluxio/src/backend.rs +1 -1
- data/core/services/alluxio/src/core.rs +113 -94
- data/core/services/alluxio/src/reader.rs +7 -3
- data/core/services/alluxio/src/writer.rs +2 -2
- data/core/services/azblob/Cargo.toml +2 -2
- data/core/services/azblob/src/backend.rs +17 -9
- data/core/services/azblob/src/copier.rs +41 -15
- data/core/services/azblob/src/core.rs +372 -135
- data/core/services/azblob/src/deleter.rs +41 -18
- data/core/services/azblob/src/lister.rs +16 -10
- data/core/services/azblob/src/reader.rs +4 -1
- data/core/services/azblob/src/writer.rs +48 -15
- data/core/services/azdls/Cargo.toml +3 -3
- data/core/services/azdls/src/backend.rs +45 -15
- data/core/services/azdls/src/config.rs +4 -1
- data/core/services/azdls/src/core.rs +276 -87
- data/core/services/azdls/src/deleter.rs +13 -4
- data/core/services/azdls/src/lister.rs +18 -12
- data/core/services/azdls/src/reader.rs +6 -2
- data/core/services/azdls/src/writer.rs +44 -23
- data/core/services/azfile/Cargo.toml +2 -2
- data/core/services/azfile/src/backend.rs +24 -8
- data/core/services/azfile/src/core.rs +195 -77
- data/core/services/azfile/src/deleter.rs +8 -1
- data/core/services/azfile/src/lister.rs +20 -14
- data/core/services/azfile/src/reader.rs +5 -2
- data/core/services/azfile/src/writer.rs +27 -15
- data/core/services/azure-common/Cargo.toml +1 -1
- data/core/services/b2/Cargo.toml +2 -2
- data/core/services/b2/src/backend.rs +30 -11
- data/core/services/b2/src/core.rs +134 -120
- data/core/services/b2/src/deleter.rs +1 -1
- data/core/services/b2/src/lister.rs +5 -2
- data/core/services/b2/src/reader.rs +5 -2
- data/core/services/b2/src/writer.rs +29 -12
- data/core/services/cacache/Cargo.toml +1 -1
- data/core/services/cacache/src/backend.rs +4 -5
- data/core/services/cacache/src/reader.rs +4 -1
- data/core/services/cacache/src/writer.rs +6 -2
- data/core/services/cloudflare-kv/Cargo.toml +1 -1
- data/core/services/cloudflare-kv/src/backend.rs +26 -15
- data/core/services/cloudflare-kv/src/config.rs +13 -2
- data/core/services/cloudflare-kv/src/core.rs +62 -56
- data/core/services/cloudflare-kv/src/deleter.rs +12 -3
- data/core/services/cloudflare-kv/src/lister.rs +66 -17
- data/core/services/cloudflare-kv/src/reader.rs +14 -9
- data/core/services/cloudflare-kv/src/writer.rs +10 -7
- data/core/services/compfs/Cargo.toml +1 -1
- data/core/services/compfs/src/backend.rs +11 -7
- data/core/services/compfs/src/lister.rs +7 -7
- data/core/services/compfs/src/writer.rs +1 -1
- data/core/services/cos/Cargo.toml +1 -1
- data/core/services/cos/src/backend.rs +129 -16
- data/core/services/cos/src/core.rs +198 -80
- data/core/services/cos/src/deleter.rs +4 -1
- data/core/services/cos/src/lister.rs +42 -27
- data/core/services/cos/src/reader.rs +6 -2
- data/core/services/cos/src/writer.rs +45 -21
- data/core/services/d1/Cargo.toml +1 -1
- data/core/services/d1/src/backend.rs +6 -5
- data/core/services/d1/src/core.rs +79 -63
- data/core/services/d1/src/reader.rs +4 -1
- data/core/services/d1/src/writer.rs +6 -2
- data/core/services/dashmap/Cargo.toml +1 -1
- data/core/services/dashmap/src/backend.rs +2 -2
- data/core/services/dashmap/src/reader.rs +4 -1
- data/core/services/dashmap/src/writer.rs +11 -8
- data/core/services/dbfs/Cargo.toml +1 -1
- data/core/services/dbfs/src/backend.rs +21 -15
- data/core/services/dbfs/src/core.rs +65 -60
- data/core/services/dbfs/src/deleter.rs +4 -1
- data/core/services/dbfs/src/lister.rs +10 -10
- data/core/services/dbfs/src/writer.rs +6 -3
- data/core/services/dropbox/Cargo.toml +2 -2
- data/core/services/dropbox/src/backend.rs +30 -23
- data/core/services/dropbox/src/core.rs +65 -63
- data/core/services/dropbox/src/deleter.rs +1 -1
- data/core/services/dropbox/src/lister.rs +17 -8
- data/core/services/dropbox/src/reader.rs +4 -1
- data/core/services/dropbox/src/writer.rs +13 -10
- data/core/services/etcd/Cargo.toml +1 -1
- data/core/services/etcd/src/backend.rs +8 -5
- data/core/services/etcd/src/core.rs +5 -11
- data/core/services/etcd/src/lister.rs +6 -1
- data/core/services/etcd/src/reader.rs +4 -1
- data/core/services/etcd/src/writer.rs +6 -3
- data/core/services/foundationdb/Cargo.toml +1 -1
- data/core/services/foundationdb/src/backend.rs +6 -5
- data/core/services/foundationdb/src/reader.rs +4 -1
- data/core/services/foundationdb/src/writer.rs +6 -2
- data/core/services/foyer/Cargo.toml +3 -3
- data/core/services/foyer/src/backend.rs +6 -5
- data/core/services/foyer/src/reader.rs +4 -1
- data/core/services/foyer/src/writer.rs +6 -2
- data/core/services/fs/Cargo.toml +1 -1
- data/core/services/fs/src/backend.rs +4 -3
- data/core/services/fs/src/core.rs +44 -26
- data/core/services/fs/src/lister.rs +9 -6
- data/core/services/fs/src/writer.rs +20 -13
- data/core/services/ftp/Cargo.toml +4 -6
- data/core/services/ftp/src/backend.rs +9 -5
- data/core/services/ftp/src/core.rs +9 -7
- data/core/services/ftp/src/lister.rs +7 -8
- data/core/services/ftp/src/reader.rs +3 -3
- data/core/services/ftp/src/writer.rs +3 -3
- data/core/services/gcs/Cargo.toml +4 -2
- data/core/services/gcs/src/backend.rs +53 -7
- data/core/services/gcs/src/composer.rs +705 -0
- data/core/services/gcs/src/copier.rs +14 -4
- data/core/services/gcs/src/core.rs +828 -124
- data/core/services/gcs/src/deleter.rs +33 -18
- data/core/services/gcs/src/lib.rs +1 -0
- data/core/services/gcs/src/lister.rs +21 -12
- data/core/services/gcs/src/reader.rs +12 -5
- data/core/services/gcs/src/writer.rs +632 -10
- data/core/services/gcs-grpc/Cargo.toml +58 -0
- data/core/services/gcs-grpc/README.md +19 -0
- data/core/services/gcs-grpc/proto/README.md +23 -0
- data/core/services/gcs-grpc/proto/google/storage/v2/storage.proto +171 -0
- data/core/services/gcs-grpc/proto/upstream-descriptor.bin +0 -0
- data/core/services/gcs-grpc/src/backend.rs +449 -0
- data/core/services/gcs-grpc/src/config.rs +116 -0
- data/core/services/gcs-grpc/src/copier.rs +98 -0
- data/core/services/gcs-grpc/src/core.rs +298 -0
- data/core/services/gcs-grpc/src/deleter.rs +65 -0
- data/core/services/gcs-grpc/src/docs.md +19 -0
- data/core/services/gcs-grpc/src/generated/google.storage.v2.rs +541 -0
- data/core/services/gcs-grpc/src/generated/mod.rs +24 -0
- data/core/services/gcs-grpc/src/lib.rs +43 -0
- data/core/services/gcs-grpc/src/lister.rs +125 -0
- data/core/services/gcs-grpc/src/reader.rs +140 -0
- data/core/services/gcs-grpc/src/writer.rs +780 -0
- data/core/services/gdrive/Cargo.toml +2 -2
- data/core/services/gdrive/src/backend.rs +123 -69
- data/core/services/gdrive/src/core.rs +87 -69
- data/core/services/gdrive/src/deleter.rs +8 -2
- data/core/services/gdrive/src/lister.rs +38 -26
- data/core/services/gdrive/src/path_index.rs +2 -2
- data/core/services/gdrive/src/reader.rs +9 -3
- data/core/services/gdrive/src/writer.rs +13 -7
- data/core/services/ghac/Cargo.toml +2 -2
- data/core/services/ghac/src/backend.rs +5 -2
- data/core/services/ghac/src/core.rs +59 -37
- data/core/services/ghac/src/reader.rs +5 -2
- data/core/services/ghac/src/writer.rs +16 -6
- data/core/services/github/Cargo.toml +1 -1
- data/core/services/github/src/backend.rs +16 -8
- data/core/services/github/src/core.rs +88 -76
- data/core/services/github/src/lister.rs +17 -15
- data/core/services/github/src/reader.rs +5 -2
- data/core/services/github/src/writer.rs +12 -6
- data/core/services/goosefs/Cargo.toml +2 -2
- data/core/services/goosefs/src/backend.rs +2 -2
- data/core/services/goosefs/src/core.rs +291 -208
- data/core/services/goosefs/src/docs.md +3 -0
- data/core/services/goosefs/src/lister.rs +2 -3
- data/core/services/goosefs/src/reader.rs +7 -3
- data/core/services/goosefs/src/writer.rs +21 -10
- data/core/services/goosefs/tests/safe_conditional_put.rs +37 -0
- data/core/services/gridfs/Cargo.toml +2 -2
- data/core/services/gridfs/src/backend.rs +12 -8
- data/core/services/gridfs/src/core.rs +1 -1
- data/core/services/gridfs/src/reader.rs +4 -1
- data/core/services/gridfs/src/writer.rs +6 -2
- data/core/services/hdfs/Cargo.toml +1 -1
- data/core/services/hdfs/src/backend.rs +1 -1
- data/core/services/hdfs/src/core.rs +7 -4
- data/core/services/hdfs/src/lister.rs +7 -9
- data/core/services/hdfs/src/writer.rs +5 -1
- data/core/services/hdfs-native/Cargo.toml +1 -1
- data/core/services/hdfs-native/src/backend.rs +1 -1
- data/core/services/hdfs-native/src/core.rs +44 -50
- data/core/services/hdfs-native/src/lister.rs +8 -10
- data/core/services/hdfs-native/src/writer.rs +5 -1
- data/core/services/hf/Cargo.toml +4 -3
- data/core/services/hf/src/backend.rs +4 -3
- data/core/services/hf/src/core.rs +907 -153
- data/core/services/hf/src/lister.rs +16 -6
- data/core/services/hf/src/reader.rs +377 -57
- data/core/services/hf/src/writer.rs +6 -2
- data/core/services/http/Cargo.toml +3 -3
- data/core/services/http/src/backend.rs +8 -6
- data/core/services/http/src/core.rs +57 -35
- data/core/services/http/src/reader.rs +5 -2
- data/core/services/ipfs/Cargo.toml +1 -1
- data/core/services/ipfs/src/backend.rs +20 -9
- data/core/services/ipfs/src/core.rs +43 -34
- data/core/services/ipfs/src/reader.rs +5 -2
- data/core/services/ipmfs/Cargo.toml +1 -1
- data/core/services/ipmfs/src/backend.rs +17 -8
- data/core/services/ipmfs/src/core.rs +66 -60
- data/core/services/ipmfs/src/deleter.rs +5 -2
- data/core/services/ipmfs/src/lister.rs +15 -12
- data/core/services/ipmfs/src/reader.rs +5 -2
- data/core/services/ipmfs/src/writer.rs +6 -3
- data/core/services/koofr/Cargo.toml +2 -2
- data/core/services/koofr/src/backend.rs +46 -17
- data/core/services/koofr/src/core.rs +64 -48
- data/core/services/koofr/src/deleter.rs +4 -1
- data/core/services/koofr/src/lister.rs +11 -10
- data/core/services/koofr/src/reader.rs +5 -2
- data/core/services/koofr/src/writer.rs +13 -7
- data/core/services/lakefs/Cargo.toml +1 -1
- data/core/services/lakefs/src/backend.rs +25 -8
- data/core/services/lakefs/src/core.rs +79 -73
- data/core/services/lakefs/src/deleter.rs +4 -1
- data/core/services/lakefs/src/lister.rs +17 -14
- data/core/services/lakefs/src/reader.rs +5 -2
- data/core/services/lakefs/src/writer.rs +11 -10
- data/core/services/memcached/Cargo.toml +1 -1
- data/core/services/memcached/src/backend.rs +57 -7
- data/core/services/memcached/src/config.rs +13 -2
- data/core/services/memcached/src/core.rs +11 -1
- data/core/services/memcached/src/reader.rs +4 -1
- data/core/services/memcached/src/writer.rs +6 -2
- data/core/services/mini_moka/Cargo.toml +1 -1
- data/core/services/mini_moka/src/backend.rs +8 -8
- data/core/services/mini_moka/src/reader.rs +4 -1
- data/core/services/mini_moka/src/writer.rs +11 -7
- data/core/services/moka/Cargo.toml +1 -1
- data/core/services/moka/src/backend.rs +7 -7
- data/core/services/moka/src/reader.rs +4 -1
- data/core/services/moka/src/writer.rs +10 -6
- data/core/services/mongodb/Cargo.toml +2 -2
- data/core/services/mongodb/src/backend.rs +7 -6
- data/core/services/mongodb/src/core.rs +1 -1
- data/core/services/mongodb/src/reader.rs +4 -1
- data/core/services/mongodb/src/writer.rs +6 -2
- data/core/services/monoiofs/Cargo.toml +2 -2
- data/core/services/monoiofs/src/backend.rs +16 -10
- data/core/services/monoiofs/src/core.rs +8 -9
- data/core/services/monoiofs/src/reader.rs +8 -10
- data/core/services/monoiofs/src/writer.rs +19 -24
- data/core/services/mysql/Cargo.toml +2 -2
- data/core/services/mysql/src/backend.rs +7 -6
- data/core/services/mysql/src/core.rs +1 -1
- data/core/services/mysql/src/lister.rs +7 -3
- data/core/services/mysql/src/reader.rs +4 -1
- data/core/services/mysql/src/writer.rs +6 -2
- data/core/services/obs/Cargo.toml +1 -1
- data/core/services/obs/src/backend.rs +29 -11
- data/core/services/obs/src/core.rs +81 -82
- data/core/services/obs/src/deleter.rs +4 -1
- data/core/services/obs/src/lister.rs +12 -5
- data/core/services/obs/src/reader.rs +5 -2
- data/core/services/obs/src/writer.rs +40 -19
- data/core/services/onedrive/Cargo.toml +2 -2
- data/core/services/onedrive/src/backend.rs +30 -21
- data/core/services/onedrive/src/config.rs +2 -2
- data/core/services/onedrive/src/core.rs +191 -90
- data/core/services/onedrive/src/deleter.rs +5 -2
- data/core/services/onedrive/src/graph_model.rs +10 -51
- data/core/services/onedrive/src/lister.rs +60 -24
- data/core/services/onedrive/src/reader.rs +17 -2
- data/core/services/onedrive/src/writer.rs +26 -15
- data/core/services/opfs/Cargo.toml +1 -1
- data/core/services/opfs/src/backend.rs +6 -13
- data/core/services/opfs/src/core.rs +33 -37
- data/core/services/opfs/src/lister.rs +4 -4
- data/core/services/opfs/src/writer.rs +1 -3
- data/core/services/oss/Cargo.toml +1 -1
- data/core/services/oss/src/backend.rs +40 -8
- data/core/services/oss/src/core.rs +192 -92
- data/core/services/oss/src/deleter.rs +16 -6
- data/core/services/oss/src/lister.rs +43 -27
- data/core/services/oss/src/reader.rs +6 -2
- data/core/services/oss/src/writer.rs +40 -22
- data/core/services/pcloud/Cargo.toml +1 -1
- data/core/services/pcloud/src/backend.rs +40 -6
- data/core/services/pcloud/src/core.rs +80 -66
- data/core/services/pcloud/src/deleter.rs +8 -1
- data/core/services/pcloud/src/lister.rs +4 -1
- data/core/services/pcloud/src/reader.rs +5 -2
- data/core/services/pcloud/src/writer.rs +6 -3
- data/core/services/persy/Cargo.toml +1 -1
- data/core/services/persy/src/backend.rs +6 -5
- data/core/services/persy/src/core.rs +60 -15
- data/core/services/persy/src/reader.rs +4 -1
- data/core/services/persy/src/writer.rs +6 -2
- data/core/services/postgresql/Cargo.toml +2 -2
- data/core/services/postgresql/src/backend.rs +7 -6
- data/core/services/postgresql/src/core.rs +1 -1
- data/core/services/postgresql/src/reader.rs +4 -1
- data/core/services/postgresql/src/writer.rs +6 -2
- data/core/services/redb/Cargo.toml +1 -1
- data/core/services/redb/src/backend.rs +6 -5
- data/core/services/redb/src/reader.rs +4 -1
- data/core/services/redb/src/writer.rs +6 -2
- data/core/services/redis/Cargo.toml +1 -1
- data/core/services/redis/src/backend.rs +18 -8
- data/core/services/redis/src/config.rs +13 -2
- data/core/services/redis/src/reader.rs +8 -4
- data/core/services/redis/src/writer.rs +6 -2
- data/core/services/rocksdb/Cargo.toml +1 -1
- data/core/services/rocksdb/src/backend.rs +6 -5
- data/core/services/rocksdb/src/lister.rs +6 -5
- data/core/services/rocksdb/src/reader.rs +4 -1
- data/core/services/rocksdb/src/writer.rs +6 -2
- data/core/services/s3/Cargo.toml +5 -4
- data/core/services/s3/src/backend.rs +995 -39
- data/core/services/s3/src/compatible_services.md +57 -0
- data/core/services/s3/src/config.rs +16 -0
- data/core/services/s3/src/copier.rs +190 -55
- data/core/services/s3/src/core.rs +299 -190
- data/core/services/s3/src/deleter.rs +26 -7
- data/core/services/s3/src/docs.md +57 -0
- data/core/services/s3/src/lister.rs +55 -36
- data/core/services/s3/src/reader.rs +22 -2
- data/core/services/s3/src/writer.rs +154 -32
- data/core/services/seafile/Cargo.toml +2 -2
- data/core/services/seafile/src/backend.rs +3 -3
- data/core/services/seafile/src/core.rs +105 -79
- data/core/services/seafile/src/lister.rs +11 -8
- data/core/services/seafile/src/reader.rs +5 -2
- data/core/services/seafile/src/writer.rs +6 -3
- data/core/services/sftp/Cargo.toml +1 -1
- data/core/services/sftp/src/backend.rs +19 -4
- data/core/services/sftp/src/core.rs +51 -46
- data/core/services/sftp/src/lister.rs +4 -4
- data/core/services/sftp/src/writer.rs +1 -1
- data/core/services/sled/Cargo.toml +1 -1
- data/core/services/sled/src/backend.rs +6 -5
- data/core/services/sled/src/core.rs +28 -6
- data/core/services/sled/src/lister.rs +6 -5
- data/core/services/sled/src/reader.rs +4 -1
- data/core/services/sled/src/writer.rs +6 -2
- data/core/services/sqlite/Cargo.toml +2 -2
- data/core/services/sqlite/src/backend.rs +12 -7
- data/core/services/sqlite/src/core.rs +3 -3
- data/core/services/sqlite/src/reader.rs +4 -1
- data/core/services/sqlite/src/writer.rs +7 -3
- data/core/services/surrealdb/Cargo.toml +2 -2
- data/core/services/surrealdb/src/backend.rs +7 -6
- data/core/services/surrealdb/src/core.rs +1 -1
- data/core/services/surrealdb/src/reader.rs +4 -1
- data/core/services/surrealdb/src/writer.rs +6 -2
- data/core/services/swift/Cargo.toml +1 -1
- data/core/services/swift/src/backend.rs +38 -8
- data/core/services/swift/src/core.rs +63 -67
- data/core/services/swift/src/deleter.rs +8 -2
- data/core/services/swift/src/lister.rs +11 -8
- data/core/services/swift/src/reader.rs +5 -2
- data/core/services/swift/src/writer.rs +17 -8
- data/core/services/tikv/Cargo.toml +2 -2
- data/core/services/tikv/src/backend.rs +7 -6
- data/core/services/tikv/src/core.rs +31 -14
- data/core/services/tikv/src/reader.rs +4 -1
- data/core/services/tikv/src/writer.rs +6 -2
- data/core/services/tos/Cargo.toml +2 -2
- data/core/services/tos/src/backend.rs +45 -21
- data/core/services/tos/src/copier.rs +44 -17
- data/core/services/tos/src/core.rs +147 -117
- data/core/services/tos/src/deleter.rs +9 -3
- data/core/services/tos/src/docs.md +1 -1
- data/core/services/tos/src/lister.rs +43 -28
- data/core/services/tos/src/reader.rs +5 -2
- data/core/services/tos/src/writer.rs +37 -16
- data/core/services/upyun/Cargo.toml +1 -1
- data/core/services/upyun/src/backend.rs +30 -7
- data/core/services/upyun/src/core.rs +122 -87
- data/core/services/upyun/src/deleter.rs +4 -1
- data/core/services/upyun/src/lister.rs +10 -10
- data/core/services/upyun/src/reader.rs +5 -2
- data/core/services/upyun/src/writer.rs +19 -7
- data/core/services/vercel-artifacts/Cargo.toml +1 -1
- data/core/services/vercel-artifacts/src/backend.rs +6 -3
- data/core/services/vercel-artifacts/src/core.rs +32 -27
- data/core/services/vercel-artifacts/src/reader.rs +5 -2
- data/core/services/vercel-artifacts/src/writer.rs +6 -3
- data/core/services/vercel-blob/Cargo.toml +1 -1
- data/core/services/vercel-blob/src/backend.rs +23 -6
- data/core/services/vercel-blob/src/core.rs +92 -81
- data/core/services/vercel-blob/src/lister.rs +12 -3
- data/core/services/vercel-blob/src/reader.rs +5 -2
- data/core/services/vercel-blob/src/writer.rs +19 -7
- data/core/services/webdav/Cargo.toml +2 -2
- data/core/services/webdav/src/backend.rs +25 -5
- data/core/services/webdav/src/core.rs +116 -59
- data/core/services/webdav/src/deleter.rs +4 -1
- data/core/services/webdav/src/lister.rs +4 -1
- data/core/services/webdav/src/reader.rs +6 -2
- data/core/services/webdav/src/writer.rs +17 -7
- data/core/services/webhdfs/Cargo.toml +2 -2
- data/core/services/webhdfs/src/backend.rs +24 -11
- data/core/services/webhdfs/src/core.rs +99 -98
- data/core/services/webhdfs/src/deleter.rs +5 -2
- data/core/services/webhdfs/src/lister.rs +21 -9
- data/core/services/webhdfs/src/reader.rs +5 -2
- data/core/services/webhdfs/src/writer.rs +49 -14
- data/core/services/yandex-disk/Cargo.toml +1 -1
- data/core/services/yandex-disk/src/backend.rs +28 -6
- data/core/services/yandex-disk/src/core.rs +97 -79
- data/core/services/yandex-disk/src/deleter.rs +4 -1
- data/core/services/yandex-disk/src/lister.rs +25 -9
- data/core/services/yandex-disk/src/reader.rs +5 -2
- data/core/services/yandex-disk/src/writer.rs +6 -3
- data/core/src/lib.rs +5 -0
- data/core/testkit/Cargo.toml +4 -4
- data/core/testkit/src/utils.rs +53 -8
- data/core/tests/behavior/async_compose.rs +297 -0
- data/core/tests/behavior/async_copy.rs +162 -1
- data/core/tests/behavior/async_delete.rs +364 -3
- data/core/tests/behavior/async_read.rs +86 -0
- data/core/tests/behavior/async_restore.rs +162 -0
- data/core/tests/behavior/async_stat.rs +90 -0
- data/core/tests/behavior/async_write.rs +330 -2
- data/core/tests/behavior/main.rs +4 -0
- data/core/upgrade.md +114 -1
- data/src/capability.rs +0 -1
- data/src/io.rs +0 -1
- data/src/lister.rs +0 -1
- data/src/metadata.rs +0 -1
- data/src/operator_info.rs +0 -1
- metadata +44 -2
|
@@ -15,96 +15,182 @@
|
|
|
15
15
|
// specific language governing permissions and limitations
|
|
16
16
|
// under the License.
|
|
17
17
|
|
|
18
|
-
use crate::raw::*;
|
|
19
|
-
use crate::*;
|
|
20
|
-
use std::collections::HashMap;
|
|
21
18
|
use std::fmt;
|
|
19
|
+
use std::str;
|
|
20
|
+
|
|
21
|
+
use crate::EntryMode;
|
|
22
|
+
use crate::raw::Timestamp;
|
|
23
|
+
use crate::types::compact::CompactFieldWriter;
|
|
24
|
+
use crate::types::compact::CompactValues;
|
|
25
|
+
|
|
26
|
+
const MODE_MASK: u16 = 0b11;
|
|
27
|
+
const MODE_FILE: u16 = 0b01;
|
|
28
|
+
const MODE_DIR: u16 = 0b10;
|
|
29
|
+
const IS_CURRENT_MASK: u16 = 0b11 << 2;
|
|
30
|
+
const IS_CURRENT_FALSE: u16 = 0b01 << 2;
|
|
31
|
+
const IS_CURRENT_TRUE: u16 = 0b10 << 2;
|
|
32
|
+
const IS_DELETED: u16 = 1 << 4;
|
|
33
|
+
const HAS_LAST_MODIFIED: u16 = 1 << 5;
|
|
34
|
+
|
|
35
|
+
const STRING_FIELD_COUNT: usize = 7;
|
|
36
|
+
const VALUE_FIELD_COUNT: usize = 9;
|
|
37
|
+
|
|
38
|
+
#[derive(Clone, Copy)]
|
|
39
|
+
#[repr(usize)]
|
|
40
|
+
enum ValueField {
|
|
41
|
+
CacheControl,
|
|
42
|
+
ContentDisposition,
|
|
43
|
+
ContentMd5,
|
|
44
|
+
ContentType,
|
|
45
|
+
ContentEncoding,
|
|
46
|
+
Etag,
|
|
47
|
+
Version,
|
|
48
|
+
UserMetadata,
|
|
49
|
+
Path,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[derive(Clone, Copy, Eq, PartialEq)]
|
|
53
|
+
struct MetadataHeader {
|
|
54
|
+
content_length: u64,
|
|
55
|
+
last_modified_seconds: i64,
|
|
56
|
+
last_modified_nanoseconds: u32,
|
|
57
|
+
flags: u16,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
impl MetadataHeader {
|
|
61
|
+
fn new(mode: EntryMode) -> Self {
|
|
62
|
+
let mut header = Self {
|
|
63
|
+
content_length: 0,
|
|
64
|
+
last_modified_seconds: 0,
|
|
65
|
+
last_modified_nanoseconds: 0,
|
|
66
|
+
flags: 0,
|
|
67
|
+
};
|
|
68
|
+
header.set_mode(mode);
|
|
69
|
+
header
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn mode(&self) -> EntryMode {
|
|
73
|
+
match self.flags & MODE_MASK {
|
|
74
|
+
MODE_FILE => EntryMode::FILE,
|
|
75
|
+
MODE_DIR => EntryMode::DIR,
|
|
76
|
+
_ => EntryMode::Unknown,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fn set_mode(&mut self, mode: EntryMode) {
|
|
81
|
+
self.flags &= !MODE_MASK;
|
|
82
|
+
self.flags |= match mode {
|
|
83
|
+
EntryMode::FILE => MODE_FILE,
|
|
84
|
+
EntryMode::DIR => MODE_DIR,
|
|
85
|
+
EntryMode::Unknown => 0,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn is_current(&self) -> Option<bool> {
|
|
90
|
+
match self.flags & IS_CURRENT_MASK {
|
|
91
|
+
IS_CURRENT_FALSE => Some(false),
|
|
92
|
+
IS_CURRENT_TRUE => Some(true),
|
|
93
|
+
_ => None,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn set_is_current(&mut self, value: Option<bool>) {
|
|
98
|
+
self.flags &= !IS_CURRENT_MASK;
|
|
99
|
+
self.flags |= match value {
|
|
100
|
+
Some(false) => IS_CURRENT_FALSE,
|
|
101
|
+
Some(true) => IS_CURRENT_TRUE,
|
|
102
|
+
None => 0,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn set_flag(&mut self, flag: u16, enabled: bool) {
|
|
107
|
+
if enabled {
|
|
108
|
+
self.flags |= flag;
|
|
109
|
+
} else {
|
|
110
|
+
self.flags &= !flag;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
22
114
|
|
|
23
115
|
/// Metadata contains all the information related to a specific path.
|
|
24
116
|
///
|
|
25
|
-
///
|
|
26
|
-
///
|
|
27
|
-
/// tied to the given context and is not a global state.
|
|
28
|
-
///
|
|
29
|
-
/// ## File Versions
|
|
117
|
+
/// Metadata is tied to the operation that produced it. The same path can have
|
|
118
|
+
/// different metadata across versions or requests.
|
|
30
119
|
///
|
|
31
|
-
///
|
|
32
|
-
/// of a file.
|
|
120
|
+
/// ## File versions
|
|
33
121
|
///
|
|
34
|
-
///
|
|
35
|
-
///
|
|
36
|
-
///
|
|
122
|
+
/// In systems that support versioning, metadata can represent a specific object
|
|
123
|
+
/// version. [`Metadata::version`] returns its version identifier when available.
|
|
124
|
+
/// [`Metadata::is_current`] and [`Metadata::is_deleted`] describe whether that
|
|
125
|
+
/// version is current or deleted.
|
|
37
126
|
///
|
|
38
|
-
///
|
|
127
|
+
/// | `is_current` | `is_deleted` | Meaning |
|
|
128
|
+
/// | --- | --- | --- |
|
|
129
|
+
/// | `Some(true)` | `false` | The current object version. |
|
|
130
|
+
/// | `Some(true)` | `true` | The current delete marker or soft-deleted version. |
|
|
131
|
+
/// | `Some(false)` | `false` | A previous accessible version. |
|
|
132
|
+
/// | `Some(false)` | `true` | A previous deleted version. |
|
|
133
|
+
/// | `None` | `false` | A non-deleted object whose current-version status is unknown. |
|
|
134
|
+
/// | `None` | `true` | A deleted object whose current-version status is unknown. |
|
|
39
135
|
///
|
|
40
|
-
///
|
|
41
|
-
///
|
|
42
|
-
|
|
43
|
-
/// | `Some(true)` | `true` | **The metadata's associated version is the latest, deleted version (Latest Delete Marker or Soft Deleted).** This is particularly important in object storage systems like S3. It signifies that this version is the **most recent delete marker**, indicating the object has been deleted. Subsequent GET requests will return 404 errors unless a specific version ID is provided. |
|
|
44
|
-
/// | `Some(false)` | `false` | **The metadata's associated version is neither the latest version nor deleted.** This indicates that this version is a previous version, still accessible by specifying its version ID. |
|
|
45
|
-
/// | `Some(false)` | `true` | **The metadata's associated version is not the latest version and is deleted.** This represents a historical version that has been marked for deletion. Users will need to specify the version ID to access it, and accessing it may be subject to specific delete marker behavior (e.g., in S3, it might not return actual data but a specific delete marker response). |
|
|
46
|
-
/// | `None` | `false` | **The metadata's associated file is not deleted, but its version status is either unknown or it is not the latest version.** This likely indicates that versioning is not enabled for this file, or versioning information is unavailable. |
|
|
47
|
-
/// | `None` | `true` | **The metadata's associated file is deleted, but its version status is either unknown or it is not the latest version.** This typically means the file was deleted without versioning enabled, or its versioning information is unavailable. This may represent an actual data deletion operation rather than an S3 delete marker. |
|
|
48
|
-
#[derive(Clone, Eq, PartialEq, Default)]
|
|
136
|
+
/// Metadata is an immutable owned value. Use [`MetadataBuilder`] to create a
|
|
137
|
+
/// value and [`Metadata::into_builder`] to create a modified value.
|
|
138
|
+
#[derive(Clone)]
|
|
49
139
|
pub struct Metadata {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
content_encoding: Option<String>,
|
|
61
|
-
etag: Option<String>,
|
|
62
|
-
last_modified: Option<Timestamp>,
|
|
63
|
-
version: Option<String>,
|
|
64
|
-
|
|
65
|
-
user_metadata: Option<HashMap<String, String>>,
|
|
140
|
+
header: MetadataHeader,
|
|
141
|
+
values: CompactValues,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
impl PartialEq for Metadata {
|
|
145
|
+
fn eq(&self, other: &Self) -> bool {
|
|
146
|
+
self.header == other.header
|
|
147
|
+
&& (0..ValueField::Path as usize)
|
|
148
|
+
.all(|field| self.values.get(field) == other.values.get(field))
|
|
149
|
+
}
|
|
66
150
|
}
|
|
67
151
|
|
|
152
|
+
impl Eq for Metadata {}
|
|
153
|
+
|
|
68
154
|
impl fmt::Debug for Metadata {
|
|
69
155
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
70
156
|
let mut ds = f.debug_struct("Metadata");
|
|
71
|
-
ds.field("mode", &self.mode);
|
|
157
|
+
ds.field("mode", &self.mode());
|
|
72
158
|
|
|
73
|
-
if let Some(
|
|
74
|
-
ds.field("is_current", &
|
|
159
|
+
if let Some(value) = self.is_current() {
|
|
160
|
+
ds.field("is_current", &value);
|
|
75
161
|
}
|
|
76
|
-
if self.is_deleted {
|
|
77
|
-
ds.field("is_deleted", &
|
|
162
|
+
if self.is_deleted() {
|
|
163
|
+
ds.field("is_deleted", &true);
|
|
78
164
|
}
|
|
79
|
-
if let Some(
|
|
80
|
-
ds.field("cache_control",
|
|
165
|
+
if let Some(value) = self.cache_control() {
|
|
166
|
+
ds.field("cache_control", &value);
|
|
81
167
|
}
|
|
82
|
-
if let Some(
|
|
83
|
-
ds.field("content_disposition",
|
|
168
|
+
if let Some(value) = self.content_disposition() {
|
|
169
|
+
ds.field("content_disposition", &value);
|
|
84
170
|
}
|
|
85
|
-
if
|
|
86
|
-
ds.field("content_length", &content_length);
|
|
171
|
+
if self.is_file() {
|
|
172
|
+
ds.field("content_length", &self.content_length());
|
|
87
173
|
}
|
|
88
|
-
if let Some(
|
|
89
|
-
ds.field("content_md5",
|
|
174
|
+
if let Some(value) = self.content_md5() {
|
|
175
|
+
ds.field("content_md5", &value);
|
|
90
176
|
}
|
|
91
|
-
if let Some(
|
|
92
|
-
ds.field("content_type",
|
|
177
|
+
if let Some(value) = self.content_type() {
|
|
178
|
+
ds.field("content_type", &value);
|
|
93
179
|
}
|
|
94
|
-
if let Some(
|
|
95
|
-
ds.field("content_encoding",
|
|
180
|
+
if let Some(value) = self.content_encoding() {
|
|
181
|
+
ds.field("content_encoding", &value);
|
|
96
182
|
}
|
|
97
|
-
if let Some(
|
|
98
|
-
ds.field("etag",
|
|
183
|
+
if let Some(value) = self.etag() {
|
|
184
|
+
ds.field("etag", &value);
|
|
99
185
|
}
|
|
100
|
-
if let Some(
|
|
101
|
-
ds.field("last_modified", &
|
|
186
|
+
if let Some(value) = self.last_modified() {
|
|
187
|
+
ds.field("last_modified", &value);
|
|
102
188
|
}
|
|
103
|
-
if let Some(
|
|
104
|
-
ds.field("version",
|
|
189
|
+
if let Some(value) = self.version() {
|
|
190
|
+
ds.field("version", &value);
|
|
105
191
|
}
|
|
106
|
-
if let Some(
|
|
107
|
-
ds.field("user_metadata",
|
|
192
|
+
if let Some(value) = self.user_metadata() {
|
|
193
|
+
ds.field("user_metadata", &value);
|
|
108
194
|
}
|
|
109
195
|
|
|
110
196
|
ds.finish()
|
|
@@ -112,381 +198,682 @@ impl fmt::Debug for Metadata {
|
|
|
112
198
|
}
|
|
113
199
|
|
|
114
200
|
impl Metadata {
|
|
115
|
-
///
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
is_current: None,
|
|
121
|
-
is_deleted: false,
|
|
122
|
-
|
|
123
|
-
cache_control: None,
|
|
124
|
-
content_length: None,
|
|
125
|
-
content_md5: None,
|
|
126
|
-
content_type: None,
|
|
127
|
-
content_encoding: None,
|
|
128
|
-
last_modified: None,
|
|
129
|
-
etag: None,
|
|
130
|
-
content_disposition: None,
|
|
131
|
-
version: None,
|
|
132
|
-
user_metadata: None,
|
|
133
|
-
}
|
|
201
|
+
/// Consume this metadata and return a builder initialized with its values.
|
|
202
|
+
#[inline]
|
|
203
|
+
pub fn into_builder(self) -> MetadataBuilder {
|
|
204
|
+
MetadataBuilder::from_metadata(self)
|
|
134
205
|
}
|
|
135
206
|
|
|
136
|
-
///
|
|
207
|
+
/// Return this entry's mode.
|
|
208
|
+
#[inline]
|
|
137
209
|
pub fn mode(&self) -> EntryMode {
|
|
138
|
-
self.mode
|
|
210
|
+
self.header.mode()
|
|
139
211
|
}
|
|
140
212
|
|
|
141
|
-
///
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
self
|
|
213
|
+
/// Return `true` if this metadata is for a file.
|
|
214
|
+
#[inline]
|
|
215
|
+
pub fn is_file(&self) -> bool {
|
|
216
|
+
self.mode().is_file()
|
|
145
217
|
}
|
|
146
218
|
|
|
147
|
-
///
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
self
|
|
219
|
+
/// Return `true` if this metadata is for a directory.
|
|
220
|
+
#[inline]
|
|
221
|
+
pub fn is_dir(&self) -> bool {
|
|
222
|
+
self.mode().is_dir()
|
|
151
223
|
}
|
|
152
224
|
|
|
153
|
-
///
|
|
154
|
-
|
|
155
|
-
|
|
225
|
+
/// Return whether this metadata describes the current object version.
|
|
226
|
+
///
|
|
227
|
+
/// `None` means the service did not report whether the version is current.
|
|
228
|
+
#[inline]
|
|
229
|
+
pub fn is_current(&self) -> Option<bool> {
|
|
230
|
+
self.header.is_current()
|
|
156
231
|
}
|
|
157
232
|
|
|
158
|
-
///
|
|
159
|
-
|
|
160
|
-
|
|
233
|
+
/// Return whether this metadata describes a deleted object or delete marker.
|
|
234
|
+
#[inline]
|
|
235
|
+
pub fn is_deleted(&self) -> bool {
|
|
236
|
+
self.header.flags & IS_DELETED != 0
|
|
161
237
|
}
|
|
162
238
|
|
|
163
|
-
///
|
|
239
|
+
/// Return this entry's Cache-Control value.
|
|
164
240
|
///
|
|
165
|
-
///
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
///
|
|
172
|
-
/// # Return Value
|
|
241
|
+
/// See [RFC 9111](https://www.rfc-editor.org/rfc/rfc9111.html).
|
|
242
|
+
#[inline]
|
|
243
|
+
pub fn cache_control(&self) -> Option<&str> {
|
|
244
|
+
self.string(ValueField::CacheControl)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/// Return the full content length of this entry.
|
|
173
248
|
///
|
|
174
|
-
///
|
|
249
|
+
/// For file metadata returned by stat, list, or read operations, this value
|
|
250
|
+
/// is the complete object size even when a read returns only a range.
|
|
251
|
+
/// Directory and unknown metadata return zero.
|
|
252
|
+
#[inline]
|
|
253
|
+
pub fn content_length(&self) -> u64 {
|
|
254
|
+
self.header.content_length
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/// Return this entry's Content-MD5 value.
|
|
175
258
|
///
|
|
176
|
-
///
|
|
177
|
-
///
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
/// versioning is not supported or enabled, or if there is insufficient information to ascertain the version status.
|
|
182
|
-
pub fn is_current(&self) -> Option<bool> {
|
|
183
|
-
self.is_current
|
|
259
|
+
/// OpenDAL returns the service-provided value and does not guarantee that it
|
|
260
|
+
/// is the MD5 digest of the content.
|
|
261
|
+
#[inline]
|
|
262
|
+
pub fn content_md5(&self) -> Option<&str> {
|
|
263
|
+
self.string(ValueField::ContentMd5)
|
|
184
264
|
}
|
|
185
265
|
|
|
186
|
-
///
|
|
266
|
+
/// Return this entry's Content-Type value.
|
|
187
267
|
///
|
|
188
|
-
///
|
|
189
|
-
|
|
190
|
-
pub fn
|
|
191
|
-
self.
|
|
192
|
-
self
|
|
268
|
+
/// See [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-type).
|
|
269
|
+
#[inline]
|
|
270
|
+
pub fn content_type(&self) -> Option<&str> {
|
|
271
|
+
self.string(ValueField::ContentType)
|
|
193
272
|
}
|
|
194
273
|
|
|
195
|
-
///
|
|
274
|
+
/// Return this entry's Content-Encoding value.
|
|
196
275
|
///
|
|
197
|
-
///
|
|
198
|
-
|
|
199
|
-
pub fn
|
|
200
|
-
self.
|
|
201
|
-
self
|
|
276
|
+
/// See [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-encoding).
|
|
277
|
+
#[inline]
|
|
278
|
+
pub fn content_encoding(&self) -> Option<&str> {
|
|
279
|
+
self.string(ValueField::ContentEncoding)
|
|
202
280
|
}
|
|
203
281
|
|
|
204
|
-
///
|
|
282
|
+
/// Return this entry's Last-Modified timestamp.
|
|
205
283
|
///
|
|
206
|
-
///
|
|
207
|
-
|
|
208
|
-
|
|
284
|
+
/// See [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#field.last-modified).
|
|
285
|
+
#[inline]
|
|
286
|
+
pub fn last_modified(&self) -> Option<Timestamp> {
|
|
287
|
+
if self.header.flags & HAS_LAST_MODIFIED == 0 {
|
|
288
|
+
return None;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
Some(
|
|
292
|
+
Timestamp::new(
|
|
293
|
+
self.header.last_modified_seconds,
|
|
294
|
+
self.header.last_modified_nanoseconds as i32,
|
|
295
|
+
)
|
|
296
|
+
.expect("metadata stores a previously validated timestamp"),
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/// Return this entry's service-provided ETag as-is.
|
|
209
301
|
///
|
|
210
|
-
///
|
|
302
|
+
/// Quotes and weak-validator prefixes are part of the returned value. See
|
|
303
|
+
/// [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#field.etag).
|
|
304
|
+
#[inline]
|
|
305
|
+
pub fn etag(&self) -> Option<&str> {
|
|
306
|
+
self.string(ValueField::Etag)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/// Return this entry's Content-Disposition value.
|
|
211
310
|
///
|
|
212
|
-
///
|
|
311
|
+
/// See [RFC 6266](https://www.rfc-editor.org/rfc/rfc6266.html).
|
|
312
|
+
#[inline]
|
|
313
|
+
pub fn content_disposition(&self) -> Option<&str> {
|
|
314
|
+
self.string(ValueField::ContentDisposition)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/// Return this entry's service-specific version identifier.
|
|
318
|
+
#[inline]
|
|
319
|
+
pub fn version(&self) -> Option<&str> {
|
|
320
|
+
self.string(ValueField::Version)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/// Return a borrowed view of this entry's user metadata.
|
|
213
324
|
///
|
|
214
|
-
///
|
|
215
|
-
|
|
216
|
-
|
|
325
|
+
/// Service-specific metadata prefixes are removed from the returned keys.
|
|
326
|
+
#[inline]
|
|
327
|
+
pub fn user_metadata(&self) -> Option<UserMetadata<'_>> {
|
|
328
|
+
self.values
|
|
329
|
+
.get(ValueField::UserMetadata as usize)
|
|
330
|
+
.map(UserMetadata::new)
|
|
217
331
|
}
|
|
218
332
|
|
|
219
|
-
|
|
220
|
-
pub fn
|
|
221
|
-
self.
|
|
222
|
-
self
|
|
333
|
+
#[inline]
|
|
334
|
+
pub(crate) fn path(&self) -> Option<&str> {
|
|
335
|
+
self.string(ValueField::Path)
|
|
223
336
|
}
|
|
224
337
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
self.
|
|
228
|
-
self
|
|
338
|
+
#[inline]
|
|
339
|
+
fn string(&self, field: ValueField) -> Option<&str> {
|
|
340
|
+
self.values.get_str(field as usize)
|
|
229
341
|
}
|
|
342
|
+
}
|
|
230
343
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
344
|
+
/// Mutable construction state for [`Metadata`].
|
|
345
|
+
pub struct MetadataBuilder {
|
|
346
|
+
header: MetadataHeader,
|
|
347
|
+
values: CompactValues,
|
|
348
|
+
strings: [Option<String>; STRING_FIELD_COUNT],
|
|
349
|
+
user_metadata: Option<Vec<(String, String)>>,
|
|
350
|
+
path: Option<String>,
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
impl MetadataBuilder {
|
|
354
|
+
/// Create a builder for file metadata with its complete content length.
|
|
355
|
+
#[inline]
|
|
356
|
+
pub fn file(content_length: u64) -> Self {
|
|
357
|
+
let mut builder = Self::fresh(EntryMode::FILE);
|
|
358
|
+
builder.header.content_length = content_length;
|
|
359
|
+
builder
|
|
237
360
|
}
|
|
238
361
|
|
|
239
|
-
///
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
pub fn set_cache_control(&mut self, v: &str) -> &mut Self {
|
|
244
|
-
self.cache_control = Some(v.to_string());
|
|
245
|
-
self
|
|
362
|
+
/// Create a builder for directory metadata.
|
|
363
|
+
#[inline]
|
|
364
|
+
pub fn dir() -> Self {
|
|
365
|
+
Self::fresh(EntryMode::DIR)
|
|
246
366
|
}
|
|
247
367
|
|
|
248
|
-
///
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
pub fn with_cache_control(mut self, v: String) -> Self {
|
|
253
|
-
self.cache_control = Some(v);
|
|
254
|
-
self
|
|
368
|
+
/// Create a builder for metadata whose entry mode is not known.
|
|
369
|
+
#[inline]
|
|
370
|
+
pub fn unknown() -> Self {
|
|
371
|
+
Self::fresh(EntryMode::Unknown)
|
|
255
372
|
}
|
|
256
373
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
/// a range of the object.
|
|
266
|
-
///
|
|
267
|
-
/// # Returns
|
|
268
|
-
///
|
|
269
|
-
/// Content length of this entry. It will be `0` if the content length is not set by the storage services.
|
|
270
|
-
pub fn content_length(&self) -> u64 {
|
|
271
|
-
self.content_length.unwrap_or_default()
|
|
374
|
+
fn fresh(mode: EntryMode) -> Self {
|
|
375
|
+
Self {
|
|
376
|
+
header: MetadataHeader::new(mode),
|
|
377
|
+
values: CompactValues::default(),
|
|
378
|
+
strings: Default::default(),
|
|
379
|
+
user_metadata: None,
|
|
380
|
+
path: None,
|
|
381
|
+
}
|
|
272
382
|
}
|
|
273
383
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
384
|
+
fn from_metadata(metadata: Metadata) -> Self {
|
|
385
|
+
Self {
|
|
386
|
+
header: metadata.header,
|
|
387
|
+
values: metadata.values,
|
|
388
|
+
strings: Default::default(),
|
|
389
|
+
user_metadata: None,
|
|
390
|
+
path: None,
|
|
391
|
+
}
|
|
277
392
|
}
|
|
278
393
|
|
|
279
|
-
/// Set
|
|
280
|
-
pub fn
|
|
281
|
-
self.
|
|
394
|
+
/// Set the entry mode to file and replace its complete content length.
|
|
395
|
+
pub fn set_file(&mut self, content_length: u64) -> &mut Self {
|
|
396
|
+
self.header.set_mode(EntryMode::FILE);
|
|
397
|
+
self.header.content_length = content_length;
|
|
282
398
|
self
|
|
283
399
|
}
|
|
284
400
|
|
|
285
|
-
/// Set
|
|
286
|
-
pub fn
|
|
287
|
-
self.
|
|
401
|
+
/// Set the entry mode to directory and discard any file content length.
|
|
402
|
+
pub fn set_dir(&mut self) -> &mut Self {
|
|
403
|
+
self.header.set_mode(EntryMode::DIR);
|
|
404
|
+
self.header.content_length = 0;
|
|
288
405
|
self
|
|
289
406
|
}
|
|
290
407
|
|
|
291
|
-
///
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
/// OpenDAL will try its best to set this value, but not guarantee this value is the md5 of content.
|
|
297
|
-
pub fn content_md5(&self) -> Option<&str> {
|
|
298
|
-
self.content_md5.as_deref()
|
|
408
|
+
/// Set the entry mode to unknown and discard any file content length.
|
|
409
|
+
pub fn set_unknown(&mut self) -> &mut Self {
|
|
410
|
+
self.header.set_mode(EntryMode::Unknown);
|
|
411
|
+
self.header.content_length = 0;
|
|
412
|
+
self
|
|
299
413
|
}
|
|
300
414
|
|
|
301
|
-
/// Set
|
|
302
|
-
pub fn
|
|
303
|
-
self.
|
|
415
|
+
/// Set whether this metadata describes the current object version.
|
|
416
|
+
pub fn is_current(&mut self, value: Option<bool>) -> &mut Self {
|
|
417
|
+
self.header.set_is_current(value);
|
|
304
418
|
self
|
|
305
419
|
}
|
|
306
420
|
|
|
307
|
-
/// Set
|
|
308
|
-
pub fn
|
|
309
|
-
self.
|
|
421
|
+
/// Set whether this metadata describes a deleted object.
|
|
422
|
+
pub fn is_deleted(&mut self, value: bool) -> &mut Self {
|
|
423
|
+
self.header.set_flag(IS_DELETED, value);
|
|
310
424
|
self
|
|
311
425
|
}
|
|
312
426
|
|
|
313
|
-
///
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
///
|
|
317
|
-
/// Refer to [MDN Content-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) for more information.
|
|
318
|
-
pub fn content_type(&self) -> Option<&str> {
|
|
319
|
-
self.content_type.as_deref()
|
|
427
|
+
/// Set the Cache-Control value.
|
|
428
|
+
pub fn cache_control(&mut self, value: impl Into<String>) -> &mut Self {
|
|
429
|
+
self.set_string(ValueField::CacheControl, value.into())
|
|
320
430
|
}
|
|
321
431
|
|
|
322
|
-
/// Set Content
|
|
323
|
-
pub fn
|
|
324
|
-
self.
|
|
325
|
-
self
|
|
432
|
+
/// Set the Content-MD5 value.
|
|
433
|
+
pub fn content_md5(&mut self, value: impl Into<String>) -> &mut Self {
|
|
434
|
+
self.set_string(ValueField::ContentMd5, value.into())
|
|
326
435
|
}
|
|
327
436
|
|
|
328
|
-
/// Set Content
|
|
329
|
-
pub fn
|
|
330
|
-
self.
|
|
331
|
-
self
|
|
437
|
+
/// Set the Content-Type value.
|
|
438
|
+
pub fn content_type(&mut self, value: impl Into<String>) -> &mut Self {
|
|
439
|
+
self.set_string(ValueField::ContentType, value.into())
|
|
332
440
|
}
|
|
333
441
|
|
|
334
|
-
/// Content
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
///
|
|
338
|
-
/// Refer to [MDN Content-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding) for more information.
|
|
339
|
-
pub fn content_encoding(&self) -> Option<&str> {
|
|
340
|
-
self.content_encoding.as_deref()
|
|
442
|
+
/// Set the Content-Encoding value.
|
|
443
|
+
pub fn content_encoding(&mut self, value: impl Into<String>) -> &mut Self {
|
|
444
|
+
self.set_string(ValueField::ContentEncoding, value.into())
|
|
341
445
|
}
|
|
342
446
|
|
|
343
|
-
/// Set
|
|
344
|
-
pub fn
|
|
345
|
-
|
|
447
|
+
/// Set the last-modified timestamp.
|
|
448
|
+
pub fn last_modified(&mut self, value: Timestamp) -> &mut Self {
|
|
449
|
+
let value = value.into_inner();
|
|
450
|
+
self.header.last_modified_seconds = value.as_second();
|
|
451
|
+
self.header.last_modified_nanoseconds = value.subsec_nanosecond() as u32;
|
|
452
|
+
self.header.set_flag(HAS_LAST_MODIFIED, true);
|
|
346
453
|
self
|
|
347
454
|
}
|
|
348
455
|
|
|
349
|
-
///
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
///
|
|
353
|
-
/// Refer to [MDN Last-Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) for more information.
|
|
354
|
-
pub fn last_modified(&self) -> Option<Timestamp> {
|
|
355
|
-
self.last_modified
|
|
456
|
+
/// Set the ETag.
|
|
457
|
+
pub fn etag(&mut self, value: impl Into<String>) -> &mut Self {
|
|
458
|
+
self.set_string(ValueField::Etag, value.into())
|
|
356
459
|
}
|
|
357
460
|
|
|
358
|
-
/// Set
|
|
359
|
-
pub fn
|
|
360
|
-
self.
|
|
361
|
-
self
|
|
461
|
+
/// Set the Content-Disposition value.
|
|
462
|
+
pub fn content_disposition(&mut self, value: impl Into<String>) -> &mut Self {
|
|
463
|
+
self.set_string(ValueField::ContentDisposition, value.into())
|
|
362
464
|
}
|
|
363
465
|
|
|
364
|
-
/// Set
|
|
365
|
-
pub fn
|
|
366
|
-
self.
|
|
367
|
-
self
|
|
466
|
+
/// Set the object version.
|
|
467
|
+
pub fn version(&mut self, value: impl Into<String>) -> &mut Self {
|
|
468
|
+
self.set_string(ValueField::Version, value.into())
|
|
368
469
|
}
|
|
369
470
|
|
|
370
|
-
///
|
|
471
|
+
/// Set user metadata from owned key-value pairs.
|
|
371
472
|
///
|
|
372
|
-
///
|
|
473
|
+
/// Duplicate keys are rejected because user metadata has map semantics.
|
|
373
474
|
///
|
|
374
|
-
///
|
|
475
|
+
/// # Panics
|
|
375
476
|
///
|
|
376
|
-
///
|
|
477
|
+
/// Panics when `values` contains duplicate keys.
|
|
478
|
+
pub fn user_metadata(
|
|
479
|
+
&mut self,
|
|
480
|
+
values: impl IntoIterator<Item = (String, String)>,
|
|
481
|
+
) -> &mut Self {
|
|
482
|
+
let mut values: Vec<_> = values.into_iter().collect();
|
|
483
|
+
values.sort_unstable_by(|left, right| left.0.cmp(&right.0));
|
|
484
|
+
assert!(
|
|
485
|
+
values.windows(2).all(|pair| pair[0].0 != pair[1].0),
|
|
486
|
+
"user metadata contains duplicate keys"
|
|
487
|
+
);
|
|
488
|
+
self.user_metadata = Some(values);
|
|
489
|
+
self
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/// Finish this builder as immutable metadata.
|
|
377
493
|
///
|
|
378
|
-
///
|
|
379
|
-
/// - `W/"0815"`
|
|
494
|
+
/// # Panics
|
|
380
495
|
///
|
|
381
|
-
///
|
|
382
|
-
pub fn
|
|
383
|
-
|
|
496
|
+
/// Panics when the compact value block, including its index, exceeds `u16::MAX` bytes.
|
|
497
|
+
pub fn build(self) -> Metadata {
|
|
498
|
+
let Self {
|
|
499
|
+
header,
|
|
500
|
+
values,
|
|
501
|
+
strings,
|
|
502
|
+
user_metadata,
|
|
503
|
+
path,
|
|
504
|
+
} = self;
|
|
505
|
+
let has_value_edits =
|
|
506
|
+
strings.iter().any(Option::is_some) || user_metadata.is_some() || path.is_some();
|
|
507
|
+
if !has_value_edits {
|
|
508
|
+
return Metadata { header, values };
|
|
509
|
+
}
|
|
510
|
+
let mut fields = values.fields::<VALUE_FIELD_COUNT>();
|
|
511
|
+
for (index, value) in strings.iter().enumerate() {
|
|
512
|
+
if let Some(value) = value {
|
|
513
|
+
fields[index] = Some(value.as_bytes());
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
let user_metadata = user_metadata.as_deref();
|
|
517
|
+
if let Some(path) = path.as_deref() {
|
|
518
|
+
fields[ValueField::Path as usize] = Some(path.as_bytes());
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let mut lengths = fields.map(|value| value.map(<[u8]>::len));
|
|
522
|
+
if let Some(user_metadata) = user_metadata {
|
|
523
|
+
lengths[ValueField::UserMetadata as usize] =
|
|
524
|
+
Some(user_metadata_encoded_len(user_metadata));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
let values = CompactValues::encode_with(&lengths, |field, output| {
|
|
528
|
+
if field == ValueField::UserMetadata as usize
|
|
529
|
+
&& let Some(user_metadata) = user_metadata
|
|
530
|
+
{
|
|
531
|
+
write_user_metadata(user_metadata, output);
|
|
532
|
+
} else {
|
|
533
|
+
output.write(fields[field].expect("present field has a value"));
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
Metadata { header, values }
|
|
384
538
|
}
|
|
385
539
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
self.etag = Some(v.to_string());
|
|
540
|
+
pub(crate) fn path(&mut self, value: impl Into<String>) -> &mut Self {
|
|
541
|
+
self.path = Some(value.into());
|
|
389
542
|
self
|
|
390
543
|
}
|
|
391
544
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
545
|
+
fn set_string(&mut self, field: ValueField, value: String) -> &mut Self {
|
|
546
|
+
let index = field as usize;
|
|
547
|
+
debug_assert!(index < STRING_FIELD_COUNT);
|
|
548
|
+
self.strings[index] = Some(value);
|
|
395
549
|
self
|
|
396
550
|
}
|
|
551
|
+
}
|
|
397
552
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
553
|
+
/// Borrowed user metadata stored in a [`Metadata`] value.
|
|
554
|
+
#[derive(Clone, Copy)]
|
|
555
|
+
pub struct UserMetadata<'a> {
|
|
556
|
+
encoded: &'a [u8],
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
impl<'a> UserMetadata<'a> {
|
|
560
|
+
#[inline]
|
|
561
|
+
pub(crate) fn new(encoded: &'a [u8]) -> Self {
|
|
562
|
+
Self { encoded }
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/// Return the value associated with `key`.
|
|
566
|
+
#[inline]
|
|
567
|
+
pub fn get(&self, key: &str) -> Option<&'a str> {
|
|
568
|
+
let mut left = 0;
|
|
569
|
+
let mut right = self.len();
|
|
570
|
+
let header_len = 2 + right * 4;
|
|
571
|
+
while left < right {
|
|
572
|
+
let middle = left + (right - left) / 2;
|
|
573
|
+
let (candidate, value) = user_metadata_entry(self.encoded, middle, header_len);
|
|
574
|
+
match candidate.cmp(key) {
|
|
575
|
+
std::cmp::Ordering::Less => left = middle + 1,
|
|
576
|
+
std::cmp::Ordering::Greater => right = middle,
|
|
577
|
+
std::cmp::Ordering::Equal => return Some(value),
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
None
|
|
412
581
|
}
|
|
413
582
|
|
|
414
|
-
///
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
self
|
|
583
|
+
/// Return the number of user metadata pairs.
|
|
584
|
+
#[inline]
|
|
585
|
+
pub fn len(&self) -> usize {
|
|
586
|
+
user_metadata_count(self.encoded)
|
|
418
587
|
}
|
|
419
588
|
|
|
420
|
-
///
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
self
|
|
589
|
+
/// Return `true` when no user metadata pairs are present.
|
|
590
|
+
#[inline]
|
|
591
|
+
pub fn is_empty(&self) -> bool {
|
|
592
|
+
self.len() == 0
|
|
424
593
|
}
|
|
594
|
+
}
|
|
425
595
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
///
|
|
430
|
-
/// # Returns
|
|
431
|
-
///
|
|
432
|
-
/// - `Some(&str)`: If the file has a version associated with it,
|
|
433
|
-
/// this function returns `Some` containing a reference to the version ID string.
|
|
434
|
-
/// - `None`: If the file does not have a version, or if versioning is
|
|
435
|
-
/// not supported or enabled for the underlying storage system, this function
|
|
436
|
-
/// returns `None`.
|
|
437
|
-
pub fn version(&self) -> Option<&str> {
|
|
438
|
-
self.version.as_deref()
|
|
596
|
+
impl fmt::Debug for UserMetadata<'_> {
|
|
597
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
598
|
+
f.debug_map().entries(*self).finish()
|
|
439
599
|
}
|
|
600
|
+
}
|
|
440
601
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
602
|
+
impl serde::Serialize for UserMetadata<'_> {
|
|
603
|
+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
604
|
+
where
|
|
605
|
+
S: serde::Serializer,
|
|
606
|
+
{
|
|
607
|
+
serializer.collect_map(*self)
|
|
445
608
|
}
|
|
609
|
+
}
|
|
446
610
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
611
|
+
/// Iterator over borrowed user metadata pairs.
|
|
612
|
+
pub struct UserMetadataIntoIter<'a> {
|
|
613
|
+
encoded: &'a [u8],
|
|
614
|
+
index: usize,
|
|
615
|
+
header_len: usize,
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
impl<'a> Iterator for UserMetadataIntoIter<'a> {
|
|
619
|
+
type Item = (&'a str, &'a str);
|
|
620
|
+
|
|
621
|
+
fn next(&mut self) -> Option<Self::Item> {
|
|
622
|
+
if 2 + self.index * 4 == self.header_len {
|
|
623
|
+
return None;
|
|
624
|
+
}
|
|
625
|
+
let entry = user_metadata_entry(self.encoded, self.index, self.header_len);
|
|
626
|
+
self.index += 1;
|
|
627
|
+
Some(entry)
|
|
451
628
|
}
|
|
452
629
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
/// is remove from the key
|
|
457
|
-
pub fn user_metadata(&self) -> Option<&HashMap<String, String>> {
|
|
458
|
-
self.user_metadata.as_ref()
|
|
630
|
+
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
631
|
+
let remaining = (self.header_len - 2) / 4 - self.index;
|
|
632
|
+
(remaining, Some(remaining))
|
|
459
633
|
}
|
|
634
|
+
}
|
|
460
635
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
636
|
+
impl ExactSizeIterator for UserMetadataIntoIter<'_> {}
|
|
637
|
+
|
|
638
|
+
impl<'a> IntoIterator for UserMetadata<'a> {
|
|
639
|
+
type Item = (&'a str, &'a str);
|
|
640
|
+
type IntoIter = UserMetadataIntoIter<'a>;
|
|
641
|
+
|
|
642
|
+
fn into_iter(self) -> Self::IntoIter {
|
|
643
|
+
let len = self.len();
|
|
644
|
+
UserMetadataIntoIter {
|
|
645
|
+
encoded: self.encoded,
|
|
646
|
+
index: 0,
|
|
647
|
+
header_len: 2 + len * 4,
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
impl<'a> IntoIterator for &UserMetadata<'a> {
|
|
653
|
+
type Item = (&'a str, &'a str);
|
|
654
|
+
type IntoIter = UserMetadataIntoIter<'a>;
|
|
655
|
+
|
|
656
|
+
fn into_iter(self) -> Self::IntoIter {
|
|
657
|
+
(*self).into_iter()
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
pub(crate) fn user_metadata_encoded_len(values: &[(String, String)]) -> usize {
|
|
662
|
+
u16::try_from(values.len()).expect("user metadata contains too many pairs");
|
|
663
|
+
let header_len = size_of::<u16>() + values.len() * 2 * size_of::<u16>();
|
|
664
|
+
let payload_len: usize = values
|
|
665
|
+
.iter()
|
|
666
|
+
.map(|(key, value)| key.len() + value.len())
|
|
667
|
+
.sum();
|
|
668
|
+
let total_len = header_len
|
|
669
|
+
.checked_add(payload_len)
|
|
670
|
+
.expect("user metadata length overflowed");
|
|
671
|
+
assert!(
|
|
672
|
+
total_len <= u16::MAX as usize,
|
|
673
|
+
"user metadata exceeds 64 KiB"
|
|
674
|
+
);
|
|
675
|
+
total_len
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
pub(crate) fn write_user_metadata(
|
|
679
|
+
values: &[(String, String)],
|
|
680
|
+
output: &mut CompactFieldWriter<'_>,
|
|
681
|
+
) {
|
|
682
|
+
let count = u16::try_from(values.len()).expect("user metadata contains too many pairs");
|
|
683
|
+
let header_len = size_of::<u16>() + values.len() * 2 * size_of::<u16>();
|
|
684
|
+
output.write(&count.to_le_bytes());
|
|
685
|
+
|
|
686
|
+
let mut payload_offset = header_len;
|
|
687
|
+
for (key, value) in values {
|
|
688
|
+
for part in [key.as_bytes(), value.as_bytes()] {
|
|
689
|
+
payload_offset += part.len();
|
|
690
|
+
let end = u16::try_from(payload_offset).expect("user metadata length was validated");
|
|
691
|
+
output.write(&end.to_le_bytes());
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
for (key, value) in values {
|
|
696
|
+
output.write(key.as_bytes());
|
|
697
|
+
output.write(value.as_bytes());
|
|
465
698
|
}
|
|
466
699
|
}
|
|
467
700
|
|
|
701
|
+
#[inline]
|
|
702
|
+
fn user_metadata_count(encoded: &[u8]) -> usize {
|
|
703
|
+
u16::from_le_bytes(
|
|
704
|
+
encoded[..2]
|
|
705
|
+
.try_into()
|
|
706
|
+
.expect("user metadata contains its pair count"),
|
|
707
|
+
) as usize
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
#[inline]
|
|
711
|
+
fn user_metadata_entry(encoded: &[u8], index: usize, header_len: usize) -> (&str, &str) {
|
|
712
|
+
debug_assert!(index * 4 + 6 <= header_len);
|
|
713
|
+
let key_offset = index * 2;
|
|
714
|
+
let key_start = if key_offset == 0 {
|
|
715
|
+
header_len
|
|
716
|
+
} else {
|
|
717
|
+
user_metadata_offset(encoded, key_offset - 1)
|
|
718
|
+
};
|
|
719
|
+
let key_end = user_metadata_offset(encoded, key_offset);
|
|
720
|
+
let value_end = user_metadata_offset(encoded, key_offset + 1);
|
|
721
|
+
(
|
|
722
|
+
// User metadata enters this encoding from owned UTF-8 strings.
|
|
723
|
+
unsafe { str::from_utf8_unchecked(&encoded[key_start..key_end]) },
|
|
724
|
+
// User metadata enters this encoding from owned UTF-8 strings.
|
|
725
|
+
unsafe { str::from_utf8_unchecked(&encoded[key_end..value_end]) },
|
|
726
|
+
)
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
#[inline]
|
|
730
|
+
fn user_metadata_offset(encoded: &[u8], index: usize) -> usize {
|
|
731
|
+
let offset = 2 + index * 2;
|
|
732
|
+
u16::from_le_bytes(
|
|
733
|
+
encoded[offset..offset + 2]
|
|
734
|
+
.try_into()
|
|
735
|
+
.expect("user metadata contains a complete offset"),
|
|
736
|
+
) as usize
|
|
737
|
+
}
|
|
738
|
+
|
|
468
739
|
#[cfg(test)]
|
|
469
740
|
mod tests {
|
|
741
|
+
use std::collections::HashMap;
|
|
742
|
+
|
|
470
743
|
use super::*;
|
|
471
744
|
|
|
745
|
+
#[test]
|
|
746
|
+
fn metadata_layout_is_40_bytes() {
|
|
747
|
+
assert_eq!(size_of::<MetadataHeader>(), 24);
|
|
748
|
+
assert_eq!(size_of::<CompactValues>(), 16);
|
|
749
|
+
assert_eq!(size_of::<Metadata>(), 40);
|
|
750
|
+
}
|
|
751
|
+
|
|
472
752
|
#[test]
|
|
473
753
|
fn debug_metadata_omits_default_values() {
|
|
474
|
-
let metadata =
|
|
754
|
+
let metadata = MetadataBuilder::file(0).build();
|
|
755
|
+
assert_eq!(
|
|
756
|
+
format!("{metadata:?}"),
|
|
757
|
+
"Metadata { mode: FILE, content_length: 0 }"
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
#[test]
|
|
762
|
+
fn metadata_roundtrip() {
|
|
763
|
+
let timestamp = Timestamp::new(-1, -123_456_789).unwrap();
|
|
764
|
+
let mut builder = MetadataBuilder::file(42);
|
|
765
|
+
builder
|
|
766
|
+
.is_current(Some(false))
|
|
767
|
+
.is_deleted(true)
|
|
768
|
+
.last_modified(timestamp)
|
|
769
|
+
.version("v1")
|
|
770
|
+
.user_metadata([
|
|
771
|
+
("owner".to_string(), "opendal".to_string()),
|
|
772
|
+
("region".to_string(), "us-east-1".to_string()),
|
|
773
|
+
]);
|
|
774
|
+
let metadata = builder.build();
|
|
775
|
+
|
|
776
|
+
assert_eq!(metadata.mode(), EntryMode::FILE);
|
|
777
|
+
assert_eq!(metadata.is_current(), Some(false));
|
|
778
|
+
assert!(metadata.is_deleted());
|
|
779
|
+
assert_eq!(metadata.content_length(), 42);
|
|
780
|
+
assert_eq!(metadata.last_modified(), Some(timestamp));
|
|
781
|
+
assert_eq!(metadata.version(), Some("v1"));
|
|
782
|
+
assert_eq!(
|
|
783
|
+
metadata.user_metadata().unwrap().get("owner"),
|
|
784
|
+
Some("opendal")
|
|
785
|
+
);
|
|
786
|
+
assert_eq!(
|
|
787
|
+
metadata
|
|
788
|
+
.user_metadata()
|
|
789
|
+
.unwrap()
|
|
790
|
+
.into_iter()
|
|
791
|
+
.collect::<HashMap<_, _>>()
|
|
792
|
+
.len(),
|
|
793
|
+
2
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
#[test]
|
|
798
|
+
fn into_builder_preserves_values_for_header_changes() {
|
|
799
|
+
let mut builder = MetadataBuilder::file(0);
|
|
800
|
+
builder.etag("etag");
|
|
801
|
+
let metadata = builder.build();
|
|
802
|
+
let cloned = metadata.clone();
|
|
475
803
|
|
|
476
|
-
|
|
804
|
+
let mut builder = metadata.into_builder();
|
|
805
|
+
builder.set_file(42);
|
|
806
|
+
let changed = builder.build();
|
|
807
|
+
|
|
808
|
+
assert_eq!(cloned.content_length(), 0);
|
|
809
|
+
assert_eq!(changed.content_length(), 42);
|
|
810
|
+
assert_eq!(changed.etag(), Some("etag"));
|
|
811
|
+
assert_eq!(cloned.etag(), Some("etag"));
|
|
477
812
|
}
|
|
478
813
|
|
|
479
814
|
#[test]
|
|
480
|
-
fn
|
|
481
|
-
let
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
815
|
+
fn mode_transitions_reset_content_length() {
|
|
816
|
+
let mut builder = MetadataBuilder::file(42);
|
|
817
|
+
builder.set_dir();
|
|
818
|
+
let directory = builder.build();
|
|
819
|
+
assert!(directory.is_dir());
|
|
820
|
+
assert_eq!(directory.content_length(), 0);
|
|
821
|
+
|
|
822
|
+
let mut builder = directory.into_builder();
|
|
823
|
+
builder.set_file(7);
|
|
824
|
+
let file = builder.build();
|
|
825
|
+
assert!(file.is_file());
|
|
826
|
+
assert_eq!(file.content_length(), 7);
|
|
827
|
+
|
|
828
|
+
let mut builder = file.into_builder();
|
|
829
|
+
builder.set_unknown();
|
|
830
|
+
let unknown = builder.build();
|
|
831
|
+
assert_eq!(unknown.mode(), EntryMode::Unknown);
|
|
832
|
+
assert_eq!(unknown.content_length(), 0);
|
|
833
|
+
}
|
|
486
834
|
|
|
835
|
+
#[test]
|
|
836
|
+
fn into_builder_does_not_mutate_shared_packed_values() {
|
|
837
|
+
let mut builder = MetadataBuilder::file(0);
|
|
838
|
+
builder.etag("original").version("version").user_metadata([
|
|
839
|
+
("owner".to_string(), "opendal".to_string()),
|
|
840
|
+
("region".to_string(), "us-east-1".to_string()),
|
|
841
|
+
]);
|
|
842
|
+
let original = builder.build();
|
|
843
|
+
|
|
844
|
+
let mut builder = original.clone().into_builder();
|
|
845
|
+
builder
|
|
846
|
+
.etag("changed")
|
|
847
|
+
.user_metadata([("owner".to_string(), "another-owner".to_string())]);
|
|
848
|
+
let changed = builder.build();
|
|
849
|
+
|
|
850
|
+
assert_eq!(original.etag(), Some("original"));
|
|
851
|
+
assert_eq!(original.version(), Some("version"));
|
|
852
|
+
assert_eq!(original.user_metadata().unwrap().len(), 2);
|
|
853
|
+
assert_eq!(changed.etag(), Some("changed"));
|
|
854
|
+
assert_eq!(changed.version(), Some("version"));
|
|
487
855
|
assert_eq!(
|
|
488
|
-
|
|
489
|
-
"
|
|
856
|
+
changed.user_metadata().unwrap().get("owner"),
|
|
857
|
+
Some("another-owner")
|
|
490
858
|
);
|
|
491
859
|
}
|
|
860
|
+
|
|
861
|
+
#[test]
|
|
862
|
+
fn empty_user_metadata_is_present() {
|
|
863
|
+
let mut builder = MetadataBuilder::file(0);
|
|
864
|
+
builder.user_metadata([]);
|
|
865
|
+
let metadata = builder.build();
|
|
866
|
+
|
|
867
|
+
assert!(metadata.user_metadata().unwrap().is_empty());
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
#[test]
|
|
871
|
+
fn internal_entry_path_does_not_change_metadata_equality() {
|
|
872
|
+
let metadata = MetadataBuilder::file(0).build();
|
|
873
|
+
let mut builder = metadata.clone().into_builder();
|
|
874
|
+
builder.path("path");
|
|
875
|
+
let metadata_with_path = builder.build();
|
|
876
|
+
|
|
877
|
+
assert_eq!(metadata, metadata_with_path);
|
|
878
|
+
}
|
|
492
879
|
}
|