Some minor cleanup

This makes the code use GetISpoofFile() instead of accessing m_sISpoofFile
directly. Additonally, CFile::GetLongName() is used for printing the filepath.

(This also removes an useless if branch, because nothing here cares if
m_sISpoofFile is empty, we just need the lock file.)

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2011-02-20 10:55:29 +01:00
parent cd78225482
commit f69aeff3d9

22
znc.cpp
View File

@@ -255,9 +255,9 @@ bool CZNC::WriteISpoof(CUser* pUser) {
if (m_pISpoofLockFile != NULL) if (m_pISpoofLockFile != NULL)
return false; return false;
if (!m_sISpoofFile.empty()) { if (!GetISpoofFile().empty()) {
m_pISpoofLockFile = new CFile; m_pISpoofLockFile = new CFile;
if (!m_pISpoofLockFile->TryExLock(m_sISpoofFile, O_RDWR | O_CREAT)) { if (!m_pISpoofLockFile->TryExLock(GetISpoofFile(), O_RDWR | O_CREAT)) {
DEBUG("Couldn't open and lock ISpoofFile: " << strerror(errno)); DEBUG("Couldn't open and lock ISpoofFile: " << strerror(errno));
delete m_pISpoofLockFile; delete m_pISpoofLockFile;
m_pISpoofLockFile = NULL; m_pISpoofLockFile = NULL;
@@ -283,7 +283,7 @@ bool CZNC::WriteISpoof(CUser* pUser) {
if (sData == m_sISpoofFormat) { if (sData == m_sISpoofFormat) {
sData.Replace("%", pUser->GetIdent()); sData.Replace("%", pUser->GetIdent());
} }
DEBUG("Writing [" + sData + "] to ISpoofFile [" + m_sISpoofFile + "]"); DEBUG("Writing [" + sData + "] to ISpoofFile [" + m_pISpoofLockFile->GetLongName() + "]");
m_pISpoofLockFile->Write(sData + "\n"); m_pISpoofLockFile->Write(sData + "\n");
} }
return true; return true;
@@ -293,17 +293,15 @@ void CZNC::ReleaseISpoof() {
if (m_pISpoofLockFile == NULL) if (m_pISpoofLockFile == NULL)
return; return;
if (!m_sISpoofFile.empty()) { if (m_pISpoofLockFile->Seek(0) && m_pISpoofLockFile->Truncate()) {
if (m_pISpoofLockFile->Seek(0) && m_pISpoofLockFile->Truncate()) { DEBUG("Writing [" + m_sOrigISpoof + "] to ISpoofFile [" + m_pISpoofLockFile->GetLongName() + "]");
DEBUG("Writing [" + m_sOrigISpoof + "] to ISpoofFile [" + m_sISpoofFile + "]"); m_pISpoofLockFile->Write(m_sOrigISpoof);
m_pISpoofLockFile->Write(m_sOrigISpoof); } else {
} else { DEBUG("Error while restoring ISpoof: " << strerror(errno));
DEBUG("Error while restoring ISpoof: " << strerror(errno));
}
m_sOrigISpoof = "";
} }
m_sOrigISpoof = "";
delete m_pISpoofLockFile; delete m_pISpoofLockFile;
m_pISpoofLockFile = NULL; m_pISpoofLockFile = NULL;
} }