/// <inheritdoc/> private ObjectId SaveStream(OdbStreamWriter stream) { ObjectId objId = stream.CurrentHash; string fileUrl = BuildUrl(vfsRootUrl, objId); string temporaryFilePath = stream.TemporaryName; lock (LockOnMove) { // File may already exists, in this case we decide to not override it. if (!virtualFileProvider.FileExists(fileUrl)) { try { // Remove the second part of ObjectId to get the path (cf BuildUrl) virtualFileProvider.CreateDirectory(fileUrl.Substring(0, fileUrl.Length - (ObjectId.HashStringLength - 2))); virtualFileProvider.FileMove(temporaryFilePath, BuildUrl(vfsRootUrl, objId)); } catch (IOException e) { // Ignore only IOException "The destination file already exists." // because other exceptions that we want to catch might inherit from IOException. // This happens if two FileMove were performed at the same time. if (e.GetType() != typeof(IOException)) { throw; } // But we should still clean our temporary file virtualFileProvider.FileDelete(temporaryFilePath); } } else { // But we should still clean our temporary file virtualFileProvider.FileDelete(temporaryFilePath); } } return(objId); }
/// <inheritdoc/> private ObjectId SaveStream(OdbStreamWriter stream) { ObjectId objId = stream.CurrentHash; string fileUrl = BuildUrl(vfsRootUrl, objId); string temporaryFilePath = stream.TemporaryName; lock (LockOnMove) { // File may already exists, in this case we decide to not override it. if (!virtualFileProvider.FileExists(fileUrl)) { try { // Remove the second part of ObjectId to get the path (cf BuildUrl) virtualFileProvider.CreateDirectory(fileUrl.Substring(0, fileUrl.Length - (ObjectId.HashStringLength - 2))); virtualFileProvider.FileMove(temporaryFilePath, BuildUrl(vfsRootUrl, objId)); } catch (IOException e) { // Ignore only IOException "The destination file already exists." // because other exceptions that we want to catch might inherit from IOException. // This happens if two FileMove were performed at the same time. if (e.GetType() != typeof(IOException)) throw; // But we should still clean our temporary file virtualFileProvider.FileDelete(temporaryFilePath); } } else { // But we should still clean our temporary file virtualFileProvider.FileDelete(temporaryFilePath); } } return objId; }