Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove nanoseconds in creationdate for Windows compatibility #35

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading