Compare commits

..

No commits in common. "8437750a616b241c8cd0c9e4870d6bba0bc96474" and "d9941a0bc257b74b46899d211d88c8d945bae3ca" have entirely different histories.

3 changed files with 8 additions and 83 deletions

View File

@ -22,9 +22,6 @@ namespace TessesDedup
[JsonIgnore] [JsonIgnore]
public string PasswordSalt {get;set;} public string PasswordSalt {get;set;}
[JsonIgnore]
public long BlockCount {get;set;}=0;
public void NewSalt() public void NewSalt()
{ {
byte[] bytes=new byte[64]; byte[] bytes=new byte[64];

View File

@ -12,7 +12,6 @@ using Tesses.WebServer;
using System.Xml; using System.Xml;
using System.Text; using System.Text;
using System.Web; using System.Web;
using System.Data.Common;
namespace TessesDedup namespace TessesDedup
{ {
@ -250,34 +249,6 @@ namespace TessesDedup
routeServer.Add("/api/v1/Registered",RegisteredAsync,"GET"); routeServer.Add("/api/v1/Registered",RegisteredAsync,"GET");
routeServer.Add("/api/v1/Stats",StatsAsync,"GET"); routeServer.Add("/api/v1/Stats",StatsAsync,"GET");
using(var _db = Database)
{
if(_db.Accounts.Count() == 1)
{
var acnt = _db.Accounts.FindAll().First();
if(acnt.BlockCount == 0)
{
long blocks=0;
foreach(var dir in fs.EnumerateDirectories(Special.Root))
{
foreach(var dir2 in fs.EnumerateDirectories(dir))
{
foreach(var file in fs.EnumerateFiles(dir2))
{
blocks++;
}
}
}
acnt.BlockCount = blocks;
_db.Accounts.Update(acnt);
}
}
}
} }
private async Task AccessKeyDeleteAsync(ServerContext ctx) private async Task AccessKeyDeleteAsync(ServerContext ctx)
@ -334,8 +305,7 @@ namespace TessesDedup
private async Task StatsAsync(ServerContext ctx) private async Task StatsAsync(ServerContext ctx)
{ {
if(await Unauthenticated(ctx)) return; if(await Unauthenticated(ctx)) return;
long blocks = 0;
/*
await foreach(var dir in fs.EnumerateDirectoriesAsync(Special.Root)) await foreach(var dir in fs.EnumerateDirectoriesAsync(Special.Root))
{ {
await foreach(var dir2 in fs.EnumerateDirectoriesAsync(dir)) await foreach(var dir2 in fs.EnumerateDirectoriesAsync(dir))
@ -347,25 +317,10 @@ namespace TessesDedup
} }
}*/ }
using(var db = Database)
{
var key = GetAuthorizationKey(ctx);
var ak=db.AccessKeys.FindOne(e=>e.Key == key);
var user = db.Accounts.FindById(ak.UserId);
if(user != null)
{
long blocks = user.BlockCount;
long bytes = blocks*DedupStorage.BlockLength; long bytes = blocks*DedupStorage.BlockLength;
using(var db = Database)
await ctx.SendJsonAsync(new{blocks,bytes,backups=db.Backups.Count(),label=BytesToUnited(bytes)}); await ctx.SendJsonAsync(new{blocks,bytes,backups=db.Backups.Count(),label=BytesToUnited(bytes)});
}
}
} }
public bool Registered() public bool Registered()
@ -594,14 +549,8 @@ namespace TessesDedup
private async Task PutBlockAsync(ServerContext ctx) private async Task PutBlockAsync(ServerContext ctx)
{ {
if(await Unauthenticated(ctx)) return; if(await Unauthenticated(ctx)) return;
var vals=await ctx.ReadBytesAsync(); var vals=await ctx.ReadBytesAsync();
await ctx.SendTextAsync(Storage.WriteBlock(vals),"text/plain");
long acntId=GetAccountId(ctx);
string res = Storage.WriteBlock(vals,this,acntId);
await ctx.SendTextAsync(res,"text/plain");
} }
private async Task HasBlockAsync(ServerContext ctx) private async Task HasBlockAsync(ServerContext ctx)
@ -746,28 +695,18 @@ namespace TessesDedup
return BitConverter.ToString(hash).ToLower().Replace("-",""); return BitConverter.ToString(hash).ToLower().Replace("-","");
} }
} }
public string WriteBlock(byte[] data)
public string WriteBlock(byte[] data,Dedup dedup,long acntId)
{ {
if(data.Length != BlockLength) if(data.Length != BlockLength)
mtx.WaitOne(); mtx.WaitOne();
string hash=Sha512Hash(data); string hash=Sha512Hash(data);
if(!HasBlock(hash)) if(!HasBlock(hash))
{ {
string hashSlice1 = hash.Substring(0,2); string hashSlice1 = hash.Substring(0,2);
string hashSlice2 = hash.Substring(2,2); string hashSlice2 = hash.Substring(2,2);
vfs.CreateDirectory(Special.Root / hashSlice1); vfs.CreateDirectory(Special.Root / hashSlice1);
vfs.CreateDirectory(Special.Root / hashSlice1 / hashSlice2); vfs.CreateDirectory(Special.Root / hashSlice1 / hashSlice2);
vfs.WriteAllBytes(GetHashPath(hash),data); vfs.WriteAllBytes(GetHashPath(hash),data);
using(var db = dedup.Database)
{
var acnt=db.Accounts.FindById(acntId);
acnt.BlockCount++;
db.Accounts.Update(acnt);
}
} }
mtx.ReleaseMutex(); mtx.ReleaseMutex();
return hash; return hash;

View File

@ -16,7 +16,6 @@ using Tesses.VirtualFilesystem;
using Tesses.VirtualFilesystem.Extensions; using Tesses.VirtualFilesystem.Extensions;
using Tesses.WebServer; using Tesses.WebServer;
using System.Net; using System.Net;
using System.Security;
namespace TessesDedup namespace TessesDedup
{ {
public class DedupClient : IDisposable public class DedupClient : IDisposable
@ -25,17 +24,14 @@ namespace TessesDedup
string url; string url;
bool ownClient; bool ownClient;
public bool ShowProgress {get;set;} public bool ShowProgress {get;set;}
public bool IgnoreErrors {get;set;} public DedupClient(HttpClient client, string url,bool ownClient=true,bool showProgress=true)
public DedupClient(HttpClient client, string url,bool ownClient=true,bool showProgress=true,bool ignoreErrors=true)
{ {
ShowProgress = showProgress; ShowProgress = showProgress;
IgnoreErrors = ignoreErrors;
this.clt = client; this.clt = client;
this.url = url.TrimEnd('/'); this.url = url.TrimEnd('/');
this.ownClient = ownClient; this.ownClient = ownClient;
} }
public DedupClient(string url,bool showProgress=true,bool ignoreErrors=true) : this(new HttpClient(),url,true,showProgress,ignoreErrors) public DedupClient(string url,bool showProgress=true) : this(new HttpClient(),url,true,showProgress)
{ {
} }
@ -163,14 +159,7 @@ namespace TessesDedup
await foreach(var ent in fs.EnumerateFileSystemEntriesAsync(path)) await foreach(var ent in fs.EnumerateFileSystemEntriesAsync(path))
{ {
if(token.IsCancellationRequested) return entry; if(token.IsCancellationRequested) return entry;
try{
entry.Entries.Add(await BackupPathAsync(authkey,fs,ent,token)); entry.Entries.Add(await BackupPathAsync(authkey,fs,ent,token));
}catch(Exception ex)
{
_=ex;
if(!IgnoreErrors)
throw;
}
} }
return entry; return entry;
} }