trying to not overcome the quota, [TODO] remove truncated saved part
This commit is contained in:
parent
c70030cd9b
commit
2dc196e79e
1 changed files with 14 additions and 2 deletions
|
|
@ -102,6 +102,12 @@ public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, st
|
||||||
fi.Delete();
|
fi.Delete();
|
||||||
user.DiskUsage -= fi.Length;
|
user.DiskUsage -= fi.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AddQuota(this ApplicationUser user, int quota)
|
||||||
|
{
|
||||||
|
user.DiskQuota += quota;
|
||||||
|
}
|
||||||
|
|
||||||
public static FileRecievedInfo ReceiveUserFile(this ApplicationUser user, string root, IFormFile f, string destFileName = null)
|
public static FileRecievedInfo ReceiveUserFile(this ApplicationUser user, string root, IFormFile f, string destFileName = null)
|
||||||
{
|
{
|
||||||
// TODO lock user's disk usage for this scope,
|
// TODO lock user's disk usage for this scope,
|
||||||
|
|
@ -130,19 +136,25 @@ public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, st
|
||||||
item.QuotaOffensed = true;
|
item.QuotaOffensed = true;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
usage += len;
|
|
||||||
|
|
||||||
while (len > 0)
|
while (len > 0 && usage < user.DiskQuota)
|
||||||
{
|
{
|
||||||
int blen = len > 1024 ? 1024 : (int)len;
|
int blen = len > 1024 ? 1024 : (int)len;
|
||||||
org.Read(buffer, 0, blen);
|
org.Read(buffer, 0, blen);
|
||||||
dest.Write(buffer, 0, blen);
|
dest.Write(buffer, 0, blen);
|
||||||
len -= blen;
|
len -= blen;
|
||||||
|
usage += blen;
|
||||||
}
|
}
|
||||||
|
user.DiskUsage = usage;
|
||||||
dest.Close();
|
dest.Close();
|
||||||
org.Close();
|
org.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (usage >= user.DiskQuota) {
|
||||||
|
item.QuotaOffensed = true;
|
||||||
|
|
||||||
|
}
|
||||||
user.DiskUsage = usage;
|
user.DiskUsage = usage;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue