Skip to content

Commit

Permalink
v14.0.13424-Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Jan 8, 2024
1 parent 8011eed commit 1b15eed
Show file tree
Hide file tree
Showing 192 changed files with 46,868 additions and 50,479 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<VersionPrefix>13.4.13237</VersionPrefix>
<VersionPrefix>14.0.13424-Beta</VersionPrefix>
<AssemblyName>CalDAVServer.FileSystemStorage.AspNetCore</AssemblyName>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
Expand All @@ -16,9 +16,9 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="ITHit.Server" Version="13.4.13237" />
<PackageReference Include="ITHit.Server.Core" Version="13.4.13237" />
<PackageReference Include="ITHit.WebDAV.Server" Version="13.4.13237" />
<PackageReference Include="ITHit.Server" Version="14.0.13424-Beta" />
<PackageReference Include="ITHit.Server.Core" Version="14.0.13424-Beta" />
<PackageReference Include="ITHit.WebDAV.Server" Version="14.0.13424-Beta" />
<PackageReference Include="System.Data.OleDb" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public static async Task ReadConfigurationAsync(this IConfigurationSection confi
{
FileSystemInfoExtension.UseFileSystemAttribute(new FileSystemExtendedAttribute(config.AttrStoragePath, config.RepositoryPath));
}
else if (!await new DirectoryInfo(config.RepositoryPath).IsExtendedAttributesSupportedAsync())
{
var tempPath = Path.Combine(Path.GetTempPath(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
FileSystemInfoExtension.UseFileSystemAttribute(new FileSystemExtendedAttribute(tempPath, config.RepositoryPath));
}
}
}
}
3 changes: 3 additions & 0 deletions CS/CalDAVServer.FileSystemStorage.AspNetCore/DavFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public virtual async Task<bool> WriteAsync(Stream content, string contentType, l
if (startIndex == 0 && fileInfo.Length > 0)
{
await using (FileStream filestream = fileInfo.Open(FileMode.Truncate)) { }

// Refresh file state since file was truncated.
fileInfo.Refresh();
}
await WriteInternalAsync(content, contentType, startIndex, totalFileSize);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace CalDAVServer.FileSystemStorage.AspNetCore.ExtendedAttributes
{
/// <summary>
/// Provides methods for reading and writing extended attributes on files and folders.
/// NTFS alternate data streams are used to store attributes.
/// </summary>
public class ExtendedAttribute : IExtendedAttribute
{
private readonly string pathFormat = "{0}:{1}";

/// <summary>
/// Checks extended attribute existence.
/// </summary>
/// <param name="path">File or folder path.</param>
/// <param name="attribName">Attribute name.</param>
/// <returns>True if attribute exist, false otherwise.</returns>
public async Task<bool> HasExtendedAttributeAsync(string path, string attribName)
{
if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrEmpty(attribName)) throw new ArgumentNullException(nameof(attribName));

bool attributeExists = true;
string fullPath = string.Format(pathFormat, path, attribName);

if (!File.Exists(fullPath))
{
attributeExists = false;
}
return attributeExists;
}

/// <summary>
/// Deletes extended attribute.
/// </summary>
/// <param name="path">File or folder path.</param>
/// <param name="attribName">Attribute name.</param>
public async Task DeleteExtendedAttributeAsync(string path, string attribName)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}

if (string.IsNullOrEmpty(attribName))
{
throw new ArgumentNullException("attribName");
}

string fullPath = string.Format(pathFormat, path, attribName);
File.Delete(fullPath);
}

/// <summary>
/// Gets extended attribute.
/// </summary>
/// <param name="path">File or folder path.</param>
/// <param name="attribName">Attribute name.</param>
/// <returns>Attribute value or null if attribute or file not found.</returns>
public async Task<string> GetExtendedAttributeAsync(string path, string attribName)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}

if (string.IsNullOrEmpty(attribName))
{
throw new ArgumentNullException("attribName");
}

string fullPath = string.Format(pathFormat, path, attribName);
if (File.Exists(fullPath))
{
await using (FileStream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
using (StreamReader streamReader = new StreamReader(fileStream))
{
return await streamReader.ReadToEndAsync();
}
}

return null;
}

/// <summary>
/// Sets extended attribute.
/// </summary>
/// <param name="path">File or folder path.</param>
/// <param name="attribName">Attribute name.</param>
/// <param name="attribValue">Attribute value.</param>
public async Task SetExtendedAttributeAsync(string path, string attribName, string attribValue)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}

if (string.IsNullOrEmpty(attribName))
{
throw new ArgumentNullException("attribName");
}

if (attribValue == null)
{
throw new ArgumentNullException("attribValue");
}

string fullPath = string.Format(pathFormat, path, attribName);
await using (FileStream fileStream = File.Open(fullPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete))
await using (StreamWriter streamWriter = new StreamWriter(fileStream))
{
await streamWriter.WriteAsync(attribValue);
}
}

public Task DeleteExtendedAttributes(string path)
{
throw new NotImplementedException();
}

public Task MoveExtendedAttributes(string sourcePath, string destinationPath)
{
throw new NotImplementedException();
}

public Task CopyExtendedAttributes(string sourcePath, string destinationPath)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ public FileSystemExtendedAttribute(string attrStoragePath, string dataStoragePat
this.DataStoragePath = System.IO.Path.GetFullPath(dataStoragePath);
}

/// <summary>
/// Determines whether extended attributes are supported.
/// </summary>
/// <param name="path">File or folder path.</param>
/// <returns>True if extended attributes or NTFS file alternative streams are supported, false otherwise.</returns>
public async Task<bool> IsExtendedAttributesSupportedAsync(string path)
{
return false;
}

/// <summary>
/// Checks extended attribute existence.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace CalDAVServer.FileSystemStorage.AspNetCore.ExtendedAttributes
public static class FileSystemInfoExtension
{
/// <summary>
/// Depending on OS holds WindowsExtendedAttribute, OSXExtendedAttribute or LinuxExtendedAttribute class instance.
/// Implementation of <see cref="IExtendedAttribute"/>.
/// </summary>
private static IExtendedAttribute extendedAttribute;
private static IExtendedAttribute extendedAttribute = new ExtendedAttribute();

/// <summary>
/// Sets <see cref="FileSystemExtendedAttribute"/> as a storage for attributes.
Expand All @@ -36,54 +36,6 @@ public static bool IsUsingFileSystemAttribute
{
get { return extendedAttribute is FileSystemExtendedAttribute; }
}

/// <summary>
/// Initializes static class members.
/// </summary>
static FileSystemInfoExtension()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
extendedAttribute = new WindowsExtendedAttribute();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
extendedAttribute = new LinuxExtendedAttribute();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
extendedAttribute = new OSXExtendedAttribute();
}
else
{
throw new Exception("Not Supported OS");
}
}

/// <summary>
/// Determines whether extended attributes are supported.
/// </summary>
/// <param name="info"><see cref="FileSystemInfo"/> instance.</param>
/// <returns>True if extended attributes or NTFS file alternative streams are supported, false otherwise.</returns>
public static async Task<bool> IsExtendedAttributesSupportedAsync(this FileSystemInfo info)
{
if (info == null)
{
throw new ArgumentNullException("info");
}

return await extendedAttribute.IsExtendedAttributesSupportedAsync(info.FullName);
}

/// <summary>
/// Determines whether extended attributes are supported.
/// </summary>
/// <param name="info"><see cref="FileSystemInfo"/> instance.</param>
/// <returns>True if extended attributes or NTFS file alternative streams are supported, false otherwise.</returns>
public static bool IsExtendedAttributesSupported(this FileSystemInfo info)
{
return info.IsExtendedAttributesSupportedAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}
/// <summary>
/// Checks whether a FileInfo or DirectoryInfo object is a directory, or intended to be a directory.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ namespace CalDAVServer.FileSystemStorage.AspNetCore.ExtendedAttributes
/// </summary>
public interface IExtendedAttribute
{
/// <summary>
/// Determines whether extended attributes are supported.
/// </summary>
/// <param name="path">File or folder path.</param>
/// <returns>True if extended attributes or NTFS file alternative streams are supported, false otherwise.</returns>
Task<bool> IsExtendedAttributesSupportedAsync(string path);

/// <summary>
/// Checks extended attribute existence.
/// </summary>
Expand Down
Loading

0 comments on commit 1b15eed

Please sign in to comment.