tesses-backup/TessesDedup/FilesystemEntry.cs

66 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Tesses.VirtualFilesystem;
using Zio;
namespace TessesDedup
{
public class FilesystemEntry
{
[JsonProperty("name")]
public string Name {get;set;}="";
[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter),typeof(CamelCaseNamingStrategy))]
public FilesystemEntryType Type {get;set;} = FilesystemEntryType.Dir;
[JsonProperty("entries")]
public List<FilesystemEntry> Entries {get;set;}=new List<FilesystemEntry>();
[JsonProperty("hashes")]
public List<string> Hashes {get;set;}=new List<string>();
[JsonProperty("length")]
public long Length {get;set;}
[JsonProperty("points_to")]
public string PointsTo {get;set;}
public FilesystemEntry WithoutHashes()
{
if(Type == FilesystemEntryType.Dir)
{
FilesystemEntry ent=new FilesystemEntry();
ent.Name = Name;
ent.Type = FilesystemEntryType.Dir;
foreach(var item in Entries)
{
ent.Entries.Add(item.WithoutHashes());
}
return ent;
}
else if(Type == FilesystemEntryType.File)
{
FilesystemEntry ent=new FilesystemEntry();
ent.Length = Length;
ent.Name = Name;
ent.Type = FilesystemEntryType.File;
return ent;
}
return this;
}
}
public enum FilesystemEntryType
{
Dir,
File,
Symlink
}
}