From: <ps...@us...> - 2008-12-06 14:50:01
|
Revision: 1280 http://znc.svn.sourceforge.net/znc/?rev=1280&view=rev Author: psychon Date: 2008-12-06 14:49:56 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Handle read errors in CFile::Copy() This fixes an endless loop (However, I don't know how it happened). Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2008-12-06 14:39:48 UTC (rev 1279) +++ trunk/FileUtils.cpp 2008-12-06 14:49:56 UTC (rev 1280) @@ -200,9 +200,19 @@ } char szBuf[8192]; - unsigned int len = 0; + int len = 0; while ((len = OldFile.Read(szBuf, 8192))) { + if (len < 0) { + DEBUG_ONLY(cout << "CFile::Copy() failed: " << strerror(errno);) + OldFile.Close(); + + // That file is only a partial copy, get rid of it + NewFile.Close(); + NewFile.Delete(); + + return false; + } NewFile.Write(szBuf, len); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sil...@us...> - 2008-12-09 20:25:37
|
Revision: 1287 http://znc.svn.sourceforge.net/znc/?rev=1287&view=rev Author: silverleo Date: 2008-12-09 20:25:34 +0000 (Tue, 09 Dec 2008) Log Message: ----------- Fix a bug introduced in r1280 Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2008-12-07 14:18:23 UTC (rev 1286) +++ trunk/FileUtils.cpp 2008-12-09 20:25:34 UTC (rev 1287) @@ -204,7 +204,7 @@ while ((len = OldFile.Read(szBuf, 8192))) { if (len < 0) { - DEBUG_ONLY(cout << "CFile::Copy() failed: " << strerror(errno);) + DEBUG_ONLY(cout << "CFile::Copy() failed: " << strerror(errno) << endl); OldFile.Close(); // That file is only a partial copy, get rid of it This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2008-12-28 13:03:58
|
Revision: 1306 http://znc.svn.sourceforge.net/znc/?rev=1306&view=rev Author: psychon Date: 2008-12-28 13:03:43 +0000 (Sun, 28 Dec 2008) Log Message: ----------- Improve CFile::ReadLine() a little IMHO it is now a little clearer how this function works and it might be a little faster. Biggest change is that we now read 4k of the file at once instead of reading it in 64byte chunks. I doubt that this causes a lot more memory usage, because CFile instances usually dont live for long, but it should really lower the number of syscalls we need for reading a file. Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2008-12-27 09:06:49 UTC (rev 1305) +++ trunk/FileUtils.cpp 2008-12-28 13:03:43 UTC (rev 1306) @@ -278,8 +278,7 @@ } bool CFile::ReadLine(CString& sData, const CString & sDelimiter) { - char buff[64]; - sData.clear(); + char buff[4096]; if (m_iFD == -1) { return false; @@ -287,16 +286,16 @@ bool bEOF = false; - while (true) { + while (!bEOF) { CString::size_type iFind = m_sBuffer.find(sDelimiter); if (iFind != CString::npos) { + // We found a line, return it sData = m_sBuffer.substr(0, (iFind + 1)); m_sBuffer.erase(0, (iFind + 1)); - break; + return true; } - memset((char *)buff, '\0', 64); - int iBytes = read(m_iFD, buff, 64); + int iBytes = read(m_iFD, buff, sizeof(buff)); switch(iBytes) { case -1: { @@ -312,24 +311,19 @@ break; } } - - if (bEOF) { - break; - } } - CString::size_type iFind = m_sBuffer.find(sDelimiter); - if (iFind != CString::npos) { - return true; - } + // We are at the end of the file or an error happened - if (bEOF && m_sBuffer.size()) { + if (m_sBuffer.size()) { + // ..but there is still some partial line in the buffer sData = m_sBuffer; m_sBuffer.clear(); return true; } - return !bEOF; + // Nothing left for reading :( + return false; } int CFile::Write(const char *pszBuffer, u_int iBytes) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2008-12-31 14:35:01
|
Revision: 1316 http://znc.svn.sourceforge.net/znc/?rev=1316&view=rev Author: psychon Date: 2008-12-31 14:34:55 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Use fchmod() instead of chmod() if the file is already open Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2008-12-31 13:49:29 UTC (rev 1315) +++ trunk/FileUtils.cpp 2008-12-31 14:34:55 UTC (rev 1316) @@ -223,7 +223,10 @@ } bool CFile::Chmod(mode_t mode) { - return CFile::Chmod(m_sLongName, mode); + if (m_iFD == -1) { + return false; + } + return (fchmod(m_iFD, mode) == 0); } bool CFile::Chmod(const CString& sFile, mode_t mode) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-01-23 13:50:59
|
Revision: 1341 http://znc.svn.sourceforge.net/znc/?rev=1341&view=rev Author: psychon Date: 2009-01-23 13:50:53 +0000 (Fri, 23 Jan 2009) Log Message: ----------- Cleanup: Remove an unnecessary scope operator Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-01-22 17:52:35 UTC (rev 1340) +++ trunk/FileUtils.cpp 2009-01-23 13:50:53 UTC (rev 1341) @@ -394,7 +394,7 @@ return false; } - if (::flock(m_iFD, iOperation) != 0) { + if (flock(m_iFD, iOperation) != 0) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-01-28 09:55:38
|
Revision: 1354 http://znc.svn.sourceforge.net/znc/?rev=1354&view=rev Author: psychon Date: 2009-01-28 09:55:32 +0000 (Wed, 28 Jan 2009) Log Message: ----------- Use O_BINARY when opening files if it is available Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-01-27 19:56:05 UTC (rev 1353) +++ trunk/FileUtils.cpp 2009-01-28 09:55:32 UTC (rev 1354) @@ -16,6 +16,10 @@ # define lstat(a, b) stat(a, b) #endif +#ifndef O_BINARY +# define O_BINARY 0 +#endif + CFile::CFile() { m_iFD = -1; m_bClose = false; @@ -264,7 +268,13 @@ } // We never want to get a controlling TTY through this -> O_NOCTTY - m_iFD = open(m_sLongName.c_str(), iFlags | O_NOCTTY, iMode); + iMode |= O_NOCTTY; + + // Some weird OS from MS needs O_BINARY or else it generates fake EOFs + // when reading ^Z from a file. + iMode |= O_BINARY; + + m_iFD = open(m_sLongName.c_str(), iFlags, iMode); if (m_iFD < 0) return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-01-29 15:39:30
|
Revision: 1355 http://znc.svn.sourceforge.net/znc/?rev=1355&view=rev Author: psychon Date: 2009-01-29 15:39:26 +0000 (Thu, 29 Jan 2009) Log Message: ----------- Make CFile::IsDir() work on those weird OS that don't like trailing slashes Yeah, I'm talking windows here. Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-01-28 09:55:32 UTC (rev 1354) +++ trunk/FileUtils.cpp 2009-01-29 15:39:26 UTC (rev 1355) @@ -57,8 +57,13 @@ } } +bool CFile::IsDir(const CString& sLongName, bool bUseLstat) { + // Some OS don't like trailing slashes for directories + return CFile::FType(sLongName.Trim_Right_n("/"), + FT_DIRECTORY, bUseLstat); +} + bool CFile::IsReg(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_REGULAR, bUseLstat); } -bool CFile::IsDir(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_DIRECTORY, bUseLstat); } bool CFile::IsChr(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_CHARACTER, bUseLstat); } bool CFile::IsBlk(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_BLOCK, bUseLstat); } bool CFile::IsFifo(const CString& sLongName, bool bUseLstat) { return CFile::FType(sLongName, FT_FIFO, bUseLstat); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-01-29 15:41:49
|
Revision: 1356 http://znc.svn.sourceforge.net/znc/?rev=1356&view=rev Author: psychon Date: 2009-01-29 15:41:38 +0000 (Thu, 29 Jan 2009) Log Message: ----------- Just ignore this This commit never happened. You must be dreaming. Really, there is nothing to see here. Still here? Go away! Ok, I suck, feeling better now? Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-01-29 15:39:26 UTC (rev 1355) +++ trunk/FileUtils.cpp 2009-01-29 15:41:38 UTC (rev 1356) @@ -59,7 +59,7 @@ bool CFile::IsDir(const CString& sLongName, bool bUseLstat) { // Some OS don't like trailing slashes for directories - return CFile::FType(sLongName.Trim_Right_n("/"), + return CFile::FType(sLongName.TrimRight_n("/"), FT_DIRECTORY, bUseLstat); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-02-02 15:21:30
|
Revision: 1362 http://znc.svn.sourceforge.net/znc/?rev=1362&view=rev Author: psychon Date: 2009-02-02 15:20:44 +0000 (Mon, 02 Feb 2009) Log Message: ----------- Make CExecSock generate error messages if execvp() fails to find sh I doubt this will ever happen, but let's better be sure... Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-02-02 15:03:32 UTC (rev 1361) +++ trunk/FileUtils.cpp 2009-02-02 15:20:44 UTC (rev 1362) @@ -550,7 +550,9 @@ NULL }; execvp("sh", (char * const *) pArgv); - exit(0); + // if execvp returns, there was an error + perror("execvp"); + exit(1); } close(wpipes[0]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-02-03 18:18:09
|
Revision: 1366 http://znc.svn.sourceforge.net/znc/?rev=1366&view=rev Author: psychon Date: 2009-02-03 18:18:05 +0000 (Tue, 03 Feb 2009) Log Message: ----------- Make CFile::ReadFile() actually honour the max file size we give it Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-02-03 18:15:56 UTC (rev 1365) +++ trunk/FileUtils.cpp 2009-02-03 18:18:05 UTC (rev 1366) @@ -365,6 +365,7 @@ return true; sData.append(buff, iBytes); + iBytesRead += iBytes; } // Buffer limit reached This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sil...@us...> - 2009-02-27 20:58:35
|
Revision: 1404 http://znc.svn.sourceforge.net/znc/?rev=1404&view=rev Author: silverleo Date: 2009-02-27 20:58:34 +0000 (Fri, 27 Feb 2009) Log Message: ----------- CFile::IsDir failed for the root directory "/". This patch fixes that special case. Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-02-27 19:52:31 UTC (rev 1403) +++ trunk/FileUtils.cpp 2009-02-27 20:58:34 UTC (rev 1404) @@ -47,6 +47,9 @@ } bool CFile::IsDir(const CString& sLongName, bool bUseLstat) { + if (sLongName.Equals("/")) + return CFile::FType(sLongName, FT_DIRECTORY, bUseLstat); + // Some OS don't like trailing slashes for directories return CFile::FType(sLongName.TrimRight_n("/"), FT_DIRECTORY, bUseLstat); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-03-31 07:52:27
|
Revision: 1459 http://znc.svn.sourceforge.net/znc/?rev=1459&view=rev Author: psychon Date: 2009-03-31 07:52:24 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Minor cleanup to CFile::ReadLine(), no behavior changes (I hope) Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-03-31 07:34:42 UTC (rev 1458) +++ trunk/FileUtils.cpp 2009-03-31 07:52:24 UTC (rev 1459) @@ -299,14 +299,13 @@ bool CFile::ReadLine(CString& sData, const CString & sDelimiter) { char buff[4096]; + int iBytes; if (m_iFD == -1) { return false; } - bool bEOF = false; - - while (!bEOF) { + do { CString::size_type iFind = m_sBuffer.find(sDelimiter); if (iFind != CString::npos) { // We found a line, return it @@ -315,23 +314,12 @@ return true; } - int iBytes = read(m_iFD, buff, sizeof(buff)); + iBytes = read(m_iFD, buff, sizeof(buff)); - switch(iBytes) { - case -1: { - bEOF = true; - break; - } - case 0: { - bEOF = true; - break; - } - default: { - m_sBuffer.append(buff, iBytes); - break; - } + if (iBytes > 0) { + m_sBuffer.append(buff, iBytes); } - } + } while (iBytes > 0); // We are at the end of the file or an error happened This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-03-31 07:57:02
|
Revision: 1460 http://znc.svn.sourceforge.net/znc/?rev=1460&view=rev Author: psychon Date: 2009-03-31 07:56:55 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Small fix for ReadLine() for multi-byte line delimiters (Oh and empty() is better (tm) than size()) Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-03-31 07:52:24 UTC (rev 1459) +++ trunk/FileUtils.cpp 2009-03-31 07:56:55 UTC (rev 1460) @@ -309,8 +309,8 @@ CString::size_type iFind = m_sBuffer.find(sDelimiter); if (iFind != CString::npos) { // We found a line, return it - sData = m_sBuffer.substr(0, (iFind + 1)); - m_sBuffer.erase(0, (iFind + 1)); + sData = m_sBuffer.substr(0, iFind + sDelimiter.length()); + m_sBuffer.erase(0, iFind + sDelimiter.length()); return true; } @@ -323,7 +323,7 @@ // We are at the end of the file or an error happened - if (m_sBuffer.size()) { + if (!m_sBuffer.empty()) { // ..but there is still some partial line in the buffer sData = m_sBuffer; m_sBuffer.clear(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ps...@us...> - 2009-04-04 11:49:34
|
Revision: 1476 http://znc.svn.sourceforge.net/znc/?rev=1476&view=rev Author: psychon Date: 2009-04-04 11:49:15 +0000 (Sat, 04 Apr 2009) Log Message: ----------- CFile::Close(): check return value of close() for errors Modified Paths: -------------- trunk/FileUtils.cpp Modified: trunk/FileUtils.cpp =================================================================== --- trunk/FileUtils.cpp 2009-04-02 13:05:05 UTC (rev 1475) +++ trunk/FileUtils.cpp 2009-04-04 11:49:15 UTC (rev 1476) @@ -372,7 +372,10 @@ } void CFile::Close() { if (m_iFD >= 0) { - close(m_iFD); + if (close(m_iFD) < 0) { + DEBUG("CFile::Close(): close() failed with [" + << strerror(errno) << "]"); + } } m_iFD = -1; ClearBuffer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |