| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | use std::{collections::HashMap, path::PathBuf, pin::Pin}; |
| 7 | |
| 8 | use tokio::io::AsyncRead; |
| 9 | |
| 10 | use crate::domain::{ |
| 11 | BranchRow, CommitDetail, CommitEntry, CommitSummary, DomainError, Email, EntryCommit, GitRef, |
| 12 | GrepHit, ImportSource, ObjectId, OrgName, PasswordHash, RefName, RepoName, RepoPath, TagRow, |
| 13 | TagSummary, TreeEntry, |
| 14 | }; |
| 15 | |
| 16 | use super::blame::Blame; |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | pub trait PasswordHasher: Send + Sync { |
| 24 | |
| 25 | fn hash(&self, plaintext: &str) -> Result<PasswordHash, PasswordError>; |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | fn verify(&self, plaintext: &str, hash: &PasswordHash) -> Result<bool, PasswordError>; |
| 33 | } |
| 34 | |
| 35 | |
| 36 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 37 | pub struct PasswordError(String); |
| 38 | |
| 39 | impl PasswordError { |
| 40 | pub fn new(message: impl Into<String>) -> Self { |
| 41 | Self(message.into()) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl std::fmt::Display for PasswordError { |
| 46 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 47 | write!(f, "password hashing failed: {}", self.0) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | impl std::error::Error for PasswordError {} |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 59 | pub struct Mail { |
| 60 | pub to: Email, |
| 61 | pub subject: String, |
| 62 | pub body: String, |
| 63 | } |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | pub trait Mailer: Send + Sync { |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | fn configured(&self) -> bool; |
| 79 | |
| 80 | |
| 81 | fn send(&self, mail: &Mail) -> impl Future<Output = Result<(), MailError>> + Send; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 86 | pub struct MailError(String); |
| 87 | |
| 88 | impl MailError { |
| 89 | pub fn new(message: impl Into<String>) -> Self { |
| 90 | Self(message.into()) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | impl std::fmt::Display for MailError { |
| 95 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 96 | write!(f, "could not send mail: {}", self.0) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | impl std::error::Error for MailError {} |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | pub trait GitStorage: Send + Sync { |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | fn init_bare( |
| 122 | &self, |
| 123 | handle: &OrgName, |
| 124 | name: &RepoName, |
| 125 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | fn remove( |
| 133 | &self, |
| 134 | handle: &OrgName, |
| 135 | name: &RepoName, |
| 136 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | fn rename( |
| 149 | &self, |
| 150 | handle: &OrgName, |
| 151 | from: &RepoName, |
| 152 | to: &RepoName, |
| 153 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | fn set_default_branch( |
| 170 | &self, |
| 171 | handle: &OrgName, |
| 172 | name: &RepoName, |
| 173 | branch: &RefName, |
| 174 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | fn enable_reflogs(&self) -> impl Future<Output = Result<u64, GitStorageError>> + Send; |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | fn list_repo_dirs(&self) -> impl Future<Output = Result<Vec<RepoDir>, GitStorageError>> + Send; |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | fn quarantine( |
| 218 | &self, |
| 219 | dir: &RepoDir, |
| 220 | label: &str, |
| 221 | ) -> impl Future<Output = Result<PathBuf, GitStorageError>> + Send; |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | fn repo_path(&self, handle: &OrgName, name: &RepoName) -> PathBuf; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 236 | pub struct RepoDir { |
| 237 | |
| 238 | pub handle: String, |
| 239 | |
| 240 | pub name: String, |
| 241 | |
| 242 | pub path: PathBuf, |
| 243 | } |
| 244 | |
| 245 | |
| 246 | #[derive(Debug)] |
| 247 | pub enum GitStorageError { |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | AlreadyExists, |
| 254 | |
| 255 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 256 | } |
| 257 | |
| 258 | impl GitStorageError { |
| 259 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 260 | Self::Backend(error.into()) |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | impl std::fmt::Display for GitStorageError { |
| 265 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 266 | match self { |
| 267 | Self::AlreadyExists => f.write_str("a repository already exists at that path"), |
| 268 | Self::Backend(error) => write!(f, "git storage failure: {error}"), |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | impl std::error::Error for GitStorageError { |
| 274 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 275 | match self { |
| 276 | Self::AlreadyExists => None, |
| 277 | Self::Backend(error) => Some(&**error), |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | pub type ByteStream = Pin<Box<dyn AsyncRead + Send>>; |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 295 | pub enum GitMethod { |
| 296 | Get, |
| 297 | Post, |
| 298 | } |
| 299 | |
| 300 | impl GitMethod { |
| 301 | pub fn as_str(self) -> &'static str { |
| 302 | match self { |
| 303 | Self::Get => "GET", |
| 304 | Self::Post => "POST", |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | pub struct GitRequest { |
| 318 | pub method: GitMethod, |
| 319 | |
| 320 | pub path_info: String, |
| 321 | |
| 322 | pub query: String, |
| 323 | pub content_type: Option<String>, |
| 324 | |
| 325 | |
| 326 | |
| 327 | pub content_encoding: Option<String>, |
| 328 | pub content_length: Option<String>, |
| 329 | |
| 330 | |
| 331 | pub git_protocol: Option<String>, |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | pub allow_receive_pack: bool, |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | pub remote_user: Option<String>, |
| 349 | pub body: ByteStream, |
| 350 | } |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | pub struct GitResponse { |
| 358 | pub status: u16, |
| 359 | pub headers: Vec<(String, String)>, |
| 360 | pub body: ByteStream, |
| 361 | } |
| 362 | |
| 363 | |
| 364 | |
| 365 | impl std::fmt::Debug for GitRequest { |
| 366 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 367 | f.debug_struct("GitRequest") |
| 368 | .field("method", &self.method) |
| 369 | .field("path_info", &self.path_info) |
| 370 | .field("query", &self.query) |
| 371 | .field("content_type", &self.content_type) |
| 372 | .field("content_encoding", &self.content_encoding) |
| 373 | .field("content_length", &self.content_length) |
| 374 | .field("git_protocol", &self.git_protocol) |
| 375 | .field("allow_receive_pack", &self.allow_receive_pack) |
| 376 | .field("remote_user", &self.remote_user) |
| 377 | .finish_non_exhaustive() |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | impl std::fmt::Debug for GitResponse { |
| 382 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 383 | f.debug_struct("GitResponse") |
| 384 | .field("status", &self.status) |
| 385 | .field("headers", &self.headers) |
| 386 | .finish_non_exhaustive() |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | pub trait GitProtocolServer: Send + Sync { |
| 395 | fn serve( |
| 396 | &self, |
| 397 | request: GitRequest, |
| 398 | ) -> impl Future<Output = Result<GitResponse, GitProtocolError>> + Send; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | #[derive(Debug)] |
| 407 | pub struct GitProtocolError(Box<dyn std::error::Error + Send + Sync>); |
| 408 | |
| 409 | impl GitProtocolError { |
| 410 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 411 | Self(error.into()) |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | impl std::fmt::Display for GitProtocolError { |
| 416 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 417 | write!(f, "git protocol failure: {}", self.0) |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | impl std::error::Error for GitProtocolError { |
| 422 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 423 | Some(&*self.0) |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 434 | pub struct WebhookRequest { |
| 435 | pub url: String, |
| 436 | pub headers: Vec<(String, String)>, |
| 437 | pub body: Vec<u8>, |
| 438 | } |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 446 | pub struct WebhookOutcome { |
| 447 | |
| 448 | |
| 449 | pub status: Option<u16>, |
| 450 | |
| 451 | |
| 452 | pub body: String, |
| 453 | pub duration: std::time::Duration, |
| 454 | } |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | pub trait WebhookSender: Send + Sync { |
| 462 | fn send(&self, request: WebhookRequest) -> impl Future<Output = WebhookOutcome> + Send; |
| 463 | } |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | pub trait Clock: Send + Sync { |
| 477 | fn now(&self) -> std::time::SystemTime; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 486 | pub struct Blob { |
| 487 | pub id: ObjectId, |
| 488 | pub size: u64, |
| 489 | pub content: Option<Vec<u8>>, |
| 490 | } |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | pub trait GitQuery: Send + Sync { |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | fn default_branch( |
| 513 | &self, |
| 514 | handle: &OrgName, |
| 515 | name: &RepoName, |
| 516 | ) -> impl Future<Output = Result<Option<RefName>, GitQueryError>> + Send; |
| 517 | |
| 518 | |
| 519 | fn resolve( |
| 520 | &self, |
| 521 | handle: &OrgName, |
| 522 | name: &RepoName, |
| 523 | rev: &RefName, |
| 524 | ) -> impl Future<Output = Result<Option<ObjectId>, GitQueryError>> + Send; |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | fn list_tree( |
| 531 | &self, |
| 532 | handle: &OrgName, |
| 533 | name: &RepoName, |
| 534 | rev: &RefName, |
| 535 | path: &RepoPath, |
| 536 | ) -> impl Future<Output = Result<Option<Vec<TreeEntry>>, GitQueryError>> + Send; |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | fn last_commits( |
| 556 | &self, |
| 557 | handle: &OrgName, |
| 558 | name: &RepoName, |
| 559 | rev: &RefName, |
| 560 | path: &RepoPath, |
| 561 | entries: &[String], |
| 562 | ) -> impl Future<Output = Result<HashMap<String, EntryCommit>, GitQueryError>> + Send; |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | fn read_blob( |
| 568 | &self, |
| 569 | handle: &OrgName, |
| 570 | name: &RepoName, |
| 571 | rev: &RefName, |
| 572 | path: &RepoPath, |
| 573 | max_bytes: u64, |
| 574 | ) -> impl Future<Output = Result<Option<Blob>, GitQueryError>> + Send; |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | fn log( |
| 588 | &self, |
| 589 | handle: &OrgName, |
| 590 | name: &RepoName, |
| 591 | rev: &RefName, |
| 592 | offset: usize, |
| 593 | limit: usize, |
| 594 | ) -> impl Future<Output = Result<Vec<CommitSummary>, GitQueryError>> + Send; |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | fn log_entries( |
| 603 | &self, |
| 604 | handle: &OrgName, |
| 605 | name: &RepoName, |
| 606 | rev: &RefName, |
| 607 | limit: usize, |
| 608 | ) -> impl Future<Output = Result<Vec<CommitEntry>, GitQueryError>> + Send; |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | fn list_refs( |
| 625 | &self, |
| 626 | handle: &OrgName, |
| 627 | name: &RepoName, |
| 628 | ) -> impl Future<Output = Result<Vec<GitRef>, GitQueryError>> + Send; |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | fn count_commits( |
| 637 | &self, |
| 638 | handle: &OrgName, |
| 639 | name: &RepoName, |
| 640 | rev: &RefName, |
| 641 | ) -> impl Future<Output = Result<u64, GitQueryError>> + Send; |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | fn latest_tag( |
| 653 | &self, |
| 654 | handle: &OrgName, |
| 655 | name: &RepoName, |
| 656 | ) -> impl Future<Output = Result<Option<TagSummary>, GitQueryError>> + Send; |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | fn commit( |
| 669 | &self, |
| 670 | handle: &OrgName, |
| 671 | name: &RepoName, |
| 672 | rev: &RefName, |
| 673 | ) -> impl Future<Output = Result<Option<CommitDetail>, GitQueryError>> + Send; |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | fn diff( |
| 693 | &self, |
| 694 | handle: &OrgName, |
| 695 | name: &RepoName, |
| 696 | base: Option<&ObjectId>, |
| 697 | head: &ObjectId, |
| 698 | max_bytes: u64, |
| 699 | ) -> impl Future<Output = Result<RawDiff, GitQueryError>> + Send; |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | fn merge_base( |
| 708 | &self, |
| 709 | handle: &OrgName, |
| 710 | name: &RepoName, |
| 711 | base: &ObjectId, |
| 712 | head: &ObjectId, |
| 713 | ) -> impl Future<Output = Result<Option<ObjectId>, GitQueryError>> + Send; |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | fn log_between( |
| 724 | &self, |
| 725 | handle: &OrgName, |
| 726 | name: &RepoName, |
| 727 | base: Option<&ObjectId>, |
| 728 | head: &ObjectId, |
| 729 | offset: usize, |
| 730 | limit: usize, |
| 731 | ) -> impl Future<Output = Result<Vec<CommitSummary>, GitQueryError>> + Send; |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | fn count_between( |
| 739 | &self, |
| 740 | handle: &OrgName, |
| 741 | name: &RepoName, |
| 742 | base: Option<&ObjectId>, |
| 743 | head: &ObjectId, |
| 744 | ) -> impl Future<Output = Result<usize, GitQueryError>> + Send; |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | fn branches( |
| 763 | &self, |
| 764 | handle: &OrgName, |
| 765 | name: &RepoName, |
| 766 | ) -> impl Future<Output = Result<Vec<BranchRow>, GitQueryError>> + Send; |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | fn tags( |
| 774 | &self, |
| 775 | handle: &OrgName, |
| 776 | name: &RepoName, |
| 777 | ) -> impl Future<Output = Result<Vec<TagRow>, GitQueryError>> + Send; |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | fn grep( |
| 792 | &self, |
| 793 | handle: &OrgName, |
| 794 | name: &RepoName, |
| 795 | commit: &ObjectId, |
| 796 | query: &str, |
| 797 | limit: usize, |
| 798 | ) -> impl Future<Output = Result<Vec<GrepHit>, GitQueryError>> + Send; |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | fn blame( |
| 815 | &self, |
| 816 | handle: &OrgName, |
| 817 | name: &RepoName, |
| 818 | rev: &RefName, |
| 819 | path: &RepoPath, |
| 820 | ) -> impl Future<Output = Result<Option<Blame>, GitQueryError>> + Send; |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | fn ref_snapshot( |
| 842 | &self, |
| 843 | handle: &OrgName, |
| 844 | name: &RepoName, |
| 845 | ) -> impl Future<Output = Result<Vec<(RefName, ObjectId)>, GitQueryError>> + Send; |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | #[allow(clippy::too_many_arguments)] |
| 866 | fn log_at_path( |
| 867 | &self, |
| 868 | handle: &OrgName, |
| 869 | name: &RepoName, |
| 870 | rev: &RefName, |
| 871 | path: &RepoPath, |
| 872 | follow: bool, |
| 873 | offset: usize, |
| 874 | limit: usize, |
| 875 | ) -> impl Future<Output = Result<Vec<CommitSummary>, GitQueryError>> + Send; |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | |
| 891 | fn count_commits_at_path( |
| 892 | &self, |
| 893 | handle: &OrgName, |
| 894 | name: &RepoName, |
| 895 | rev: &RefName, |
| 896 | path: &RepoPath, |
| 897 | follow: bool, |
| 898 | ) -> impl Future<Output = Result<CommitCount, GitQueryError>> + Send; |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | fn symlink_targets( |
| 911 | &self, |
| 912 | handle: &OrgName, |
| 913 | name: &RepoName, |
| 914 | ids: &[ObjectId], |
| 915 | ) -> impl Future<Output = Result<HashMap<ObjectId, String>, GitQueryError>> + Send; |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | fn merge_preview( |
| 940 | &self, |
| 941 | handle: &OrgName, |
| 942 | name: &RepoName, |
| 943 | target: &ObjectId, |
| 944 | source: &ObjectId, |
| 945 | ) -> impl Future<Output = Result<MergePreview, GitQueryError>> + Send; |
| 946 | } |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 956 | pub struct CommitCount { |
| 957 | |
| 958 | pub total: u64, |
| 959 | |
| 960 | pub capped: bool, |
| 961 | } |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 968 | pub enum MergePreview { |
| 969 | |
| 970 | Clean { tree: ObjectId }, |
| 971 | |
| 972 | |
| 973 | |
| 974 | Conflicted { paths: Vec<String> }, |
| 975 | } |
| 976 | |
| 977 | impl MergePreview { |
| 978 | pub fn is_clean(&self) -> bool { |
| 979 | matches!(self, Self::Clean { .. }) |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 993 | pub struct RawDiff { |
| 994 | |
| 995 | |
| 996 | pub numstat: Vec<u8>, |
| 997 | |
| 998 | |
| 999 | pub patch: Vec<u8>, |
| 1000 | |
| 1001 | pub truncated: bool, |
| 1002 | } |
| 1003 | |
| 1004 | #[derive(Debug)] |
| 1005 | pub struct GitQueryError { |
| 1006 | kind: GitQueryErrorKind, |
| 1007 | source: Box<dyn std::error::Error + Send + Sync>, |
| 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 1018 | pub enum GitQueryErrorKind { |
| 1019 | Failed, |
| 1020 | TimedOut, |
| 1021 | TooLarge, |
| 1022 | } |
| 1023 | |
| 1024 | impl GitQueryError { |
| 1025 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 1026 | Self { |
| 1027 | kind: GitQueryErrorKind::Failed, |
| 1028 | source: error.into(), |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | |
| 1033 | pub fn timed_out(limit: std::time::Duration) -> Self { |
| 1034 | Self { |
| 1035 | kind: GitQueryErrorKind::TimedOut, |
| 1036 | source: format!("git did not finish within {limit:?}").into(), |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | pub fn too_large(max_bytes: u64) -> Self { |
| 1048 | Self { |
| 1049 | kind: GitQueryErrorKind::TooLarge, |
| 1050 | source: format!("git wrote more than {max_bytes} bytes").into(), |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | pub fn kind(&self) -> GitQueryErrorKind { |
| 1055 | self.kind |
| 1056 | } |
| 1057 | |
| 1058 | pub fn is_timeout(&self) -> bool { |
| 1059 | self.kind == GitQueryErrorKind::TimedOut |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | impl std::fmt::Display for GitQueryError { |
| 1064 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1065 | match self.kind { |
| 1066 | GitQueryErrorKind::Failed => { |
| 1067 | write!(f, "could not read the repository: {}", self.source) |
| 1068 | } |
| 1069 | GitQueryErrorKind::TimedOut => { |
| 1070 | write!(f, "reading the repository took too long: {}", self.source) |
| 1071 | } |
| 1072 | GitQueryErrorKind::TooLarge => { |
| 1073 | write!(f, "there is too much to show: {}", self.source) |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | impl std::error::Error for GitQueryError { |
| 1080 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 1081 | Some(&*self.source) |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 1091 | pub enum ArchiveFormat { |
| 1092 | TarGz, |
| 1093 | Zip, |
| 1094 | } |
| 1095 | |
| 1096 | impl ArchiveFormat { |
| 1097 | |
| 1098 | |
| 1099 | pub fn as_str(self) -> &'static str { |
| 1100 | match self { |
| 1101 | Self::TarGz => "tar.gz", |
| 1102 | Self::Zip => "zip", |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | pub fn content_type(self) -> &'static str { |
| 1112 | match self { |
| 1113 | Self::TarGz => "application/gzip", |
| 1114 | Self::Zip => "application/zip", |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | impl std::str::FromStr for ArchiveFormat { |
| 1122 | type Err = DomainError; |
| 1123 | |
| 1124 | fn from_str(value: &str) -> std::result::Result<Self, Self::Err> { |
| 1125 | match value { |
| 1126 | "tar.gz" => Ok(Self::TarGz), |
| 1127 | "zip" => Ok(Self::Zip), |
| 1128 | other => Err(DomainError::validation( |
| 1129 | "format", |
| 1130 | format!("unknown archive format {other:?}"), |
| 1131 | )), |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 1143 | pub struct ArchiveRequest { |
| 1144 | pub handle: OrgName, |
| 1145 | pub name: RepoName, |
| 1146 | pub format: ArchiveFormat, |
| 1147 | pub commit: ObjectId, |
| 1148 | |
| 1149 | |
| 1150 | pub prefix: String, |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | pub trait GitArchive: Send + Sync { |
| 1160 | fn archive( |
| 1161 | &self, |
| 1162 | request: ArchiveRequest, |
| 1163 | ) -> impl Future<Output = Result<ByteStream, GitArchiveError>> + Send; |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | #[derive(Debug)] |
| 1171 | pub struct GitArchiveError(Box<dyn std::error::Error + Send + Sync>); |
| 1172 | |
| 1173 | impl GitArchiveError { |
| 1174 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 1175 | Self(error.into()) |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | impl std::fmt::Display for GitArchiveError { |
| 1180 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1181 | write!(f, "could not archive the repository: {}", self.0) |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | impl std::error::Error for GitArchiveError { |
| 1186 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 1187 | Some(&*self.0) |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | pub trait GitImport: Send + Sync { |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | fn mirror( |
| 1210 | &self, |
| 1211 | handle: &OrgName, |
| 1212 | name: &RepoName, |
| 1213 | source: &ImportSource, |
| 1214 | ) -> impl Future<Output = Result<(), GitImportError>> + Send; |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | #[derive(Debug)] |
| 1224 | pub struct GitImportError(String); |
| 1225 | |
| 1226 | impl GitImportError { |
| 1227 | pub fn new(message: impl Into<String>) -> Self { |
| 1228 | Self(message.into()) |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | pub fn message(&self) -> &str { |
| 1234 | &self.0 |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | impl std::fmt::Display for GitImportError { |
| 1239 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1240 | write!(f, "could not import the repository: {}", self.0) |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | impl std::error::Error for GitImportError {} |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | pub trait GitMerge: Send + Sync { |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | fn commit_tree( |
| 1268 | &self, |
| 1269 | handle: &OrgName, |
| 1270 | name: &RepoName, |
| 1271 | request: &CommitTreeRequest, |
| 1272 | ) -> impl Future<Output = Result<ObjectId, GitMergeError>> + Send; |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | fn update_ref( |
| 1282 | &self, |
| 1283 | handle: &OrgName, |
| 1284 | name: &RepoName, |
| 1285 | branch: &RefName, |
| 1286 | new: &ObjectId, |
| 1287 | old: &ObjectId, |
| 1288 | ) -> impl Future<Output = Result<(), GitMergeError>> + Send; |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | fn delete_ref( |
| 1296 | &self, |
| 1297 | handle: &OrgName, |
| 1298 | name: &RepoName, |
| 1299 | branch: &RefName, |
| 1300 | old: &ObjectId, |
| 1301 | ) -> impl Future<Output = Result<(), GitMergeError>> + Send; |
| 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 1310 | pub struct CommitTreeRequest { |
| 1311 | |
| 1312 | |
| 1313 | pub tree: ObjectId, |
| 1314 | |
| 1315 | |
| 1316 | pub parents: Vec<ObjectId>, |
| 1317 | |
| 1318 | pub message: String, |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | pub author_name: String, |
| 1323 | pub author_email: String, |
| 1324 | |
| 1325 | |
| 1326 | pub now: std::time::SystemTime, |
| 1327 | } |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | #[derive(Debug)] |
| 1335 | pub enum GitMergeError { |
| 1336 | |
| 1337 | Stale, |
| 1338 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 1339 | } |
| 1340 | |
| 1341 | impl GitMergeError { |
| 1342 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 1343 | Self::Backend(error.into()) |
| 1344 | } |
| 1345 | |
| 1346 | pub fn is_stale(&self) -> bool { |
| 1347 | matches!(self, Self::Stale) |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | impl std::fmt::Display for GitMergeError { |
| 1352 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1353 | match self { |
| 1354 | Self::Stale => f.write_str( |
| 1355 | "the branch moved while the merge was being prepared, so nothing was changed", |
| 1356 | ), |
| 1357 | Self::Backend(error) => write!(f, "the merge could not be written: {error}"), |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | impl std::error::Error for GitMergeError { |
| 1363 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 1364 | match self { |
| 1365 | Self::Stale => None, |
| 1366 | Self::Backend(error) => Some(&**error), |
| 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | pub trait DiskUsage: Send + Sync { |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | fn measure(&self) -> impl Future<Output = Result<DiskReport, DiskError>> + Send; |
| 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 1395 | pub struct DiskReport { |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | pub data_dir_bytes: u64, |
| 1402 | |
| 1403 | pub filesystem_total_bytes: u64, |
| 1404 | |
| 1405 | |
| 1406 | pub filesystem_free_bytes: u64, |
| 1407 | } |
| 1408 | |
| 1409 | |
| 1410 | #[derive(Debug)] |
| 1411 | pub struct DiskError(Box<dyn std::error::Error + Send + Sync>); |
| 1412 | |
| 1413 | impl DiskError { |
| 1414 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 1415 | Self(error.into()) |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | impl std::fmt::Display for DiskError { |
| 1420 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1421 | write!(f, "could not measure the disk: {}", self.0) |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | impl std::error::Error for DiskError { |
| 1426 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 1427 | Some(&*self.0) |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | |
| 1436 | |
| 1437 | |
| 1438 | |
| 1439 | |
| 1440 | |
| 1441 | pub trait DatabaseSnapshot: Send + Sync { |
| 1442 | |
| 1443 | |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | |
| 1448 | |
| 1449 | fn snapshot( |
| 1450 | &self, |
| 1451 | workspace: &std::path::Path, |
| 1452 | ) -> impl Future<Output = Result<PathBuf, BackupError>> + Send; |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | fn replace( |
| 1464 | &self, |
| 1465 | source: &std::path::Path, |
| 1466 | ) -> impl Future<Output = Result<(), BackupError>> + Send; |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | pub trait BackupArchive: Send + Sync { |
| 1476 | |
| 1477 | fn pack(&self, plan: BackupPlan) -> impl Future<Output = Result<u64, BackupError>> + Send; |
| 1478 | |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | fn manifest( |
| 1484 | &self, |
| 1485 | archive: &std::path::Path, |
| 1486 | ) -> impl Future<Output = Result<super::backup::BackupManifest, BackupError>> + Send; |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 | fn unpack(&self, plan: RestorePlan) -> impl Future<Output = Result<(), BackupError>> + Send; |
| 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | pub const BACKUP_MANIFEST: &str = "manifest.json"; |
| 1503 | |
| 1504 | |
| 1505 | pub const BACKUP_DATABASE: &str = "steid.db"; |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | pub const BACKUP_DATA_PREFIX: &str = "data"; |
| 1513 | |
| 1514 | |
| 1515 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 1516 | pub struct BackupPlan { |
| 1517 | |
| 1518 | pub destination: PathBuf, |
| 1519 | |
| 1520 | pub database: PathBuf, |
| 1521 | |
| 1522 | pub data_dir: PathBuf, |
| 1523 | pub manifest: super::backup::BackupManifest, |
| 1524 | } |
| 1525 | |
| 1526 | |
| 1527 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 1528 | pub struct RestorePlan { |
| 1529 | pub archive: PathBuf, |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | pub database: PathBuf, |
| 1534 | |
| 1535 | pub data_dir: PathBuf, |
| 1536 | |
| 1537 | pub existing: ExistingData, |
| 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 1546 | pub enum ExistingData { |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | Refuse, |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | Replace { |
| 1562 | |
| 1563 | |
| 1564 | staging: PathBuf, |
| 1565 | |
| 1566 | aside: PathBuf, |
| 1567 | }, |
| 1568 | } |
| 1569 | |
| 1570 | |
| 1571 | #[derive(Debug)] |
| 1572 | pub enum BackupError { |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | Malformed(String), |
| 1579 | |
| 1580 | Refused(String), |
| 1581 | |
| 1582 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 1583 | } |
| 1584 | |
| 1585 | impl BackupError { |
| 1586 | pub fn malformed(reason: impl Into<String>) -> Self { |
| 1587 | Self::Malformed(reason.into()) |
| 1588 | } |
| 1589 | |
| 1590 | pub fn refused(reason: impl Into<String>) -> Self { |
| 1591 | Self::Refused(reason.into()) |
| 1592 | } |
| 1593 | |
| 1594 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 1595 | Self::Backend(error.into()) |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | impl std::fmt::Display for BackupError { |
| 1600 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1601 | match self { |
| 1602 | Self::Malformed(reason) => write!(f, "that is not a usable backup: {reason}"), |
| 1603 | Self::Refused(reason) => write!(f, "refusing: {reason}"), |
| 1604 | Self::Backend(error) => write!(f, "the backup could not be handled: {error}"), |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | impl std::error::Error for BackupError { |
| 1610 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 1611 | match self { |
| 1612 | Self::Malformed(_) | Self::Refused(_) => None, |
| 1613 | Self::Backend(error) => Some(&**error), |
| 1614 | } |
| 1615 | } |
| 1616 | } |