Permalink
Browse files

fixed #520 failure of rename on Windows; fixed tests 213, 214

  • Loading branch information...
tomatolog committed Sep 25, 2018
1 parent 1455ba2 commit 0f3cc333f6129451ad1ae2c97905b6c04ba5d454
Showing with 17 additions and 12 deletions.
  1. +1 −1 src/searchd.cpp
  2. +8 −8 src/sphinx.cpp
  3. +5 −0 src/sphinxint.h
  4. +2 −2 src/sphinxplugin.cpp
  5. +1 −1 src/sphinxrt.cpp
@@ -18813,7 +18813,7 @@ static void SphinxqlStateThreadFunc ( void * )
/////////////////////////////////
tWriter.CloseFile();
if ( ::rename ( sNewState.cstr(), g_sSphinxqlState.cstr() )==0 )
if ( sph::rename ( sNewState.cstr(), g_sSphinxqlState.cstr() )==0 )
{
::unlink ( sNewState.cstr() );
} else
@@ -9446,7 +9446,7 @@ bool CSphIndex_VLN::JuggleFile ( const char* szExt, CSphString & sError, bool bN
sExtNew.SetSprintf ( "%s.tmpnew", sExt.cstr() );
sExtOld.SetSprintf ( "%s.tmpold", sExt.cstr() );
if ( ::rename ( sExt.cstr(), sExtOld.cstr() ) )
if ( sph::rename ( sExt.cstr(), sExtOld.cstr() ) )
{
if ( bNeedOrigin )
{
@@ -9455,9 +9455,9 @@ bool CSphIndex_VLN::JuggleFile ( const char* szExt, CSphString & sError, bool bN
}
}
if ( ::rename ( sExtNew.cstr(), sExt.cstr() ) )
if ( sph::rename ( sExtNew.cstr(), sExt.cstr() ) )
{
if ( bNeedOrigin && !::rename ( sExtOld.cstr(), sExt.cstr() ) )
if ( bNeedOrigin && !sph::rename ( sExtOld.cstr(), sExt.cstr() ) )
{
// rollback failed too!
sError.SetSprintf ( "rollback rename to '%s' failed: %s; INDEX UNUSABLE; FIX FILE NAMES MANUALLY", sExt.cstr(), strerrorm(errno) );
@@ -31681,7 +31681,7 @@ static void FinalizeUpgrade ( const char ** sRenames, const char * sBanner, cons
sTo.SetSprintf ( "%s%s", sPath, sRenames[1] );
sRenames += 2;
if ( ::rename ( sFrom.cstr(), sTo.cstr() ) )
if ( sph::rename ( sFrom.cstr(), sTo.cstr() ) )
sphDie ( "%s: rename %s to %s failed: %s\n", sBanner,
sFrom.cstr(), sTo.cstr(), strerrorm(errno) );
}
@@ -32809,7 +32809,7 @@ bool IndexFiles_c::Rename ( const char * sFromSz, const char * sToSz ) // move
sphLogDebug ( "%s unlinked", sTo.cstr() );
#endif
if ( ::rename ( sFrom.cstr (), sTo.cstr () ) )
if ( sph::rename ( sFrom.cstr (), sTo.cstr () ) )
{
// this is no reason to fail if not necessary files missed.
if ( !dExt.m_bNeed )
@@ -32832,7 +32832,7 @@ bool IndexFiles_c::Rename ( const char * sFromSz, const char * sToSz ) // move
const auto &dExt = g_dIndexFilesExts[i];
auto sFrom = FullPath ( dExt.m_sExt, "", sToSz );
auto sTo = FullPath ( dExt.m_sExt, "", sFromSz );
if ( ::rename ( sFrom.cstr (), sTo.cstr () ) )
if ( sph::rename ( sFrom.cstr (), sTo.cstr () ) )
{
sphLogDebug ( "rollback failure when renaming %s to %s", sFrom.cstr (), sTo.cstr () );
m_bFatal = true;
@@ -32852,7 +32852,7 @@ bool IndexFiles_c::RenameLock ( const char * sToSz, int &iLockFD )
StringBuilder_c sError;
#if !USE_WINDOWS
if ( !::rename ( sFrom.cstr (), sTo.cstr () ) )
if ( !sph::rename ( sFrom.cstr (), sTo.cstr () ) )
return true;
m_sLastError.SetSprintf ("failed to rename lock %s to %s, fd=%d, error %s (%d); ", sFrom.cstr(),
@@ -32892,7 +32892,7 @@ bool IndexFiles_c::Rollback ( const char * sBackup, const char * sPath )
::unlink ( sTo.cstr() );
sphLogDebug ( "%s unlinked", sTo.cstr() );
#endif
if ( ::rename ( sFrom.cstr (), sTo.cstr () ) )
if ( sph::rename ( sFrom.cstr (), sTo.cstr () ) )
{
sphLogDebug ( "rollback rename %s to %s failed: %s", sFrom.cstr (), sTo.cstr (), strerrorm ( errno ) );
m_bFatal = true;
@@ -380,6 +380,11 @@ class CSphAutoreader : public CSphReader
};
namespace sph
{
int rename ( const char * sOld, const char * sNew );
}
//////////////////////////////////////////////////////////////////////////
/// generic COM-like uids
@@ -297,7 +297,7 @@ static PluginLib_c * LoadPluginLibrary ( const char * sLibName, CSphString & sEr
if ( bLinuxReload )
{
sTmpfile.SetSprintf ( "%s/%s.%u", g_sPluginDir.cstr(), sLibName, sphRand() );
if ( ::rename ( sLibfile.cstr(), sTmpfile.cstr() ) )
if ( sph::rename ( sLibfile.cstr(), sTmpfile.cstr() ) )
{
sError.SetSprintf ( "failed to rename file (src=%s, dst=%s, errno=%d, error=%s)", sLibfile.cstr(), sTmpfile.cstr(), errno, strerrorm(errno) );
return nullptr;
@@ -316,7 +316,7 @@ static PluginLib_c * LoadPluginLibrary ( const char * sLibName, CSphString & sEr
// rename file back to the original name
if ( bLinuxReload )
{
if ( ::rename ( sTmpfile.cstr(), sLibfile.cstr() ) )
if ( sph::rename ( sTmpfile.cstr(), sLibfile.cstr() ) )
{
sError.SetSprintf ( "failed to rename file (src=%s, dst=%s, errno=%d, error=%s)", sTmpfile.cstr(), sLibfile.cstr(), errno, strerrorm(errno) );
dlclose ( pHandle );
@@ -3875,7 +3875,7 @@ void RtIndex_t::SaveDiskHeader ( const char * sFilename, SphDocID_t iMinDocID, i
namespace sph
{
inline int rename ( const char * sOld, const char * sNew )
int rename ( const char * sOld, const char * sNew )
{
#if USE_WINDOWS
if ( MoveFileEx ( sOld, sNew, MOVEFILE_REPLACE_EXISTING ) )

0 comments on commit 0f3cc33

Please sign in to comment.