mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[server] Delete chunk files when saving if the chunk is empty
This commit is contained in:
parent
3e21ef5745
commit
f4205997d9
1 changed files with 13 additions and 2 deletions
|
@ -224,12 +224,17 @@ namespace Nibriboard.RippleSpace
|
|||
return;
|
||||
|
||||
Chunk chunk = loadedChunkspace[chunkLocation];
|
||||
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilepath());
|
||||
|
||||
// If it's empty, then there's no point in saving it
|
||||
if (chunk.IsEmpty)
|
||||
{
|
||||
// Delete the existing chunk file, if it
|
||||
if (File.Exists(chunkFilePath))
|
||||
File.Delete(chunkFilePath);
|
||||
return;
|
||||
}
|
||||
|
||||
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilepath());
|
||||
|
||||
using (Stream chunkDestination = File.Open(chunkFilePath, FileMode.OpenOrCreate))
|
||||
await chunk.SaveTo(chunkDestination);
|
||||
|
@ -307,9 +312,15 @@ namespace Nibriboard.RippleSpace
|
|||
// Figure out where to put the chunk and create the relevant directories
|
||||
string chunkDestinationFilename = CalcPaths.ChunkFilepath(StorageDirectory, loadedChunkItem.Key);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(chunkDestinationFilename));
|
||||
|
||||
// Ask the chunk to save itself, but only if it isn't empty
|
||||
if (loadedChunkItem.Value.IsEmpty)
|
||||
if (loadedChunkItem.Value.IsEmpty) {
|
||||
// Delete the existing chunk file, if it
|
||||
if (File.Exists(chunkDestinationFilename))
|
||||
File.Delete(chunkDestinationFilename);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Stream chunkDestination = File.Open(chunkDestinationFilename, FileMode.OpenOrCreate);
|
||||
chunkSavers.Add(loadedChunkItem.Value.SaveTo(chunkDestination));
|
||||
|
|
Loading…
Reference in a new issue