Possible fix for issue #209
git-svn-id: https://duplicati.googlecode.com/svn/trunk@420 59da171f-624f-0410-aa54-27559c288bec
This commit is contained in:
@@ -160,7 +160,7 @@ namespace Duplicati.Library.Backend
|
||||
List<FileEntry> lst = new List<FileEntry>();
|
||||
using(System.Net.WebResponse resp = req.GetResponse())
|
||||
using(System.IO.Stream rs = resp.GetResponseStream())
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(rs))
|
||||
using(System.IO.StreamReader sr = new System.IO.StreamReader(new StreamReadHelper(rs)))
|
||||
{
|
||||
string line;
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
@@ -349,5 +349,50 @@ namespace Duplicati.Library.Backend
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Private helper class to fix a bug with the StreamReader
|
||||
/// </summary>
|
||||
private class StreamReadHelper : Core.OverrideableStream
|
||||
{
|
||||
/// <summary>
|
||||
/// Once the stream has returned 0 as the read count it is disposed
|
||||
/// in the FtpRequest, and subsequent read requests will throw an ObjectDisposedException
|
||||
/// </summary>
|
||||
private bool m_empty = false;
|
||||
|
||||
/// <summary>
|
||||
/// Basic initialization, just pass the stream to the super class
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
public StreamReadHelper(System.IO.Stream stream)
|
||||
: base(stream)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the read function to make sure that we only return less than the requested amount of data if the stream is exhausted
|
||||
/// </summary>
|
||||
/// <param name="buffer">The buffer to place data in</param>
|
||||
/// <param name="offset">The offset into the buffer to start at</param>
|
||||
/// <param name="count">The number of bytes to read</param>
|
||||
/// <returns>The number of bytes read</returns>
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int readCount = 0;
|
||||
int a;
|
||||
|
||||
while(!m_empty && count > 0)
|
||||
{
|
||||
a = base.Read(buffer, offset, count);
|
||||
readCount += a;
|
||||
count -= a;
|
||||
offset += a;
|
||||
m_empty = a == 0;
|
||||
}
|
||||
|
||||
return readCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user