Prevent race condition when reloading local stamps, fix task so "after()" gets called and correct stamp name so they actually get deleted"

This commit is contained in:
Simon Robertshaw 2012-07-21 13:09:59 +01:00
parent 78b1ffb11d
commit 5bf0a084ac
4 changed files with 25 additions and 11 deletions

View File

@ -371,7 +371,7 @@ SaveFile * Client::GetStamp(string stampID)
stampFile.read((char *)tempData, fileSize); stampFile.read((char *)tempData, fileSize);
stampFile.close(); stampFile.close();
SaveFile * file = new SaveFile(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str()); SaveFile * file = new SaveFile(string(stampID).c_str());
GameSave * tempSave = new GameSave((char *)tempData, fileSize); GameSave * tempSave = new GameSave((char *)tempData, fileSize);
file->SetGameSave(tempSave); file->SetGameSave(tempSave);
return file; return file;
@ -388,7 +388,12 @@ void Client::DeleteStamp(string stampID)
{ {
if((*iterator) == stampID) if((*iterator) == stampID)
{ {
remove(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str()); stringstream stampFilename;
stampFilename << STAMPS_DIR;
stampFilename << PATH_SEP;
stampFilename << stampID;
stampFilename << ".stm";
remove(stampFilename.str().c_str());
stampIDs.erase(iterator); stampIDs.erase(iterator);
return; return;
} }

View File

@ -65,8 +65,9 @@ void LocalBrowserController::removeSelectedC()
class RemoveSavesTask : public Task class RemoveSavesTask : public Task
{ {
std::vector<std::string> saves; std::vector<std::string> saves;
LocalBrowserController * c;
public: public:
RemoveSavesTask(std::vector<std::string> saves_) { saves = saves_; } RemoveSavesTask(LocalBrowserController * c, std::vector<std::string> saves_) : c(c) { saves = saves_; }
virtual bool doWork() virtual bool doWork()
{ {
for(int i = 0; i < saves.size(); i++) for(int i = 0; i < saves.size(); i++)
@ -80,10 +81,18 @@ void LocalBrowserController::removeSelectedC()
} }
return true; return true;
} }
virtual void after()
{
c->RefreshSavesList();
}
}; };
std::vector<std::string> selected = browserModel->GetSelected(); std::vector<std::string> selected = browserModel->GetSelected();
new TaskWindow("Removing saves", new RemoveSavesTask(selected)); new TaskWindow("Removing saves", new RemoveSavesTask(this, selected));
}
void LocalBrowserController::RefreshSavesList()
{
ClearSelection(); ClearSelection();
browserModel->UpdateSavesList(browserModel->GetPageNum()); browserModel->UpdateSavesList(browserModel->GetPageNum());
} }

View File

@ -27,6 +27,7 @@ public:
void removeSelectedC(); void removeSelectedC();
void ClearSelection(); void ClearSelection();
void Selected(std::string stampID, bool selected); void Selected(std::string stampID, bool selected);
void RefreshSavesList();
void OpenSave(SaveFile * stamp); void OpenSave(SaveFile * stamp);
void SetStamp(); void SetStamp();
void NextPage(); void NextPage();

View File

@ -86,16 +86,15 @@ void Task::Poll()
notifyStatusMain(); notifyStatusMain();
} }
if(done)
{
pthread_join(doWorkThread, NULL);
pthread_mutex_destroy(&taskMutex);
after();
}
if(newDone!=done) if(newDone!=done)
{ {
done = newDone; done = newDone;
pthread_join(doWorkThread, NULL);
pthread_mutex_destroy(&taskMutex);
after();
notifyDoneMain(); notifyDoneMain();
} }
} }