Skip to content

Commit c5392cc

Browse files
authored
Merge pull request #524 from messense/checksum
Add OwnCloud style sha1 checksums support
2 parents 7c8ebd4 + 38cdaa3 commit c5392cc

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/drive/model.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct ListFileItem {
4949
#[serde(default)]
5050
pub size: u64,
5151
pub url: Option<String>,
52+
pub content_hash: Option<String>,
5253
}
5354

5455
#[derive(Debug, Clone, Serialize)]
@@ -112,6 +113,7 @@ impl From<GetFileResponse> for AliyunFile {
112113
updated_at: res.updated_at,
113114
size,
114115
url: None,
116+
content_hash: None,
115117
}
116118
}
117119
}
@@ -272,6 +274,7 @@ pub struct AliyunFile {
272274
#[serde(default)]
273275
pub size: u64,
274276
pub url: Option<String>,
277+
pub content_hash: Option<String>,
275278
}
276279

277280
impl AliyunFile {
@@ -285,6 +288,7 @@ impl AliyunFile {
285288
updated_at: DateTime(now),
286289
size: 0,
287290
url: None,
291+
content_hash: None,
288292
}
289293
}
290294
}
@@ -304,6 +308,7 @@ impl From<ListFileItem> for AliyunFile {
304308
} else {
305309
f.url
306310
},
311+
content_hash: f.content_hash,
307312
}
308313
}
309314
}

src/vfs.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use dav_server::{
1515
ReadDirMeta,
1616
},
1717
};
18-
use futures_util::future::FutureExt;
18+
use futures_util::future::{ready, FutureExt};
1919
use path_slash::PathBufExt;
2020
use tracing::{debug, error, trace};
2121
use zip::write::{FileOptions, ZipWriter};
@@ -277,6 +277,7 @@ impl DavFileSystem for AliyunDriveFileSystem {
277277
updated_at: DateTime::new(now),
278278
size: size.unwrap_or(0),
279279
url: None,
280+
content_hash: None,
280281
};
281282
let mut uploading = self.uploading.entry(parent_file.id.clone()).or_default();
282283
uploading.push(file.clone());
@@ -512,6 +513,40 @@ impl DavFileSystem for AliyunDriveFileSystem {
512513
}
513514
.boxed()
514515
}
516+
517+
fn have_props<'a>(
518+
&'a self,
519+
_path: &'a DavPath,
520+
) -> std::pin::Pin<Box<dyn futures_util::Future<Output = bool> + Send + 'a>> {
521+
Box::pin(ready(true))
522+
}
523+
524+
fn get_prop(&self, dav_path: &DavPath, prop: dav_server::fs::DavProp) -> FsFuture<Vec<u8>> {
525+
let path = self.normalize_dav_path(dav_path);
526+
debug!(path = %path.display(), "fs: get_prop");
527+
async move {
528+
if prop.namespace.as_deref() == Some("http://owncloud.org/ns")
529+
&& prop.prefix.as_deref() == Some("oc")
530+
&& prop.name == "checksums"
531+
{
532+
let file = self.get_file(path).await?.ok_or(FsError::NotFound)?;
533+
if let Some(sha1) = file.content_hash {
534+
let checksums = format!("sha1:{}", sha1.to_ascii_lowercase());
535+
let xml = format!(
536+
r#"<?xml version="1.0"?>
537+
<oc:checksums xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns" xmlns:oc="http://owncloud.org/ns">
538+
<oc:checksum>{}</oc:checksum>
539+
</oc:checksums>
540+
"#,
541+
checksums
542+
);
543+
return Ok(xml.into_bytes());
544+
}
545+
}
546+
Err(FsError::NotImplemented)
547+
}
548+
.boxed()
549+
}
515550
}
516551

517552
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)