saqibpitafi / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

stream is not closed after exception in UploadDocument #224

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, already reported as http://code.google.com/p/gdata-
issues/issues/detail?id=1053, but reported here.

Steps to reproduce:
1. Create temporary PDF file
2. Try Uploading it with UploadDocument
3. Get Exception (as currently Google rejects PDF when it's uploaded)
4. File is locked, you cannot delete it

This issue is very important to solve as it might result in a lot of files 
locking on web server if any internal google exceptions occur.

We had to add this code into (DocumentEntry UploadDocument) to make it 
work:
FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read, 
FileShare.ReadWrite);
try
{                
DocumentEntry entry = this.Insert(postUri, stream, contentType, 
documentName) as DocumentEntry;
return entry;
}           
finally
{
stream.Close();
}        

Also, this part of code fixes another problem. If you try uploading file of 
unsupported extension, it will throw exception before closing the stream - 
again lock :(

Original issue reported on code.google.com by lek...@gmail.com on 10 Mar 2009 at 6:52

GoogleCodeExporter commented 9 years ago
I will add this to the mainline as soon as I am back from travelling. Thanks 
for reporting this.

Original comment by fman...@gmail.com on 11 Mar 2009 at 6:02

GoogleCodeExporter commented 9 years ago
checked into the source, if you sync and verify, i would appreciate it. 

Original comment by fman...@gmail.com on 23 Mar 2009 at 2:51

GoogleCodeExporter commented 9 years ago
it works, thanks

Original comment by lek...@gmail.com on 24 Mar 2009 at 11:15