Skip to content
Merged
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
42 changes: 35 additions & 7 deletions src/SharpSync/Storage/WebDavStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -930,14 +930,42 @@ private string GetFullPath(string relativePath) {
}

private string GetRelativePath(string fullUrl) {
var prefix = string.IsNullOrEmpty(RootPath) ? _baseUrl : $"{_baseUrl}/{RootPath}";

if (fullUrl.StartsWith(prefix)) {
var relativePath = fullUrl.Substring(prefix.Length).Trim('/');
return string.IsNullOrEmpty(relativePath) ? "/" : relativePath;
// The fullUrl can be either a full URL (http://server/path) or just a path (/path)
// We need to strip the base URL and RootPath to get the relative path

// Extract the path portion if it's a full URL
string path;
if (Uri.TryCreate(fullUrl, UriKind.Absolute, out var uri)) {
// It's a full URL - get the path component and decode it
path = Uri.UnescapeDataString(uri.AbsolutePath);
} else {
// It's already a path
path = fullUrl;
}

return fullUrl;

// Remove leading slash for consistency
path = path.TrimStart('/');

// If there's no root path, return the path as-is (trimming trailing slashes)
if (string.IsNullOrEmpty(RootPath)) {
return path.TrimEnd('/');
}

// Normalize the root path (no leading/trailing slashes)
var normalizedRoot = RootPath.Trim('/');

// The path should start with RootPath/
if (path.StartsWith($"{normalizedRoot}/")) {
return path.Substring(normalizedRoot.Length + 1).TrimEnd('/');
}

// If it's exactly the root path itself (directory listing)
if (path == normalizedRoot || path == $"{normalizedRoot}/") {
return "";
}

// Otherwise return as-is (trim trailing slashes)
return path.TrimEnd('/');
}

private bool _rootPathCreated;
Expand Down
5 changes: 0 additions & 5 deletions tests/SharpSync.Tests/Storage/WebDavStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,6 @@ public async Task ListItemsAsync_WithFiles_ReturnsAllItems() {
await Task.Delay(100);
}

// Debug output
foreach (var item in items!) {
System.Diagnostics.Debug.WriteLine($"Found item: {item.Path}, IsDirectory: {item.IsDirectory}");
}

// Assert
Assert.Equal(3, items.Count);
Assert.Contains(items, i => i.Path.EndsWith("file1.txt") && !i.IsDirectory);
Expand Down