$OpenBSD: patch-src_PartFile_cpp,v 1.2 2016/06/03 11:54:44 dcoppa Exp $

From f2c05727c232b607be5a3b8b78279a669b1e7ef3 Mon Sep 17 00:00:00 2001
From: upstream svn <svn@amule.org>
Date: Sat, 16 Apr 2016 19:16:44 +0000
Subject: [PATCH] Fix crash when importing partfiles with the
"Preallocate space for new files" preference option enabled

Imported parfiles won't have their space preallocated even if it
is requested in the preferences. The whole importing strategy should
be changed for that, and we'd lose many optimizations meanwhile.
On the other hand, the "create sparse files" preference setting is
taken into account.

From 151869b449d49155ea57a2f47579930dca71ea4a Mon Sep 17 00:00:00 2001
From: upstream svn <svn@amule.org>
Date: Sun, 4 Nov 2012 16:32:47 +0000
Subject: [PATCH] Delete broken seeds files

--- src/PartFile.cpp.orig	Sat Oct 15 17:43:21 2011
+++ src/PartFile.cpp	Fri Jun  3 12:14:10 2016
@@ -269,7 +269,7 @@ CPartFile::~CPartFile()
 	wxASSERT(m_A4AFsrclist.empty());
 }
 
-void CPartFile::CreatePartFile()
+void CPartFile::CreatePartFile(bool isImporting)
 {
 	// use lowest free partfilenumber for free file (InterCeptor)
 	int i = 0; 
@@ -301,7 +301,7 @@ void CPartFile::CreatePartFile()
 
 	SetFilePath(thePrefs::GetTempDir());
 			
-	if (thePrefs::GetAllocFullFile()) {
+	if (!isImporting && thePrefs::GetAllocFullFile()) {
 		SetStatus(PS_ALLOCATING);
 		CThreadScheduler::AddTask(new CAllocateFileTask(this, thePrefs::AddNewFilesPaused()));
 	} else {
@@ -1046,21 +1046,17 @@ void CPartFile::LoadSourceSeeds()
 	
 	CFile file(seedsPath, CFile::read);
 	if (!file.IsOpened()) {
-		AddLogLineN(CFormat( _("Partfile %s (%s) has no seeds file") )
+		// Exists but can't be opened. Should not happen. Probably permission problem, try to remove it.
+		AddLogLineN(CFormat( _("Can't read seeds file for Partfile %s (%s)") )
 			% m_partmetfilename
 			% GetFileName() );
+		CPath::RemoveFile(seedsPath);
 		return;
 	}	
 	
 		
+	bool badSeedsFile = false;
 	try {
-		if (file.GetLength() <= 1) {
-			AddLogLineN(CFormat( _("Partfile %s (%s) has a void seeds file") )
-				% m_partmetfilename
-				% GetFileName() );
-			return;
-		}
-
 		uint8 src_count = file.ReadUInt8();
 
 		bool bUseSX2Format = (src_count == 0);
@@ -1115,9 +1111,14 @@ void CPartFile::LoadSourceSeeds()
 				% m_partmetfilename
 				% GetFileName()
 				% e.what() );		
+		badSeedsFile = true;
 	}
 
 	file.Close();
+	if (badSeedsFile) {
+		// If we got an exception reading it remove it.
+		CPath::RemoveFile(seedsPath);
+	}
 }		
 
 void CPartFile::PartFileHashFinished(CKnownFile* result)
