Skip to content

Commit

Permalink
Merge branch 'develop2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Oct 27, 2020
2 parents 45adb35 + 61d5ef9 commit 0f25f0e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
8 changes: 4 additions & 4 deletions MailRuCloud/MailRuCloudApi/Base/Streams/Cache/CacheStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ private DataCache GetCache()
{
foreach (var rule in _deduplicateRules.Rules)
{
if (
(string.IsNullOrEmpty(rule.Target) || Regex.Match(_file.FullPath, rule.Target).Success) &&
if (
(rule.MaxSize == 0 || rule.MaxSize > _file.Size) &&
_file.Size >= rule.MinSize )
_file.Size >= rule.MinSize &&
(string.IsNullOrEmpty(rule.Target) || Regex.Match(_file.FullPath, rule.Target).Success) )
{
switch (rule.CacheType)
{
case CacheType.Memory : return new MemoryDataCache();
case CacheType.Disk : return new DiskDataCache(_deduplicateRules.DiskPath);
default: throw new NotImplementedException($"DataCache not implmented for {rule.CacheType}");
default: throw new NotImplementedException($"DataCache not implemented for {rule.CacheType}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void Upload()
{
if (Repo.SupportsAddSmallFileByHash && _file.OriginalSize <= _cloudFileHasher.Length) // do not send upload request if file content fits to hash
UploadSmall(_ringBuffer);
else if (Repo.SupportsDeduplicate && _cloud.Settings.UseDeduplicate && !_file.ServiceInfo.IsCrypted) // && !_file.ServiceInfo.SplitInfo.IsPart)
else if (Repo.SupportsDeduplicate && _cloud.Settings.UseDeduplicate) // && !_file.ServiceInfo.IsCrypted) // && !_file.ServiceInfo.SplitInfo.IsPart)
UploadCache(_ringBuffer);
else
UploadFull(_ringBuffer);
Expand Down Expand Up @@ -76,7 +76,7 @@ private void UploadCache(Stream sourceStream)
if (cache.Process())
{
Logger.Debug($"Uploading [{cache.DataCacheName}] {_file.FullPath}");

OnFileStreamSent();

_file.Hash = _cloudFileHasher.Hash;
Expand Down
8 changes: 6 additions & 2 deletions MailRuCloud/MailRuCloudApi/Streams/UploadStreamFabric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ private Stream GetCryptoStream(File file, FileUploadedDelegate onUploaded)
? file.OriginalSize.DefaultValue
: (file.OriginalSize / XTSWriteOnlyStream.BlockSize + 1) * XTSWriteOnlyStream.BlockSize;

var ustream = new SplittedUploadStream(file.FullPath, _cloud, size, FileStreamSent, ServerFileProcessed, false, file.ServiceInfo.CryptInfo);
var ustream = new SplittedUploadStream(file.FullPath, _cloud, size, null, null, false, file.ServiceInfo.CryptInfo);
if (onUploaded != null) ustream.FileUploaded += onUploaded;
// ReSharper disable once RedundantArgumentDefaultValue
var encustream = new XTSWriteOnlyStream(ustream, xts, XTSWriteOnlyStream.DefaultSectorSize);
var encustream = new XTSWriteOnlyStream(ustream, xts, XTSWriteOnlyStream.DefaultSectorSize)
{
FileStreamSent = FileStreamSent,
ServerFileProcessed = ServerFileProcessed
};

return encustream;
}
Expand Down
11 changes: 11 additions & 0 deletions MailRuCloud/MailRuCloudApi/XTSSharp/XTSWriteOnlyStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public XTSWriteOnlyStream(Stream baseStream, Xts xts, int sectorSize = DefaultSe
_sectorBuffer = new byte[sectorSize];
}

public Action FileStreamSent;
private void OnFileStreamSent() => FileStreamSent?.Invoke();

public Action ServerFileProcessed;
private void OnServerFileProcessed() => ServerFileProcessed?.Invoke();


private int _sectorBufferCount;

Expand Down Expand Up @@ -74,10 +80,15 @@ protected override void Dispose(bool disposing)

int transformedCount = _encryptor.TransformBlock(_sectorBuffer, 0, towrite, _encriptedBuffer, 0, _currentSector);
_baseStream.Write(_encriptedBuffer, 0, towrite);

}

OnFileStreamSent();

_baseStream.Dispose();
_encryptor.Dispose();

OnServerFileProcessed();
}


Expand Down
4 changes: 2 additions & 2 deletions MailRuCloud/MailRuCloudApi/YaR.Clouds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFrameworks>netcoreapp3.0;net48</TargetFrameworks>
<RootNamespace>YaR.Clouds</RootNamespace>
<AssemblyName>YaR.Clouds</AssemblyName>
<AssemblyVersion>1.13.0.1</AssemblyVersion>
<FileVersion>1.13.0.1</FileVersion>
<AssemblyVersion>1.13.0.2</AssemblyVersion>
<FileVersion>1.13.0.2</FileVersion>
<Version>$(AssemblyVersion)</Version>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions WDMRC.Console/WDMRC.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<Copyright>[email protected]</Copyright>
<Description>WebDAV emulator for Cloud.mail.ru</Description>
<PackageId>WebDAVCloudMailRu</PackageId>
<AssemblyVersion>1.13.0.1</AssemblyVersion>
<FileVersion>1.13.0.1</FileVersion>
<AssemblyVersion>1.13.0.2</AssemblyVersion>
<FileVersion>1.13.0.2</FileVersion>
<Version>$(AssemblyVersion)</Version>
<AssemblyName>wdmrc</AssemblyName>
<RootNamespace>YaR.Clouds.Console</RootNamespace>
Expand Down
2 changes: 2 additions & 0 deletions WDMRC.Console/wdmrc.config
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@

<!-- files larger than 15000000 bytes will be cached on disk -->
<Rule Cache="Disk" Target = "" MinSize = "15000000" MaxSize = "0" />

<!-- files not matched by any rule above will be uploaded directly -->
</Rules>
</Deduplicate>

Expand Down

0 comments on commit 0f25f0e

Please sign in to comment.