enforced file system

This commit is contained in:
2018-01-26 13:51:09 +01:00
parent 2a523c7eae
commit edd91faa96
26 changed files with 143 additions and 76 deletions

View File

@ -1,4 +1,5 @@
using System.Linq;
using System.Text;
namespace Yavsc.Abstract.FileSystem
{
@ -6,20 +7,35 @@ namespace Yavsc.Abstract.FileSystem
{
public static bool IsValidYavscPath(this string path)
{
if (path == null) return true;
if (string.IsNullOrEmpty(path)) return true;
foreach (var name in path.Split('/'))
{
if (!IsValidDirectoryName(name) || name.Equals("..") || name.Equals("."))
return false;
}
if (path[path.Length]==FileSystemConstants.RemoteDirectorySeparator) return false;
if (path[path.Length-1]==FileSystemConstants.RemoteDirectorySeparator) return false;
return true;
}
public static bool IsValidDirectoryName(this string name)
{
return !name.Any(c => !FileSystemConstants.ValidFileNameChars.Contains(c));
}
// Ensure this path is canonical,
// No "dirto/./this", neither "dirt/to/that/"
// no .. and each char must be listed as valid in constants
public static string FilterFileName(string fileName)
{
if (fileName==null) return null;
StringBuilder sb = new StringBuilder();
foreach (var c in fileName)
{
if (FileSystemConstants.ValidFileNameChars.Contains(c))
sb.Append(c);
else sb.Append('_');
}
return sb.ToString();
}
}
public static class FileSystemConstants

View File

@ -0,0 +1,8 @@
namespace Yavsc.Abstract.FileSystem {
public interface IDirectoryShortInfo
{
string Name { get; set; }
bool IsEmpty { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace Yavsc.Abstract.FileSystem
{
public interface IFileRecievedInfo
{
string MimeType { get; set; }
string DestDir { get; set; }
string FileName { get; set; }
bool Overriden { get; set; }
bool QuotaOffensed { get; set; }
}
}

View File

@ -7,15 +7,21 @@ namespace Yavsc.ViewModels.UserFiles
{
public class UserDirectoryInfo
{
public string UserName { get; private set; }
public string SubPath { get; private set; }
public string UserName { get; set; }
public string SubPath { get; set; }
public RemoteFileInfo [] Files {
get; private set;
get; set;
}
public string [] SubDirectories { 
get; private set;
public DirectoryShortInfo [] SubDirectories { 
get; set;
}
private DirectoryInfo dInfo;
// for deserialization
public UserDirectoryInfo()
{
}
public UserDirectoryInfo(string userReposPath, string username, string path)
{
if (string.IsNullOrWhiteSpace(username))
@ -35,7 +41,12 @@ namespace Yavsc.ViewModels.UserFiles
( entry => new RemoteFileInfo { Name = entry.Name, Size = entry.Length,
CreationTime = entry.CreationTime, LastModified = entry.LastWriteTime }).ToArray();
SubDirectories = dInfo.GetDirectories().Select
( d=> d.Name ).ToArray();
( d=> new DirectoryShortInfo { Name= d.Name, IsEmpty=false } ).ToArray();
}
}
public class DirectoryShortInfo: IDirectoryShortInfo {
public string Name { get; set; }
public bool IsEmpty { get; set; }
}
}