Ejemplo n.º 1
0
        private void WriteBlockPart(BlockId blockId, long pos, int fileType, byte[] buf, int bufSize)
        {
            // Make sure this process is exclusive
            lock (blockUploadLock) {
                try {
                    BlockData data = GetBlockData(blockId, fileType);
                    if (pos == 0)
                    {
                        if (data.Exists)
                        {
                            throw new ApplicationException("Block data exists.");
                        }

                        data.Create();
                    }

                    if (data.Length != pos)
                    {
                        throw new ApplicationException("Block sync issue on block file.");
                    }

                    // Everything ok, we can write the file,
                    Stream fout = data.OpenWrite();
                    fout.Write(buf, 0, bufSize);
                    fout.Close();
                } catch (IOException e) {
                    throw new ApplicationException("IO Error: " + e.Message);
                }
            }
        }