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.
Files changed (566) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +89 -56
  3. data/Cargo.toml +1 -1
  4. data/DEPENDENCIES.rust.tsv +55 -41
  5. data/LICENSE +201 -0
  6. data/LICENSE-MPL-2.0.txt +373 -0
  7. data/NOTICE +5 -0
  8. data/core/CHANGELOG.md +175 -0
  9. data/core/Cargo.lock +225 -298
  10. data/core/Cargo.toml +100 -94
  11. data/core/DEPENDENCIES.rust.tsv +44 -73
  12. data/core/benches/metadata/README.md +21 -0
  13. data/core/benches/metadata/main.rs +541 -0
  14. data/core/benches/vs_fs/Cargo.toml +1 -1
  15. data/core/benches/vs_s3/Cargo.toml +1 -1
  16. data/core/core/Cargo.toml +7 -2
  17. data/core/core/src/blocking/delete.rs +5 -1
  18. data/core/core/src/blocking/operator.rs +12 -0
  19. data/core/core/src/blocking/read/std_reader.rs +25 -0
  20. data/core/core/src/docs/concepts.rs +70 -94
  21. data/core/core/src/docs/internals/accessor.rs +62 -293
  22. data/core/core/src/docs/internals/layer.rs +43 -59
  23. data/core/core/src/docs/internals/mod.rs +21 -23
  24. data/core/core/src/docs/mod.rs +10 -6
  25. data/core/core/src/docs/performance/concurrent_write.md +92 -55
  26. data/core/core/src/docs/performance/http_optimization.md +120 -104
  27. data/core/core/src/docs/performance/mod.rs +8 -6
  28. data/core/core/src/docs/rfcs/5485_conditional_reader.md +4 -0
  29. data/core/core/src/docs/rfcs/7182_restore_api.md +139 -557
  30. data/core/core/src/docs/rfcs/7945_limited_read.md +210 -0
  31. data/core/core/src/docs/rfcs/7948_s3_provider_presets.md +254 -0
  32. data/core/core/src/docs/rfcs/8109_writer_copy_from.md +330 -0
  33. data/core/core/src/docs/rfcs/8145_conflict_error_kind.md +210 -0
  34. data/core/core/src/docs/rfcs/8147_write_if_not_changed.md +233 -0
  35. data/core/core/src/docs/rfcs/8188_compose_api.md +292 -0
  36. data/core/core/src/docs/rfcs/8194_compact_metadata_and_operation_args.md +444 -0
  37. data/core/core/src/docs/rfcs/README.md +14 -3
  38. data/core/core/src/docs/rfcs/mod.rs +46 -22
  39. data/core/core/src/docs/specs/README.md +34 -0
  40. data/core/core/src/docs/specs/conditional-operations.md +156 -0
  41. data/core/core/src/docs/specs/metadata.md +63 -0
  42. data/core/core/src/docs/specs/mod.rs +26 -0
  43. data/core/core/src/docs/upgrade.md +114 -1
  44. data/core/core/src/layers/capability_override.rs +15 -2
  45. data/core/core/src/layers/complete.rs +347 -43
  46. data/core/core/src/layers/correctness_check.rs +718 -51
  47. data/core/core/src/layers/error_context.rs +76 -2
  48. data/core/core/src/layers/simulate.rs +91 -28
  49. data/core/core/src/lib.rs +1 -0
  50. data/core/core/src/raw/accessor.rs +91 -15
  51. data/core/core/src/raw/enum_utils.rs +7 -0
  52. data/core/core/src/raw/http_util/header.rs +22 -17
  53. data/core/core/src/raw/oio/compose/api.rs +92 -0
  54. data/core/core/src/raw/oio/compose/mod.rs +19 -0
  55. data/core/core/src/raw/oio/copy/api.rs +3 -3
  56. data/core/core/src/raw/oio/copy/block_copy.rs +32 -4
  57. data/core/core/src/raw/oio/copy/multipart_copy.rs +36 -7
  58. data/core/core/src/raw/oio/entry.rs +48 -22
  59. data/core/core/src/raw/oio/list/flat_list.rs +1 -1
  60. data/core/core/src/raw/oio/list/hierarchy_list.rs +3 -2
  61. data/core/core/src/raw/oio/mod.rs +3 -0
  62. data/core/core/src/raw/oio/read/position_read.rs +1 -1
  63. data/core/core/src/raw/oio/write/api.rs +40 -0
  64. data/core/core/src/raw/oio/write/append_write.rs +4 -4
  65. data/core/core/src/raw/oio/write/block_write.rs +2 -2
  66. data/core/core/src/raw/oio/write/multipart_write.rs +181 -48
  67. data/core/core/src/raw/oio/write/position_write.rs +1 -1
  68. data/core/core/src/raw/operation.rs +6 -0
  69. data/core/core/src/raw/ops.rs +1191 -456
  70. data/core/core/src/raw/rps.rs +11 -0
  71. data/core/core/src/raw/time.rs +14 -3
  72. data/core/core/src/services/memory/backend.rs +5 -10
  73. data/core/core/src/services/memory/lister.rs +4 -4
  74. data/core/core/src/services/memory/writer.rs +7 -6
  75. data/core/core/src/types/buffer.rs +102 -12
  76. data/core/core/src/types/bytes_range.rs +20 -1
  77. data/core/core/src/types/capability.rs +65 -0
  78. data/core/core/src/types/compact.rs +329 -0
  79. data/core/core/src/types/compose/composer.rs +183 -0
  80. data/core/core/src/types/compose/input.rs +57 -0
  81. data/core/core/src/types/compose/mod.rs +23 -0
  82. data/core/core/src/types/context/read.rs +16 -11
  83. data/core/core/src/types/context/write.rs +150 -2
  84. data/core/core/src/types/copy.rs +5 -3
  85. data/core/core/src/types/delete/deleter.rs +20 -12
  86. data/core/core/src/types/delete/input.rs +22 -64
  87. data/core/core/src/types/delete/mod.rs +0 -1
  88. data/core/core/src/types/entry.rs +8 -14
  89. data/core/core/src/types/error.rs +28 -11
  90. data/core/core/src/types/metadata.rs +709 -322
  91. data/core/core/src/types/mod.rs +9 -1
  92. data/core/core/src/types/operator/operator.rs +278 -29
  93. data/core/core/src/types/operator/operator_futures.rs +466 -105
  94. data/core/core/src/types/options.rs +631 -158
  95. data/core/core/src/types/read/futures_async_reader.rs +663 -50
  96. data/core/core/src/types/read/reader.rs +23 -5
  97. data/core/core/src/types/write/futures_async_writer.rs +27 -0
  98. data/core/core/src/types/write/writer.rs +47 -5
  99. data/core/http-transports/reqwest/Cargo.toml +1 -1
  100. data/core/layers/async-backtrace/Cargo.toml +2 -2
  101. data/core/layers/async-backtrace/src/lib.rs +21 -2
  102. data/core/layers/await-tree/Cargo.toml +2 -2
  103. data/core/layers/await-tree/src/lib.rs +25 -2
  104. data/core/layers/capability-check/Cargo.toml +2 -2
  105. data/core/layers/capability-check/src/lib.rs +98 -10
  106. data/core/layers/chaos/Cargo.toml +2 -2
  107. data/core/layers/chaos/src/lib.rs +18 -3
  108. data/core/layers/concurrent-limit/Cargo.toml +3 -3
  109. data/core/layers/concurrent-limit/src/lib.rs +53 -13
  110. data/core/layers/dtrace/Cargo.toml +2 -2
  111. data/core/layers/dtrace/src/lib.rs +29 -2
  112. data/core/layers/fastmetrics/Cargo.toml +3 -3
  113. data/core/layers/fastrace/Cargo.toml +2 -2
  114. data/core/layers/fastrace/src/lib.rs +28 -2
  115. data/core/layers/foyer/Cargo.toml +2 -2
  116. data/core/layers/foyer/src/full.rs +16 -19
  117. data/core/layers/foyer/src/lib.rs +67 -14
  118. data/core/layers/hotpath/Cargo.toml +2 -2
  119. data/core/layers/hotpath/src/lib.rs +20 -2
  120. data/core/layers/immutable-index/Cargo.toml +2 -2
  121. data/core/layers/immutable-index/src/lib.rs +48 -24
  122. data/core/layers/logging/Cargo.toml +2 -2
  123. data/core/layers/logging/src/lib.rs +46 -2
  124. data/core/layers/metrics/Cargo.toml +3 -3
  125. data/core/layers/mime-guess/Cargo.toml +2 -2
  126. data/core/layers/mime-guess/src/lib.rs +31 -4
  127. data/core/layers/observe-metrics-common/Cargo.toml +2 -2
  128. data/core/layers/observe-metrics-common/src/lib.rs +55 -2
  129. data/core/layers/otelmetrics/Cargo.toml +3 -3
  130. data/core/layers/oteltrace/Cargo.toml +2 -2
  131. data/core/layers/oteltrace/src/lib.rs +27 -2
  132. data/core/layers/prometheus/Cargo.toml +3 -3
  133. data/core/layers/prometheus-client/Cargo.toml +3 -3
  134. data/core/layers/retry/Cargo.toml +4 -4
  135. data/core/layers/retry/src/lib.rs +76 -19
  136. data/core/layers/route/Cargo.toml +3 -3
  137. data/core/layers/route/src/lib.rs +34 -7
  138. data/core/layers/tail-cut/Cargo.toml +2 -2
  139. data/core/layers/tail-cut/src/lib.rs +28 -2
  140. data/core/layers/throttle/Cargo.toml +2 -2
  141. data/core/layers/throttle/src/lib.rs +19 -2
  142. data/core/layers/timeout/Cargo.toml +3 -3
  143. data/core/layers/timeout/src/lib.rs +38 -13
  144. data/core/layers/tracing/Cargo.toml +2 -2
  145. data/core/layers/tracing/src/lib.rs +24 -3
  146. data/core/services/aliyun-drive/Cargo.toml +2 -2
  147. data/core/services/aliyun-drive/src/backend.rs +34 -24
  148. data/core/services/aliyun-drive/src/core.rs +143 -54
  149. data/core/services/aliyun-drive/src/lister.rs +19 -18
  150. data/core/services/aliyun-drive/src/reader.rs +4 -1
  151. data/core/services/aliyun-drive/src/writer.rs +3 -3
  152. data/core/services/alluxio/Cargo.toml +1 -1
  153. data/core/services/alluxio/src/backend.rs +1 -1
  154. data/core/services/alluxio/src/core.rs +113 -94
  155. data/core/services/alluxio/src/reader.rs +7 -3
  156. data/core/services/alluxio/src/writer.rs +2 -2
  157. data/core/services/azblob/Cargo.toml +2 -2
  158. data/core/services/azblob/src/backend.rs +17 -9
  159. data/core/services/azblob/src/copier.rs +41 -15
  160. data/core/services/azblob/src/core.rs +372 -135
  161. data/core/services/azblob/src/deleter.rs +41 -18
  162. data/core/services/azblob/src/lister.rs +16 -10
  163. data/core/services/azblob/src/reader.rs +4 -1
  164. data/core/services/azblob/src/writer.rs +48 -15
  165. data/core/services/azdls/Cargo.toml +3 -3
  166. data/core/services/azdls/src/backend.rs +45 -15
  167. data/core/services/azdls/src/config.rs +4 -1
  168. data/core/services/azdls/src/core.rs +276 -87
  169. data/core/services/azdls/src/deleter.rs +13 -4
  170. data/core/services/azdls/src/lister.rs +18 -12
  171. data/core/services/azdls/src/reader.rs +6 -2
  172. data/core/services/azdls/src/writer.rs +44 -23
  173. data/core/services/azfile/Cargo.toml +2 -2
  174. data/core/services/azfile/src/backend.rs +24 -8
  175. data/core/services/azfile/src/core.rs +195 -77
  176. data/core/services/azfile/src/deleter.rs +8 -1
  177. data/core/services/azfile/src/lister.rs +20 -14
  178. data/core/services/azfile/src/reader.rs +5 -2
  179. data/core/services/azfile/src/writer.rs +27 -15
  180. data/core/services/azure-common/Cargo.toml +1 -1
  181. data/core/services/b2/Cargo.toml +2 -2
  182. data/core/services/b2/src/backend.rs +30 -11
  183. data/core/services/b2/src/core.rs +134 -120
  184. data/core/services/b2/src/deleter.rs +1 -1
  185. data/core/services/b2/src/lister.rs +5 -2
  186. data/core/services/b2/src/reader.rs +5 -2
  187. data/core/services/b2/src/writer.rs +29 -12
  188. data/core/services/cacache/Cargo.toml +1 -1
  189. data/core/services/cacache/src/backend.rs +4 -5
  190. data/core/services/cacache/src/reader.rs +4 -1
  191. data/core/services/cacache/src/writer.rs +6 -2
  192. data/core/services/cloudflare-kv/Cargo.toml +1 -1
  193. data/core/services/cloudflare-kv/src/backend.rs +26 -15
  194. data/core/services/cloudflare-kv/src/config.rs +13 -2
  195. data/core/services/cloudflare-kv/src/core.rs +62 -56
  196. data/core/services/cloudflare-kv/src/deleter.rs +12 -3
  197. data/core/services/cloudflare-kv/src/lister.rs +66 -17
  198. data/core/services/cloudflare-kv/src/reader.rs +14 -9
  199. data/core/services/cloudflare-kv/src/writer.rs +10 -7
  200. data/core/services/compfs/Cargo.toml +1 -1
  201. data/core/services/compfs/src/backend.rs +11 -7
  202. data/core/services/compfs/src/lister.rs +7 -7
  203. data/core/services/compfs/src/writer.rs +1 -1
  204. data/core/services/cos/Cargo.toml +1 -1
  205. data/core/services/cos/src/backend.rs +129 -16
  206. data/core/services/cos/src/core.rs +198 -80
  207. data/core/services/cos/src/deleter.rs +4 -1
  208. data/core/services/cos/src/lister.rs +42 -27
  209. data/core/services/cos/src/reader.rs +6 -2
  210. data/core/services/cos/src/writer.rs +45 -21
  211. data/core/services/d1/Cargo.toml +1 -1
  212. data/core/services/d1/src/backend.rs +6 -5
  213. data/core/services/d1/src/core.rs +79 -63
  214. data/core/services/d1/src/reader.rs +4 -1
  215. data/core/services/d1/src/writer.rs +6 -2
  216. data/core/services/dashmap/Cargo.toml +1 -1
  217. data/core/services/dashmap/src/backend.rs +2 -2
  218. data/core/services/dashmap/src/reader.rs +4 -1
  219. data/core/services/dashmap/src/writer.rs +11 -8
  220. data/core/services/dbfs/Cargo.toml +1 -1
  221. data/core/services/dbfs/src/backend.rs +21 -15
  222. data/core/services/dbfs/src/core.rs +65 -60
  223. data/core/services/dbfs/src/deleter.rs +4 -1
  224. data/core/services/dbfs/src/lister.rs +10 -10
  225. data/core/services/dbfs/src/writer.rs +6 -3
  226. data/core/services/dropbox/Cargo.toml +2 -2
  227. data/core/services/dropbox/src/backend.rs +30 -23
  228. data/core/services/dropbox/src/core.rs +65 -63
  229. data/core/services/dropbox/src/deleter.rs +1 -1
  230. data/core/services/dropbox/src/lister.rs +17 -8
  231. data/core/services/dropbox/src/reader.rs +4 -1
  232. data/core/services/dropbox/src/writer.rs +13 -10
  233. data/core/services/etcd/Cargo.toml +1 -1
  234. data/core/services/etcd/src/backend.rs +8 -5
  235. data/core/services/etcd/src/core.rs +5 -11
  236. data/core/services/etcd/src/lister.rs +6 -1
  237. data/core/services/etcd/src/reader.rs +4 -1
  238. data/core/services/etcd/src/writer.rs +6 -3
  239. data/core/services/foundationdb/Cargo.toml +1 -1
  240. data/core/services/foundationdb/src/backend.rs +6 -5
  241. data/core/services/foundationdb/src/reader.rs +4 -1
  242. data/core/services/foundationdb/src/writer.rs +6 -2
  243. data/core/services/foyer/Cargo.toml +3 -3
  244. data/core/services/foyer/src/backend.rs +6 -5
  245. data/core/services/foyer/src/reader.rs +4 -1
  246. data/core/services/foyer/src/writer.rs +6 -2
  247. data/core/services/fs/Cargo.toml +1 -1
  248. data/core/services/fs/src/backend.rs +4 -3
  249. data/core/services/fs/src/core.rs +44 -26
  250. data/core/services/fs/src/lister.rs +9 -6
  251. data/core/services/fs/src/writer.rs +20 -13
  252. data/core/services/ftp/Cargo.toml +4 -6
  253. data/core/services/ftp/src/backend.rs +9 -5
  254. data/core/services/ftp/src/core.rs +9 -7
  255. data/core/services/ftp/src/lister.rs +7 -8
  256. data/core/services/ftp/src/reader.rs +3 -3
  257. data/core/services/ftp/src/writer.rs +3 -3
  258. data/core/services/gcs/Cargo.toml +4 -2
  259. data/core/services/gcs/src/backend.rs +53 -7
  260. data/core/services/gcs/src/composer.rs +705 -0
  261. data/core/services/gcs/src/copier.rs +14 -4
  262. data/core/services/gcs/src/core.rs +828 -124
  263. data/core/services/gcs/src/deleter.rs +33 -18
  264. data/core/services/gcs/src/lib.rs +1 -0
  265. data/core/services/gcs/src/lister.rs +21 -12
  266. data/core/services/gcs/src/reader.rs +12 -5
  267. data/core/services/gcs/src/writer.rs +632 -10
  268. data/core/services/gcs-grpc/Cargo.toml +58 -0
  269. data/core/services/gcs-grpc/README.md +19 -0
  270. data/core/services/gcs-grpc/proto/README.md +23 -0
  271. data/core/services/gcs-grpc/proto/google/storage/v2/storage.proto +171 -0
  272. data/core/services/gcs-grpc/proto/upstream-descriptor.bin +0 -0
  273. data/core/services/gcs-grpc/src/backend.rs +449 -0
  274. data/core/services/gcs-grpc/src/config.rs +116 -0
  275. data/core/services/gcs-grpc/src/copier.rs +98 -0
  276. data/core/services/gcs-grpc/src/core.rs +298 -0
  277. data/core/services/gcs-grpc/src/deleter.rs +65 -0
  278. data/core/services/gcs-grpc/src/docs.md +19 -0
  279. data/core/services/gcs-grpc/src/generated/google.storage.v2.rs +541 -0
  280. data/core/services/gcs-grpc/src/generated/mod.rs +24 -0
  281. data/core/services/gcs-grpc/src/lib.rs +43 -0
  282. data/core/services/gcs-grpc/src/lister.rs +125 -0
  283. data/core/services/gcs-grpc/src/reader.rs +140 -0
  284. data/core/services/gcs-grpc/src/writer.rs +780 -0
  285. data/core/services/gdrive/Cargo.toml +2 -2
  286. data/core/services/gdrive/src/backend.rs +123 -69
  287. data/core/services/gdrive/src/core.rs +87 -69
  288. data/core/services/gdrive/src/deleter.rs +8 -2
  289. data/core/services/gdrive/src/lister.rs +38 -26
  290. data/core/services/gdrive/src/path_index.rs +2 -2
  291. data/core/services/gdrive/src/reader.rs +9 -3
  292. data/core/services/gdrive/src/writer.rs +13 -7
  293. data/core/services/ghac/Cargo.toml +2 -2
  294. data/core/services/ghac/src/backend.rs +5 -2
  295. data/core/services/ghac/src/core.rs +59 -37
  296. data/core/services/ghac/src/reader.rs +5 -2
  297. data/core/services/ghac/src/writer.rs +16 -6
  298. data/core/services/github/Cargo.toml +1 -1
  299. data/core/services/github/src/backend.rs +16 -8
  300. data/core/services/github/src/core.rs +88 -76
  301. data/core/services/github/src/lister.rs +17 -15
  302. data/core/services/github/src/reader.rs +5 -2
  303. data/core/services/github/src/writer.rs +12 -6
  304. data/core/services/goosefs/Cargo.toml +2 -2
  305. data/core/services/goosefs/src/backend.rs +2 -2
  306. data/core/services/goosefs/src/core.rs +291 -208
  307. data/core/services/goosefs/src/docs.md +3 -0
  308. data/core/services/goosefs/src/lister.rs +2 -3
  309. data/core/services/goosefs/src/reader.rs +7 -3
  310. data/core/services/goosefs/src/writer.rs +21 -10
  311. data/core/services/goosefs/tests/safe_conditional_put.rs +37 -0
  312. data/core/services/gridfs/Cargo.toml +2 -2
  313. data/core/services/gridfs/src/backend.rs +12 -8
  314. data/core/services/gridfs/src/core.rs +1 -1
  315. data/core/services/gridfs/src/reader.rs +4 -1
  316. data/core/services/gridfs/src/writer.rs +6 -2
  317. data/core/services/hdfs/Cargo.toml +1 -1
  318. data/core/services/hdfs/src/backend.rs +1 -1
  319. data/core/services/hdfs/src/core.rs +7 -4
  320. data/core/services/hdfs/src/lister.rs +7 -9
  321. data/core/services/hdfs/src/writer.rs +5 -1
  322. data/core/services/hdfs-native/Cargo.toml +1 -1
  323. data/core/services/hdfs-native/src/backend.rs +1 -1
  324. data/core/services/hdfs-native/src/core.rs +44 -50
  325. data/core/services/hdfs-native/src/lister.rs +8 -10
  326. data/core/services/hdfs-native/src/writer.rs +5 -1
  327. data/core/services/hf/Cargo.toml +4 -3
  328. data/core/services/hf/src/backend.rs +4 -3
  329. data/core/services/hf/src/core.rs +907 -153
  330. data/core/services/hf/src/lister.rs +16 -6
  331. data/core/services/hf/src/reader.rs +377 -57
  332. data/core/services/hf/src/writer.rs +6 -2
  333. data/core/services/http/Cargo.toml +3 -3
  334. data/core/services/http/src/backend.rs +8 -6
  335. data/core/services/http/src/core.rs +57 -35
  336. data/core/services/http/src/reader.rs +5 -2
  337. data/core/services/ipfs/Cargo.toml +1 -1
  338. data/core/services/ipfs/src/backend.rs +20 -9
  339. data/core/services/ipfs/src/core.rs +43 -34
  340. data/core/services/ipfs/src/reader.rs +5 -2
  341. data/core/services/ipmfs/Cargo.toml +1 -1
  342. data/core/services/ipmfs/src/backend.rs +17 -8
  343. data/core/services/ipmfs/src/core.rs +66 -60
  344. data/core/services/ipmfs/src/deleter.rs +5 -2
  345. data/core/services/ipmfs/src/lister.rs +15 -12
  346. data/core/services/ipmfs/src/reader.rs +5 -2
  347. data/core/services/ipmfs/src/writer.rs +6 -3
  348. data/core/services/koofr/Cargo.toml +2 -2
  349. data/core/services/koofr/src/backend.rs +46 -17
  350. data/core/services/koofr/src/core.rs +64 -48
  351. data/core/services/koofr/src/deleter.rs +4 -1
  352. data/core/services/koofr/src/lister.rs +11 -10
  353. data/core/services/koofr/src/reader.rs +5 -2
  354. data/core/services/koofr/src/writer.rs +13 -7
  355. data/core/services/lakefs/Cargo.toml +1 -1
  356. data/core/services/lakefs/src/backend.rs +25 -8
  357. data/core/services/lakefs/src/core.rs +79 -73
  358. data/core/services/lakefs/src/deleter.rs +4 -1
  359. data/core/services/lakefs/src/lister.rs +17 -14
  360. data/core/services/lakefs/src/reader.rs +5 -2
  361. data/core/services/lakefs/src/writer.rs +11 -10
  362. data/core/services/memcached/Cargo.toml +1 -1
  363. data/core/services/memcached/src/backend.rs +57 -7
  364. data/core/services/memcached/src/config.rs +13 -2
  365. data/core/services/memcached/src/core.rs +11 -1
  366. data/core/services/memcached/src/reader.rs +4 -1
  367. data/core/services/memcached/src/writer.rs +6 -2
  368. data/core/services/mini_moka/Cargo.toml +1 -1
  369. data/core/services/mini_moka/src/backend.rs +8 -8
  370. data/core/services/mini_moka/src/reader.rs +4 -1
  371. data/core/services/mini_moka/src/writer.rs +11 -7
  372. data/core/services/moka/Cargo.toml +1 -1
  373. data/core/services/moka/src/backend.rs +7 -7
  374. data/core/services/moka/src/reader.rs +4 -1
  375. data/core/services/moka/src/writer.rs +10 -6
  376. data/core/services/mongodb/Cargo.toml +2 -2
  377. data/core/services/mongodb/src/backend.rs +7 -6
  378. data/core/services/mongodb/src/core.rs +1 -1
  379. data/core/services/mongodb/src/reader.rs +4 -1
  380. data/core/services/mongodb/src/writer.rs +6 -2
  381. data/core/services/monoiofs/Cargo.toml +2 -2
  382. data/core/services/monoiofs/src/backend.rs +16 -10
  383. data/core/services/monoiofs/src/core.rs +8 -9
  384. data/core/services/monoiofs/src/reader.rs +8 -10
  385. data/core/services/monoiofs/src/writer.rs +19 -24
  386. data/core/services/mysql/Cargo.toml +2 -2
  387. data/core/services/mysql/src/backend.rs +7 -6
  388. data/core/services/mysql/src/core.rs +1 -1
  389. data/core/services/mysql/src/lister.rs +7 -3
  390. data/core/services/mysql/src/reader.rs +4 -1
  391. data/core/services/mysql/src/writer.rs +6 -2
  392. data/core/services/obs/Cargo.toml +1 -1
  393. data/core/services/obs/src/backend.rs +29 -11
  394. data/core/services/obs/src/core.rs +81 -82
  395. data/core/services/obs/src/deleter.rs +4 -1
  396. data/core/services/obs/src/lister.rs +12 -5
  397. data/core/services/obs/src/reader.rs +5 -2
  398. data/core/services/obs/src/writer.rs +40 -19
  399. data/core/services/onedrive/Cargo.toml +2 -2
  400. data/core/services/onedrive/src/backend.rs +30 -21
  401. data/core/services/onedrive/src/config.rs +2 -2
  402. data/core/services/onedrive/src/core.rs +191 -90
  403. data/core/services/onedrive/src/deleter.rs +5 -2
  404. data/core/services/onedrive/src/graph_model.rs +10 -51
  405. data/core/services/onedrive/src/lister.rs +60 -24
  406. data/core/services/onedrive/src/reader.rs +17 -2
  407. data/core/services/onedrive/src/writer.rs +26 -15
  408. data/core/services/opfs/Cargo.toml +1 -1
  409. data/core/services/opfs/src/backend.rs +6 -13
  410. data/core/services/opfs/src/core.rs +33 -37
  411. data/core/services/opfs/src/lister.rs +4 -4
  412. data/core/services/opfs/src/writer.rs +1 -3
  413. data/core/services/oss/Cargo.toml +1 -1
  414. data/core/services/oss/src/backend.rs +40 -8
  415. data/core/services/oss/src/core.rs +192 -92
  416. data/core/services/oss/src/deleter.rs +16 -6
  417. data/core/services/oss/src/lister.rs +43 -27
  418. data/core/services/oss/src/reader.rs +6 -2
  419. data/core/services/oss/src/writer.rs +40 -22
  420. data/core/services/pcloud/Cargo.toml +1 -1
  421. data/core/services/pcloud/src/backend.rs +40 -6
  422. data/core/services/pcloud/src/core.rs +80 -66
  423. data/core/services/pcloud/src/deleter.rs +8 -1
  424. data/core/services/pcloud/src/lister.rs +4 -1
  425. data/core/services/pcloud/src/reader.rs +5 -2
  426. data/core/services/pcloud/src/writer.rs +6 -3
  427. data/core/services/persy/Cargo.toml +1 -1
  428. data/core/services/persy/src/backend.rs +6 -5
  429. data/core/services/persy/src/core.rs +60 -15
  430. data/core/services/persy/src/reader.rs +4 -1
  431. data/core/services/persy/src/writer.rs +6 -2
  432. data/core/services/postgresql/Cargo.toml +2 -2
  433. data/core/services/postgresql/src/backend.rs +7 -6
  434. data/core/services/postgresql/src/core.rs +1 -1
  435. data/core/services/postgresql/src/reader.rs +4 -1
  436. data/core/services/postgresql/src/writer.rs +6 -2
  437. data/core/services/redb/Cargo.toml +1 -1
  438. data/core/services/redb/src/backend.rs +6 -5
  439. data/core/services/redb/src/reader.rs +4 -1
  440. data/core/services/redb/src/writer.rs +6 -2
  441. data/core/services/redis/Cargo.toml +1 -1
  442. data/core/services/redis/src/backend.rs +18 -8
  443. data/core/services/redis/src/config.rs +13 -2
  444. data/core/services/redis/src/reader.rs +8 -4
  445. data/core/services/redis/src/writer.rs +6 -2
  446. data/core/services/rocksdb/Cargo.toml +1 -1
  447. data/core/services/rocksdb/src/backend.rs +6 -5
  448. data/core/services/rocksdb/src/lister.rs +6 -5
  449. data/core/services/rocksdb/src/reader.rs +4 -1
  450. data/core/services/rocksdb/src/writer.rs +6 -2
  451. data/core/services/s3/Cargo.toml +5 -4
  452. data/core/services/s3/src/backend.rs +995 -39
  453. data/core/services/s3/src/compatible_services.md +57 -0
  454. data/core/services/s3/src/config.rs +16 -0
  455. data/core/services/s3/src/copier.rs +190 -55
  456. data/core/services/s3/src/core.rs +299 -190
  457. data/core/services/s3/src/deleter.rs +26 -7
  458. data/core/services/s3/src/docs.md +57 -0
  459. data/core/services/s3/src/lister.rs +55 -36
  460. data/core/services/s3/src/reader.rs +22 -2
  461. data/core/services/s3/src/writer.rs +154 -32
  462. data/core/services/seafile/Cargo.toml +2 -2
  463. data/core/services/seafile/src/backend.rs +3 -3
  464. data/core/services/seafile/src/core.rs +105 -79
  465. data/core/services/seafile/src/lister.rs +11 -8
  466. data/core/services/seafile/src/reader.rs +5 -2
  467. data/core/services/seafile/src/writer.rs +6 -3
  468. data/core/services/sftp/Cargo.toml +1 -1
  469. data/core/services/sftp/src/backend.rs +19 -4
  470. data/core/services/sftp/src/core.rs +51 -46
  471. data/core/services/sftp/src/lister.rs +4 -4
  472. data/core/services/sftp/src/writer.rs +1 -1
  473. data/core/services/sled/Cargo.toml +1 -1
  474. data/core/services/sled/src/backend.rs +6 -5
  475. data/core/services/sled/src/core.rs +28 -6
  476. data/core/services/sled/src/lister.rs +6 -5
  477. data/core/services/sled/src/reader.rs +4 -1
  478. data/core/services/sled/src/writer.rs +6 -2
  479. data/core/services/sqlite/Cargo.toml +2 -2
  480. data/core/services/sqlite/src/backend.rs +12 -7
  481. data/core/services/sqlite/src/core.rs +3 -3
  482. data/core/services/sqlite/src/reader.rs +4 -1
  483. data/core/services/sqlite/src/writer.rs +7 -3
  484. data/core/services/surrealdb/Cargo.toml +2 -2
  485. data/core/services/surrealdb/src/backend.rs +7 -6
  486. data/core/services/surrealdb/src/core.rs +1 -1
  487. data/core/services/surrealdb/src/reader.rs +4 -1
  488. data/core/services/surrealdb/src/writer.rs +6 -2
  489. data/core/services/swift/Cargo.toml +1 -1
  490. data/core/services/swift/src/backend.rs +38 -8
  491. data/core/services/swift/src/core.rs +63 -67
  492. data/core/services/swift/src/deleter.rs +8 -2
  493. data/core/services/swift/src/lister.rs +11 -8
  494. data/core/services/swift/src/reader.rs +5 -2
  495. data/core/services/swift/src/writer.rs +17 -8
  496. data/core/services/tikv/Cargo.toml +2 -2
  497. data/core/services/tikv/src/backend.rs +7 -6
  498. data/core/services/tikv/src/core.rs +31 -14
  499. data/core/services/tikv/src/reader.rs +4 -1
  500. data/core/services/tikv/src/writer.rs +6 -2
  501. data/core/services/tos/Cargo.toml +2 -2
  502. data/core/services/tos/src/backend.rs +45 -21
  503. data/core/services/tos/src/copier.rs +44 -17
  504. data/core/services/tos/src/core.rs +147 -117
  505. data/core/services/tos/src/deleter.rs +9 -3
  506. data/core/services/tos/src/docs.md +1 -1
  507. data/core/services/tos/src/lister.rs +43 -28
  508. data/core/services/tos/src/reader.rs +5 -2
  509. data/core/services/tos/src/writer.rs +37 -16
  510. data/core/services/upyun/Cargo.toml +1 -1
  511. data/core/services/upyun/src/backend.rs +30 -7
  512. data/core/services/upyun/src/core.rs +122 -87
  513. data/core/services/upyun/src/deleter.rs +4 -1
  514. data/core/services/upyun/src/lister.rs +10 -10
  515. data/core/services/upyun/src/reader.rs +5 -2
  516. data/core/services/upyun/src/writer.rs +19 -7
  517. data/core/services/vercel-artifacts/Cargo.toml +1 -1
  518. data/core/services/vercel-artifacts/src/backend.rs +6 -3
  519. data/core/services/vercel-artifacts/src/core.rs +32 -27
  520. data/core/services/vercel-artifacts/src/reader.rs +5 -2
  521. data/core/services/vercel-artifacts/src/writer.rs +6 -3
  522. data/core/services/vercel-blob/Cargo.toml +1 -1
  523. data/core/services/vercel-blob/src/backend.rs +23 -6
  524. data/core/services/vercel-blob/src/core.rs +92 -81
  525. data/core/services/vercel-blob/src/lister.rs +12 -3
  526. data/core/services/vercel-blob/src/reader.rs +5 -2
  527. data/core/services/vercel-blob/src/writer.rs +19 -7
  528. data/core/services/webdav/Cargo.toml +2 -2
  529. data/core/services/webdav/src/backend.rs +25 -5
  530. data/core/services/webdav/src/core.rs +116 -59
  531. data/core/services/webdav/src/deleter.rs +4 -1
  532. data/core/services/webdav/src/lister.rs +4 -1
  533. data/core/services/webdav/src/reader.rs +6 -2
  534. data/core/services/webdav/src/writer.rs +17 -7
  535. data/core/services/webhdfs/Cargo.toml +2 -2
  536. data/core/services/webhdfs/src/backend.rs +24 -11
  537. data/core/services/webhdfs/src/core.rs +99 -98
  538. data/core/services/webhdfs/src/deleter.rs +5 -2
  539. data/core/services/webhdfs/src/lister.rs +21 -9
  540. data/core/services/webhdfs/src/reader.rs +5 -2
  541. data/core/services/webhdfs/src/writer.rs +49 -14
  542. data/core/services/yandex-disk/Cargo.toml +1 -1
  543. data/core/services/yandex-disk/src/backend.rs +28 -6
  544. data/core/services/yandex-disk/src/core.rs +97 -79
  545. data/core/services/yandex-disk/src/deleter.rs +4 -1
  546. data/core/services/yandex-disk/src/lister.rs +25 -9
  547. data/core/services/yandex-disk/src/reader.rs +5 -2
  548. data/core/services/yandex-disk/src/writer.rs +6 -3
  549. data/core/src/lib.rs +5 -0
  550. data/core/testkit/Cargo.toml +4 -4
  551. data/core/testkit/src/utils.rs +53 -8
  552. data/core/tests/behavior/async_compose.rs +297 -0
  553. data/core/tests/behavior/async_copy.rs +162 -1
  554. data/core/tests/behavior/async_delete.rs +364 -3
  555. data/core/tests/behavior/async_read.rs +86 -0
  556. data/core/tests/behavior/async_restore.rs +162 -0
  557. data/core/tests/behavior/async_stat.rs +90 -0
  558. data/core/tests/behavior/async_write.rs +330 -2
  559. data/core/tests/behavior/main.rs +4 -0
  560. data/core/upgrade.md +114 -1
  561. data/src/capability.rs +0 -1
  562. data/src/io.rs +0 -1
  563. data/src/lister.rs +0 -1
  564. data/src/metadata.rs +0 -1
  565. data/src/operator_info.rs +0 -1
  566. metadata +44 -2
@@ -19,11 +19,13 @@ use std::fmt::Debug;
19
19
 
20
20
  use base64::Engine;
21
21
  use base64::prelude::BASE64_STANDARD;
22
+ use bytes::Buf;
22
23
  use bytes::Bytes;
23
24
  use constants::X_MS_META_PREFIX;
24
25
  use http::HeaderValue;
25
26
  use http::Request;
26
27
  use http::Response;
28
+ use http::StatusCode;
27
29
  use http::header::CONTENT_LENGTH;
28
30
  use http::header::CONTENT_TYPE;
29
31
  use http::header::HeaderName;
@@ -31,6 +33,8 @@ use http::header::IF_MATCH;
31
33
  use http::header::IF_MODIFIED_SINCE;
32
34
  use http::header::IF_NONE_MATCH;
33
35
  use http::header::IF_UNMODIFIED_SINCE;
36
+ use opendal_service_azure_common::with_azure_error_response_context;
37
+ use quick_xml::de;
34
38
  use reqsign_azure_storage::Credential;
35
39
  use reqsign_core::{Context, Signer};
36
40
  use serde::Deserialize;
@@ -55,6 +59,7 @@ pub mod constants {
55
59
  pub const X_MS_COPY_SOURCE: &str = "x-ms-copy-source";
56
60
  pub const X_MS_COPY_SOURCE_RANGE: &str = "x-ms-source-range";
57
61
  pub const X_MS_BLOB_CACHE_CONTROL: &str = "x-ms-blob-cache-control";
62
+ pub const X_MS_BLOB_CONTENT_TYPE: &str = "x-ms-blob-content-type";
58
63
  pub const X_MS_BLOB_CONDITION_APPENDPOS: &str = "x-ms-blob-condition-appendpos";
59
64
  pub const X_MS_META_PREFIX: &str = "x-ms-meta-";
60
65
 
@@ -301,11 +306,14 @@ impl AzblobCore {
301
306
  if args.if_not_exists() {
302
307
  req = req.header(IF_NONE_MATCH, "*");
303
308
  }
304
-
305
309
  if let Some(v) = args.if_none_match() {
306
310
  req = req.header(IF_NONE_MATCH, v);
307
311
  }
308
312
 
313
+ if let Some(v) = args.if_match() {
314
+ req = req.header(IF_MATCH, v);
315
+ }
316
+
309
317
  if let Some(cache_control) = args.cache_control() {
310
318
  req = req.header(constants::X_MS_BLOB_CACHE_CONTROL, cache_control);
311
319
  }
@@ -376,6 +384,10 @@ impl AzblobCore {
376
384
  "AppendBlob",
377
385
  );
378
386
 
387
+ if args.if_not_exists() {
388
+ req = req.header(IF_NONE_MATCH, "*");
389
+ }
390
+
379
391
  if let Some(ty) = args.content_type() {
380
392
  req = req.header(CONTENT_TYPE, ty)
381
393
  }
@@ -586,6 +598,31 @@ impl AzblobCore {
586
598
  req = req.header(constants::X_MS_BLOB_CACHE_CONTROL, cache_control);
587
599
  }
588
600
 
601
+ // Put Block List is where Azure applies the blob's properties and metadata;
602
+ // the headers on the individual Put Block requests are ignored.
603
+ if let Some(ty) = args.content_type() {
604
+ req = req.header(constants::X_MS_BLOB_CONTENT_TYPE, ty);
605
+ }
606
+ if let Some(user_metadata) = args.user_metadata() {
607
+ for (key, value) in user_metadata {
608
+ req = req.header(format!("{X_MS_META_PREFIX}{key}"), value);
609
+ }
610
+ }
611
+
612
+ // Put Block List is the request that actually commits a blocked write, so the
613
+ // write's preconditions have to be evaluated here rather than on Put Block.
614
+ if args.if_not_exists() {
615
+ req = req.header(IF_NONE_MATCH, "*");
616
+ }
617
+
618
+ if let Some(v) = args.if_none_match() {
619
+ req = req.header(IF_NONE_MATCH, v);
620
+ }
621
+
622
+ if let Some(v) = args.if_match() {
623
+ req = req.header(IF_MATCH, v);
624
+ }
625
+
589
626
  let content = quick_xml::se::to_string(&PutBlockListRequest {
590
627
  latest: block_ids
591
628
  .into_iter()
@@ -633,6 +670,12 @@ impl AzblobCore {
633
670
  if args.if_not_exists() {
634
671
  req = req.header(IF_NONE_MATCH, "*");
635
672
  }
673
+ if let Some(if_match) = args.if_match() {
674
+ req = req.header(IF_MATCH, if_match);
675
+ }
676
+ if let Some(if_none_match) = args.if_none_match() {
677
+ req = req.header(IF_NONE_MATCH, if_none_match);
678
+ }
636
679
 
637
680
  let content = quick_xml::se::to_string(&PutBlockListRequest {
638
681
  latest: block_ids
@@ -707,9 +750,16 @@ impl AzblobCore {
707
750
  self.send(ctx, req).await
708
751
  }
709
752
 
710
- fn azblob_delete_blob_request(&self, path: &str) -> Result<Request<Buffer>> {
711
- Request::delete(self.build_path_url(path))
712
- .header(CONTENT_LENGTH, 0)
753
+ fn azblob_delete_blob_request(&self, path: &str, args: &OpDelete) -> Result<Request<Buffer>> {
754
+ let mut req = Request::delete(self.build_path_url(path));
755
+ if let Some(if_match) = args.if_match() {
756
+ req = req.header(IF_MATCH, if_match);
757
+ }
758
+ if let Some(if_none_match) = args.if_none_match() {
759
+ req = req.header(IF_NONE_MATCH, if_none_match);
760
+ }
761
+
762
+ req.header(CONTENT_LENGTH, 0)
713
763
  .extension(Operation::Delete)
714
764
  .extension(ServiceOperation("DeleteBlob"))
715
765
  .body(Buffer::new())
@@ -720,8 +770,9 @@ impl AzblobCore {
720
770
  &self,
721
771
  ctx: &OperationContext,
722
772
  path: &str,
773
+ args: &OpDelete,
723
774
  ) -> Result<Response<Buffer>> {
724
- let req = self.azblob_delete_blob_request(path)?;
775
+ let req = self.azblob_delete_blob_request(path, args)?;
725
776
  let req = self.sign(ctx, req).await?;
726
777
  self.send(ctx, req).await
727
778
  }
@@ -749,6 +800,12 @@ impl AzblobCore {
749
800
  if args.if_not_exists() {
750
801
  req = req.header(IF_NONE_MATCH, "*");
751
802
  }
803
+ if let Some(if_match) = args.if_match() {
804
+ req = req.header(IF_MATCH, if_match);
805
+ }
806
+ if let Some(if_none_match) = args.if_none_match() {
807
+ req = req.header(IF_NONE_MATCH, if_none_match);
808
+ }
752
809
 
753
810
  let req = req
754
811
  .extension(Operation::Copy)
@@ -783,7 +840,7 @@ impl AzblobCore {
783
840
  url = url.push("delimiter", delimiter);
784
841
  }
785
842
  if !next_marker.is_empty() {
786
- url = url.push("marker", next_marker);
843
+ url = url.push("marker", &percent_encode_path(next_marker));
787
844
  }
788
845
 
789
846
  let req = Request::get(url.finish())
@@ -799,7 +856,7 @@ impl AzblobCore {
799
856
  pub async fn azblob_batch_delete(
800
857
  &self,
801
858
  ctx: &OperationContext,
802
- paths: &[String],
859
+ batch: &[(String, OpDelete)],
803
860
  ) -> Result<Response<Buffer>> {
804
861
  let url = format!(
805
862
  "{}/{}?restype=container&comp=batch",
@@ -808,8 +865,8 @@ impl AzblobCore {
808
865
 
809
866
  let mut multipart = Multipart::new();
810
867
 
811
- for (idx, path) in paths.iter().enumerate() {
812
- let req = self.azblob_delete_blob_request(path)?;
868
+ for (idx, (path, args)) in batch.iter().enumerate() {
869
+ let req = self.azblob_delete_blob_request(path, args)?;
813
870
  let req = self.batch_sign(ctx, req).await?;
814
871
 
815
872
  multipart = multipart.part(
@@ -882,6 +939,29 @@ mod tests {
882
939
  use quick_xml::de;
883
940
 
884
941
  use super::*;
942
+ use std::collections::HashMap;
943
+
944
+ use reqsign_azure_storage::RequestSigner;
945
+ use reqsign_azure_storage::StaticCredentialProvider;
946
+
947
+ fn test_core() -> AzblobCore {
948
+ AzblobCore {
949
+ info: ServiceInfo::new("azblob", "/", "c"),
950
+ capability: Capability::default(),
951
+ container: "c".to_string(),
952
+ root: "/".to_string(),
953
+ endpoint: "https://acc.blob.core.windows.net".to_string(),
954
+ encryption_key: None,
955
+ encryption_key_sha256: None,
956
+ encryption_algorithm: None,
957
+ skip_signature: true,
958
+ signer: Signer::new(
959
+ Context::new(),
960
+ StaticCredentialProvider::new_shared_key("acc", "a2V5"),
961
+ RequestSigner::new(),
962
+ ),
963
+ }
964
+ }
885
965
 
886
966
  #[test]
887
967
  fn test_parse_xml() {
@@ -1063,6 +1143,69 @@ mod tests {
1063
1143
  }
1064
1144
 
1065
1145
  /// This example is from https://learn.microsoft.com/en-us/rest/api/storageservices/put-block-list?tabs=microsoft-entra-id
1146
+ /// Put Block List is the commit point of a blocked write, and the only request
1147
+ /// in that sequence where Azure applies blob properties and metadata. azblob
1148
+ /// declares `write_with_content_type` and `write_with_user_metadata`, so both
1149
+ /// have to be carried here as well as on the one-shot Put Blob path.
1150
+ #[test]
1151
+ fn test_put_block_list_carries_content_type_and_user_metadata() {
1152
+ let core = test_core();
1153
+
1154
+ let mut meta = HashMap::new();
1155
+ meta.insert("k".to_string(), "v".to_string());
1156
+ let (args, _) = OpWrite::from_options(
1157
+ &Capability::default(),
1158
+ options::WriteOptions {
1159
+ content_type: Some("application/json".to_owned()),
1160
+ user_metadata: Some(meta),
1161
+ ..Default::default()
1162
+ },
1163
+ )
1164
+ .unwrap();
1165
+
1166
+ let req = core
1167
+ .azblob_complete_put_block_list_request("a.txt", vec![Uuid::nil()], &args)
1168
+ .expect("must build");
1169
+
1170
+ assert_eq!(
1171
+ req.headers()
1172
+ .get(constants::X_MS_BLOB_CONTENT_TYPE)
1173
+ .map(|v| v.to_str().unwrap()),
1174
+ Some("application/json")
1175
+ );
1176
+ assert_eq!(
1177
+ req.headers()
1178
+ .get("x-ms-meta-k")
1179
+ .map(|v| v.to_str().unwrap()),
1180
+ Some("v")
1181
+ );
1182
+ }
1183
+
1184
+ #[test]
1185
+ fn init_appendable_blob_carries_if_not_exists() {
1186
+ let core = test_core();
1187
+ let (args, _) = OpWrite::from_options(
1188
+ &Capability {
1189
+ write_with_if_not_exists: true,
1190
+ ..Default::default()
1191
+ },
1192
+ options::WriteOptions {
1193
+ if_not_exists: true,
1194
+ ..Default::default()
1195
+ },
1196
+ )
1197
+ .expect("options must lower");
1198
+
1199
+ let req = core
1200
+ .azblob_init_appendable_blob_request("a.txt", &args)
1201
+ .expect("request must build");
1202
+
1203
+ assert_eq!(
1204
+ req.headers().get(IF_NONE_MATCH),
1205
+ Some(&HeaderValue::from_static("*"))
1206
+ );
1207
+ }
1208
+
1066
1209
  #[test]
1067
1210
  fn test_serialize_put_block_list_request() {
1068
1211
  let req = PutBlockListRequest {
@@ -1101,154 +1244,248 @@ mod tests {
1101
1244
  }
1102
1245
  }
1103
1246
 
1104
- mod error {
1105
- use std::fmt::Debug;
1247
+ /// AzblobError is the error returned by azure blob service.
1248
+ #[derive(Default, Deserialize)]
1249
+ #[serde(default, rename_all = "PascalCase")]
1250
+ struct AzblobError {
1251
+ code: String,
1252
+ message: String,
1253
+ query_parameter_name: String,
1254
+ query_parameter_value: String,
1255
+ reason: String,
1256
+ }
1106
1257
 
1107
- use bytes::Buf;
1108
- use http::Response;
1109
- use http::StatusCode;
1110
- use opendal_core::*;
1111
- use opendal_service_azure_common::with_azure_error_response_context;
1112
- use quick_xml::de;
1113
- use serde::Deserialize;
1114
-
1115
- /// AzblobError is the error returned by azure blob service.
1116
- #[derive(Default, Deserialize)]
1117
- #[serde(default, rename_all = "PascalCase")]
1118
- struct AzblobError {
1119
- code: String,
1120
- message: String,
1121
- query_parameter_name: String,
1122
- query_parameter_value: String,
1123
- reason: String,
1124
- }
1258
+ impl Debug for AzblobError {
1259
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1260
+ let mut de = f.debug_struct("AzblobError");
1261
+ de.field("code", &self.code);
1262
+ // replace `\n` to ` ` for better reading.
1263
+ de.field("message", &self.message.replace('\n', " "));
1125
1264
 
1126
- impl Debug for AzblobError {
1127
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1128
- let mut de = f.debug_struct("AzblobError");
1129
- de.field("code", &self.code);
1130
- // replace `\n` to ` ` for better reading.
1131
- de.field("message", &self.message.replace('\n', " "));
1265
+ if !self.query_parameter_name.is_empty() {
1266
+ de.field("query_parameter_name", &self.query_parameter_name);
1267
+ }
1268
+ if !self.query_parameter_value.is_empty() {
1269
+ de.field("query_parameter_value", &self.query_parameter_value);
1270
+ }
1271
+ if !self.reason.is_empty() {
1272
+ de.field("reason", &self.reason);
1273
+ }
1132
1274
 
1133
- if !self.query_parameter_name.is_empty() {
1134
- de.field("query_parameter_name", &self.query_parameter_name);
1135
- }
1136
- if !self.query_parameter_value.is_empty() {
1137
- de.field("query_parameter_value", &self.query_parameter_value);
1138
- }
1139
- if !self.reason.is_empty() {
1140
- de.field("reason", &self.reason);
1141
- }
1275
+ de.finish()
1276
+ }
1277
+ }
1142
1278
 
1143
- de.finish()
1279
+ #[derive(Clone, Copy, Debug)]
1280
+ pub struct ErrorContext {
1281
+ service_operation: ServiceOperation,
1282
+ caller_condition: bool,
1283
+ if_not_exists: bool,
1284
+ is_append_blob_initialization: bool,
1285
+ }
1286
+
1287
+ impl ErrorContext {
1288
+ pub const fn new(service_operation: ServiceOperation) -> Self {
1289
+ Self {
1290
+ service_operation,
1291
+ caller_condition: false,
1292
+ if_not_exists: false,
1293
+ is_append_blob_initialization: false,
1144
1294
  }
1145
1295
  }
1146
1296
 
1147
- /// Parse error response into Error.
1148
- pub(crate) fn parse_error(resp: Response<Buffer>) -> Error {
1149
- let (parts, body) = resp.into_parts();
1150
- let bs = body.to_bytes();
1297
+ pub const fn with_caller_condition(mut self, caller_condition: bool) -> Self {
1298
+ self.caller_condition = caller_condition;
1299
+ self
1300
+ }
1151
1301
 
1152
- let (kind, retryable) = match parts.status {
1153
- StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
1154
- StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
1155
- StatusCode::PRECONDITION_FAILED | StatusCode::NOT_MODIFIED | StatusCode::CONFLICT => {
1156
- (ErrorKind::ConditionNotMatch, false)
1157
- }
1158
- StatusCode::INTERNAL_SERVER_ERROR
1159
- | StatusCode::BAD_GATEWAY
1160
- | StatusCode::SERVICE_UNAVAILABLE
1161
- | StatusCode::GATEWAY_TIMEOUT => (ErrorKind::Unexpected, true),
1162
- _ => (ErrorKind::Unexpected, false),
1163
- };
1302
+ pub const fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
1303
+ self.caller_condition = self.caller_condition || if_not_exists;
1304
+ self.if_not_exists = if_not_exists;
1305
+ self
1306
+ }
1164
1307
 
1165
- let bs_content = bs.chunk();
1166
- let mut message = match de::from_reader::<_, AzblobError>(bs_content.reader()) {
1167
- Ok(azblob_err) => format!("{azblob_err:?}"),
1168
- Err(_) => String::from_utf8_lossy(&bs).into_owned(),
1169
- };
1308
+ pub const fn with_append_blob_initialization(
1309
+ mut self,
1310
+ is_append_blob_initialization: bool,
1311
+ ) -> Self {
1312
+ self.is_append_blob_initialization = is_append_blob_initialization;
1313
+ self
1314
+ }
1315
+ }
1170
1316
 
1171
- // If there is no body here, fill with error code.
1172
- if message.is_empty()
1173
- && let Some(code) = parts
1174
- .headers
1175
- .get("x-ms-error-code")
1176
- .and_then(|v| v.to_str().ok())
1317
+ /// Parse error response into Error.
1318
+ pub fn parse_error(ctx: ErrorContext, resp: Response<Buffer>) -> Error {
1319
+ let (parts, body) = resp.into_parts();
1320
+ let bs = body.to_bytes();
1321
+
1322
+ let bs_content = bs.chunk();
1323
+ let mut azblob_error = de::from_reader::<_, AzblobError>(bs_content.reader()).ok();
1324
+
1325
+ if azblob_error.as_ref().is_none_or(|err| err.code.is_empty())
1326
+ && let Some(code) = parts
1327
+ .headers
1328
+ .get("x-ms-error-code")
1329
+ .and_then(|v| v.to_str().ok())
1330
+ {
1331
+ azblob_error.get_or_insert_with(AzblobError::default).code = code.to_string();
1332
+ }
1333
+
1334
+ let (mut kind, mut retryable) = match parts.status {
1335
+ StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
1336
+ StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
1337
+ StatusCode::NOT_MODIFIED | StatusCode::PRECONDITION_FAILED if ctx.caller_condition => {
1338
+ (ErrorKind::ConditionNotMatch, false)
1339
+ }
1340
+ StatusCode::TOO_MANY_REQUESTS => (ErrorKind::RateLimited, true),
1341
+ StatusCode::INTERNAL_SERVER_ERROR
1342
+ | StatusCode::BAD_GATEWAY
1343
+ | StatusCode::SERVICE_UNAVAILABLE
1344
+ | StatusCode::GATEWAY_TIMEOUT => (ErrorKind::Unexpected, true),
1345
+ _ => (ErrorKind::Unexpected, false),
1346
+ };
1347
+
1348
+ if let Some(azblob_error) = &azblob_error
1349
+ && !azblob_error.code.is_empty()
1350
+ {
1351
+ if let Some(classification) = parse_azblob_error_code(ctx, &azblob_error.code, parts.status)
1177
1352
  {
1178
- message = format!(
1179
- "{:?}",
1180
- AzblobError {
1181
- code: code.to_string(),
1182
- ..Default::default()
1183
- }
1184
- );
1353
+ (kind, retryable) = classification;
1354
+ } else if matches!(
1355
+ parts.status,
1356
+ StatusCode::CONFLICT | StatusCode::PRECONDITION_FAILED
1357
+ ) {
1358
+ (kind, retryable) = (ErrorKind::Unexpected, false);
1185
1359
  }
1360
+ }
1186
1361
 
1187
- let mut err = Error::new(kind, &message);
1362
+ let message = azblob_error
1363
+ .map(|err| format!("{err:?}"))
1364
+ .unwrap_or_else(|| String::from_utf8_lossy(&bs).into_owned());
1188
1365
 
1189
- err = with_azure_error_response_context(err, parts);
1366
+ let mut err =
1367
+ Error::new(kind, &message).with_context("service_operation", ctx.service_operation.0);
1190
1368
 
1191
- if retryable {
1192
- err = err.set_temporary();
1193
- }
1369
+ err = with_azure_error_response_context(err, parts);
1194
1370
 
1195
- err
1371
+ if retryable {
1372
+ err = err.set_temporary();
1196
1373
  }
1197
1374
 
1198
- #[cfg(test)]
1199
- mod tests {
1200
- use super::*;
1201
-
1202
- #[test]
1203
- fn test_parse_error() {
1204
- let bs = bytes::Bytes::from(
1205
- r#"
1206
- <?xml version="1.0" encoding="utf-8"?>
1207
- <Error>
1208
- <Code>string-value</Code>
1209
- <Message>string-value</Message>
1210
- </Error>
1211
- "#,
1212
- );
1213
-
1214
- let out: AzblobError = de::from_reader(bs.reader()).expect("must success");
1215
- println!("{out:?}");
1375
+ err
1376
+ }
1216
1377
 
1217
- assert_eq!(out.code, "string-value");
1218
- assert_eq!(out.message, "string-value");
1378
+ /// Classify documented Blob Storage state errors by native code and status.
1379
+ ///
1380
+ /// Reference: <https://learn.microsoft.com/rest/api/storageservices/blob-service-error-codes>
1381
+ fn parse_azblob_error_code(
1382
+ ctx: ErrorContext,
1383
+ code: &str,
1384
+ status: StatusCode,
1385
+ ) -> Option<(ErrorKind, bool)> {
1386
+ match code {
1387
+ "ConditionNotMet" | "SourceConditionNotMet" | "TargetConditionNotMet"
1388
+ if ctx.caller_condition
1389
+ && matches!(
1390
+ status,
1391
+ StatusCode::NOT_MODIFIED | StatusCode::PRECONDITION_FAILED
1392
+ ) =>
1393
+ {
1394
+ Some((ErrorKind::ConditionNotMatch, false))
1395
+ }
1396
+ "BlobAlreadyExists" | "ContainerAlreadyExists" | "ResourceAlreadyExists" => {
1397
+ let classification = if ctx.if_not_exists {
1398
+ (ErrorKind::ConditionNotMatch, false)
1399
+ } else if ctx.is_append_blob_initialization {
1400
+ (ErrorKind::Conflict, true)
1401
+ } else {
1402
+ (ErrorKind::AlreadyExists, false)
1403
+ };
1404
+ Some(classification)
1405
+ }
1406
+ "DirectorySasNotSupportedVersion"
1407
+ | "FeatureVersionMismatch"
1408
+ | "PreviousSnapshotOperationNotSupported" => Some((ErrorKind::Unsupported, false)),
1409
+ "SnapshotOperationRateExceeded" => Some((ErrorKind::RateLimited, true)),
1410
+ "AppendPositionConditionNotMet"
1411
+ | "BlobArchived"
1412
+ | "BlobBeingRehydrated"
1413
+ | "BlobImmutableDueToLegalHold"
1414
+ | "BlobImmutableDueToPolicy"
1415
+ | "BlobNotArchived"
1416
+ | "BlobOperationNotSupported"
1417
+ | "BlobOverwritten"
1418
+ | "BlobTierInadequateForContentLength"
1419
+ | "BlockCountExceedsLimit"
1420
+ | "CannotChangeToLowerTier"
1421
+ | "ContainerBeingDeleted"
1422
+ | "ContainerDisabled"
1423
+ | "ContainerHasLegalHold"
1424
+ | "ContainerImmutabilityPolicyLocked"
1425
+ | "ContentLengthLargerThanTierLimit"
1426
+ | "CopyIdMismatch"
1427
+ | "IncrementalCopyBlobMismatch"
1428
+ | "IncrementalCopyOfEarlierSnapshotNotAllowed"
1429
+ | "IncrementalCopyOfEarlierVersionSnapshotNotAllowed"
1430
+ | "IncrementalCopySourceMustBeSnapshot"
1431
+ | "InvalidBlobType"
1432
+ | "InvalidSourceBlobType"
1433
+ | "InvalidSourceBlobUrl"
1434
+ | "LeaseAlreadyBroken"
1435
+ | "LeaseAlreadyPresent"
1436
+ | "LeaseIdMismatchWithBlobOperation"
1437
+ | "LeaseIdMismatchWithContainerOperation"
1438
+ | "LeaseIdMismatchWithLeaseOperation"
1439
+ | "LeaseIdMissing"
1440
+ | "LeaseIsBreakingAndCannotBeAcquired"
1441
+ | "LeaseIsBreakingAndCannotBeChanged"
1442
+ | "LeaseIsBrokenAndCannotBeRenewed"
1443
+ | "LeaseLost"
1444
+ | "LeaseNotPresentWithBlobOperation"
1445
+ | "LeaseNotPresentWithContainerOperation"
1446
+ | "LeaseNotPresentWithLeaseOperation"
1447
+ | "InfiniteLeaseDurationRequired"
1448
+ | "MaxBlobSizeConditionNotMet"
1449
+ | "NoPendingCopyOperation"
1450
+ | "OperationNotAllowedOnIncrementalCopyBlob"
1451
+ | "PendingCopyOperation"
1452
+ | "PreviousSnapshotNotFound"
1453
+ | "SequenceNumberConditionNotMet"
1454
+ | "SequenceNumberIncrementTooLarge"
1455
+ | "SnapshotCountExceeded"
1456
+ | "SnapshotsPresent"
1457
+ | "SystemInUse"
1458
+ | "ResourceTypeMismatch"
1459
+ if matches!(
1460
+ status,
1461
+ StatusCode::CONFLICT | StatusCode::PRECONDITION_FAILED
1462
+ ) =>
1463
+ {
1464
+ Some((ErrorKind::Conflict, false))
1219
1465
  }
1466
+ _ => None,
1467
+ }
1468
+ }
1220
1469
 
1221
- #[test]
1222
- fn test_parse_error_with_reason() {
1223
- let bs = bytes::Bytes::from(
1224
- r#"
1225
- <?xml version="1.0" encoding="utf-8"?>
1226
- <Error>
1227
- <Code>InvalidQueryParameterValue</Code>
1228
- <Message>Value for one of the query parameters specified in the request URI is invalid.</Message>
1229
- <QueryParameterName>popreceipt</QueryParameterName>
1230
- <QueryParameterValue>33537277-6a52-4a2b-b4eb-0f905051827b</QueryParameterValue>
1231
- <Reason>invalid receipt format</Reason>
1232
- </Error>
1233
- "#,
1234
- );
1470
+ #[cfg(test)]
1471
+ mod error_tests {
1472
+ use super::*;
1235
1473
 
1236
- let out: AzblobError = de::from_reader(bs.reader()).expect("must success");
1237
- println!("{out:?}");
1474
+ #[test]
1475
+ fn append_blob_initialization_preserves_condition_and_retryability() {
1476
+ let conditional = ErrorContext::new(ServiceOperation("PutBlob"))
1477
+ .with_if_not_exists(true)
1478
+ .with_append_blob_initialization(true);
1479
+ assert_eq!(
1480
+ parse_azblob_error_code(conditional, "BlobAlreadyExists", StatusCode::CONFLICT),
1481
+ Some((ErrorKind::ConditionNotMatch, false))
1482
+ );
1238
1483
 
1239
- assert_eq!(out.code, "InvalidQueryParameterValue");
1240
- assert_eq!(
1241
- out.message,
1242
- "Value for one of the query parameters specified in the request URI is invalid."
1243
- );
1244
- assert_eq!(out.query_parameter_name, "popreceipt");
1245
- assert_eq!(
1246
- out.query_parameter_value,
1247
- "33537277-6a52-4a2b-b4eb-0f905051827b"
1248
- );
1249
- assert_eq!(out.reason, "invalid receipt format");
1250
- }
1484
+ let raced =
1485
+ ErrorContext::new(ServiceOperation("PutBlob")).with_append_blob_initialization(true);
1486
+ assert_eq!(
1487
+ parse_azblob_error_code(raced, "BlobAlreadyExists", StatusCode::CONFLICT),
1488
+ Some((ErrorKind::Conflict, true))
1489
+ );
1251
1490
  }
1252
1491
  }
1253
-
1254
- pub(super) use error::*;