Skip to content

Commit

Permalink
fix: temporarly included webdav-xml into project to fix parsing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Mar 2, 2024
1 parent 4dcac9f commit 6a9f2d6
Show file tree
Hide file tree
Showing 35 changed files with 1,911 additions and 42 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Changelog

- [Changelog](#changelog)
- [0.1.1](#011)
- [0.1.0](#010)

---

## 0.1.1

Released on 02/03/2024

- Temporarily included a custom version of webdav-xml inside the project to fix proplist response parser
- Follow up <https://github.com/d-k-bo/webdav-rs/pull/1>

## 0.1.0

Released on 02/03/2024
Expand Down
30 changes: 10 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "remotefs-webdav"
version = "0.1.0"
version = "0.1.1"
authors = ["Christian Visintin <[email protected]>"]
edition = "2021"
categories = ["network-programming"]
Expand All @@ -14,11 +14,24 @@ repository = "https://github.com/veeso/remotefs-rs-webdav"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bytes = "1.5"
log = "0.4"
remotefs = "0.2"
rustydav = "0.1.3"
thiserror = "^1.0"
webdav-xml = "^0.1"
#webdav-xml = "^0.1"
#webdav-xml = { git = "https://github.com/veeso/webdav-rs.git", package = "webdav-xml" }

# webdav-xml deps
bytestring = "1.3.1"
http = "1"
httpdate = "1.0.3"
indexmap = "2.2.3"
mime = "0.3.17"
nonempty = "0.9.0"
quick-xml = "0.31.0"
time = { version = "0.3.34", features = ["parsing", "formatting"] }


[dev-dependencies]
env_logger = "^0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p align="center">~ Remotefs WebDAV client ~</p>

<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
<p align="center">Current version: 0.1.0 (02/03/2024)</p>
<p align="center">Current version: 0.1.1 (02/03/2024)</p>

<p align="center">
<a href="https://opensource.org/licenses/MIT"
Expand Down
47 changes: 31 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern crate log;
#[cfg(test)]
mod mock;
mod parser;
mod webdav_xml;

use std::io::Read;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -58,10 +59,10 @@ impl WebDAVFs {
}

/// Resolve query url
fn url(&self, path: &Path) -> String {
fn url(&self, path: &Path, force_dir: bool) -> String {
let mut p = self.url.clone();
p.push_str(&self.path(path).to_string_lossy());
if !p.ends_with('/') && path.is_dir() {
if !p.ends_with('/') && (path.is_dir() || force_dir) {
p.push('/');
}
p
Expand Down Expand Up @@ -103,12 +104,15 @@ impl RemoteFs for WebDAVFs {
self.list_dir(&new_dir)?;

self.wrkdir = new_dir.to_string_lossy().to_string();
if !self.wrkdir.ends_with('/') {
self.wrkdir.push('/');
}
debug!("Changed directory to: {}", self.wrkdir);
Ok(new_dir)
}

fn list_dir(&mut self, path: &Path) -> RemoteResult<Vec<File>> {
let url = self.url(path);
let url = self.url(path, true);
debug!("Listing directory: {}", url);
let response = self
.client
Expand All @@ -130,7 +134,7 @@ impl RemoteFs for WebDAVFs {
}

fn stat(&mut self, path: &Path) -> RemoteResult<File> {
let url = self.url(path);
let url = self.url(path, false);
debug!("Listing directory: {}", url);
let response = self
.client
Expand All @@ -154,7 +158,7 @@ impl RemoteFs for WebDAVFs {
}

fn remove_file(&mut self, path: &Path) -> RemoteResult<()> {
let url = self.url(path);
let url = self.url(path, false);
debug!("Removing file: {}", url);
let response = self
.client
Expand All @@ -165,7 +169,14 @@ impl RemoteFs for WebDAVFs {
}

fn remove_dir(&mut self, path: &Path) -> RemoteResult<()> {
self.remove_file(path)
let url = self.url(path, true);
debug!("Removing directory: {}", url);
let response = self
.client
.delete(&url)
.map_err(|e| RemoteError::new_ex(RemoteErrorType::ProtocolError, e))?;

ResponseParser::from(response).status()
}

fn remove_dir_all(&mut self, path: &Path) -> RemoteResult<()> {
Expand All @@ -176,7 +187,7 @@ impl RemoteFs for WebDAVFs {
if self.stat(path).is_ok() {
return Err(RemoteError::new(RemoteErrorType::DirectoryAlreadyExists));
}
let url = self.url(path);
let url = self.url(path, true);
// check if dir exists
debug!("Creating directory: {}", url);
let response = self
Expand All @@ -196,8 +207,8 @@ impl RemoteFs for WebDAVFs {
}

fn mov(&mut self, src: &Path, dest: &Path) -> RemoteResult<()> {
let src_url = self.url(src);
let dest_url = self.url(dest);
let src_url = self.url(src, false);
let dest_url = self.url(dest, false);
debug!("Moving file: {} to {}", src_url, dest_url);

let response = self
Expand Down Expand Up @@ -230,7 +241,7 @@ impl RemoteFs for WebDAVFs {
_metadata: &Metadata,
mut reader: Box<dyn std::io::prelude::Read>,
) -> RemoteResult<u64> {
let url = self.url(path);
let url = self.url(path, false);
debug!("Creating file: {}", url);
let mut content = Vec::new();
reader
Expand All @@ -252,7 +263,7 @@ impl RemoteFs for WebDAVFs {
src: &Path,
mut dest: Box<dyn std::io::prelude::Write + Send>,
) -> RemoteResult<u64> {
let url = self.url(src);
let url = self.url(src, false);
debug!("Opening file: {}", url);
let mut response = self
.client
Expand Down Expand Up @@ -283,6 +294,7 @@ mod test {
use std::io::Cursor;

use pretty_assertions::assert_eq;
#[cfg(feature = "with-containers")]
use serial_test::serial;

use super::*;
Expand All @@ -299,20 +311,23 @@ mod test {
fn test_should_get_url() {
let mut client = WebDAVFs::new("user", "password", "http://localhost:3080");
let path = Path::new("a.txt");
assert_eq!(client.url(path), "http://localhost:3080/a.txt");
assert_eq!(client.url(path, false), "http://localhost:3080/a.txt");

let path = Path::new("/a.txt");
assert_eq!(client.url(path), "http://localhost:3080/a.txt");
assert_eq!(client.url(path, false), "http://localhost:3080/a.txt");

let path = Path::new("/");
assert_eq!(client.url(path), "http://localhost:3080/");
assert_eq!(client.url(path, false), "http://localhost:3080/");

client.wrkdir = "/test/".to_string();
let path = Path::new("a.txt");
assert_eq!(client.url(path), "http://localhost:3080/test/a.txt");
assert_eq!(client.url(path, false), "http://localhost:3080/test/a.txt");

let path = Path::new("/a.txt");
assert_eq!(client.url(path), "http://localhost:3080/a.txt");
assert_eq!(client.url(path, false), "http://localhost:3080/a.txt");

let path = Path::new("/gabibbo");
assert_eq!(client.url(path, true), "http://localhost:3080/gabibbo/");
}

#[test]
Expand Down
Loading

0 comments on commit 6a9f2d6

Please sign in to comment.