From df799c0a470d4940b53c4935eac10e6f39215518 Mon Sep 17 00:00:00 2001 From: AJIOB Date: Wed, 7 Feb 2024 19:17:41 +0300 Subject: [PATCH] Add possibility to answer without response if file isn't exist --- core/src/services/webdav/backend.rs | 17 ++++++++++++++--- core/src/services/webdav/lister.rs | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/core/src/services/webdav/backend.rs b/core/src/services/webdav/backend.rs index e2279d1f03aa..75106ddbe7c3 100644 --- a/core/src/services/webdav/backend.rs +++ b/core/src/services/webdav/backend.rs @@ -33,6 +33,7 @@ use serde::Deserialize; use super::error::parse_error; use super::lister::Multistatus; +use super::lister::MultistatusOptional; use super::lister::WebdavLister; use super::writer::WebdavWriter; use crate::raw::*; @@ -303,10 +304,20 @@ impl Accessor for WebdavBackend { } let bs = resp.into_body().bytes().await?; - let result: Multistatus = + let result: MultistatusOptional = quick_xml::de::from_reader(bs.reader()).map_err(new_xml_deserialize_error)?; - let item = result - .response + + let response = match result.response { + Some(v) => v, + None => { + return Err(Error::new( + ErrorKind::NotFound, + "Failed getting item stat: response field was not found", + )) + } + }; + + let item = response .first() .ok_or_else(|| { Error::new( diff --git a/core/src/services/webdav/lister.rs b/core/src/services/webdav/lister.rs index adca8ef6b814..131084445064 100644 --- a/core/src/services/webdav/lister.rs +++ b/core/src/services/webdav/lister.rs @@ -78,6 +78,11 @@ pub struct Multistatus { pub response: Vec, } +#[derive(Deserialize, Debug, PartialEq, Eq, Clone)] +pub struct MultistatusOptional { + pub response: Option>, +} + #[derive(Deserialize, Debug, PartialEq, Eq, Clone)] pub struct ListOpResponse { pub href: String,