Skip to content

Commit

Permalink
fix: remove nanoseconds in creationdate for Windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticLampyrid committed Dec 7, 2024
1 parent 084b56b commit 7e2242c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/handle_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::fs::*;
use crate::handle_lock::{list_lockdiscovery, list_supportedlock};
use crate::ls::*;
use crate::util::MemBuffer;
use crate::util::{dav_xml_error, systemtime_to_httpdate, systemtime_to_rfc3339};
use crate::util::{dav_xml_error, systemtime_to_httpdate, systemtime_to_rfc3339_without_nanosecond};
use crate::{DavInner, DavResult};

const NS_APACHE_URI: &str = "http://apache.org/dav/props/";
Expand Down Expand Up @@ -693,7 +693,7 @@ impl<C: Clone + Send + Sync + 'static> PropWriter<C> {
match prop.name.as_str() {
"creationdate" => {
if let Ok(time) = meta.created() {
let tm = systemtime_to_rfc3339(time);
let tm = systemtime_to_rfc3339_without_nanosecond(time);
return self.build_elem(docontent, pfx, prop, tm);
}
// use ctime instead - apache seems to do this.
Expand All @@ -704,7 +704,7 @@ impl<C: Clone + Send + Sync + 'static> PropWriter<C> {
time = mtime;
}
}
let tm = systemtime_to_rfc3339(time);
let tm = systemtime_to_rfc3339_without_nanosecond(time);
return self.build_elem(docontent, pfx, prop, tm);
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ pub(crate) fn systemtime_to_httpdate(t: SystemTime) -> String {
v[0].to_str().unwrap().to_owned()
}

pub(crate) fn systemtime_to_rfc3339(t: SystemTime) -> String {
pub(crate) fn systemtime_to_rfc3339_without_nanosecond(t: SystemTime) -> String {
// 1996-12-19T16:39:57Z
systemtime_to_offsetdatetime(t).format(&Rfc3339).unwrap()
systemtime_to_offsetdatetime(t)
.replace_nanosecond(0)
.ok()
.and_then(|x| x.format(&Rfc3339).ok())
.unwrap_or("1970-01-01T00:00:00Z".into())
}

// A buffer that implements "Write".
Expand Down Expand Up @@ -205,7 +209,8 @@ mod tests {
use std::time::UNIX_EPOCH;

#[test]
fn test_rfc3339() {
assert!(systemtime_to_rfc3339(UNIX_EPOCH) == "1970-01-01T00:00:00Z");
fn test_rfc3339_no_nanosecond() {
let t = UNIX_EPOCH + std::time::Duration::new(1, 5);
assert!(systemtime_to_rfc3339_without_nanosecond(t) == "1970-01-01T00:00:01Z");
}
}

0 comments on commit 7e2242c

Please sign in to comment.