Kaydet (Commit) c3967de4 authored tarafından Matteo Casalin's avatar Matteo Casalin Kaydeden (comit) Caolán McNamara

Bail out early

Change-Id: I4b80a029d5342b180a9f53777f714527b4d3f982
Reviewed-on: https://gerrit.libreoffice.org/5180Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst b40012bd
......@@ -65,28 +65,23 @@ static String lcl_CheckFileName( const OUString& rNewFilePath,
}
sRet = comphelper::string::strip(sRet, ' ');
bool bOk = false;
if( sRet.Len() )
{
String sTmpDir(rNewFilePath);
sTmpDir += INET_PATH_TOKEN;
sTmpDir += sRet;
sTmpDir += SwGlossaries::GetExtension();
bOk = !FStatHelper::IsDocument( sTmpDir );
if (!FStatHelper::IsDocument( sTmpDir ))
return sRet;
}
if( !bOk )
{
OUString rSG = SwGlossaries::GetExtension();
//generate generic name
utl::TempFile aTemp(OUString("group"),
&rSG, &rNewFilePath );
utl::TempFile aTemp(OUString("group"), &rSG, &rNewFilePath );
aTemp.EnableKillingFile();
INetURLObject aTempURL( aTemp.GetURL() );
sRet = aTempURL.GetBase();
}
return sRet;
return aTempURL.GetBase();
}
/*------------------------------------------------------------------------
......@@ -223,21 +218,24 @@ sal_Bool SwGlossaries::NewGroupDoc(String& rGroupName, const String& rTitle)
sal_Bool SwGlossaries::RenameGroupDoc(
const String& rOldGroup, String& rNewGroup, const String& rNewTitle )
{
sal_Bool bRet = sal_False;
sal_uInt16 nOldPath = (sal_uInt16)rOldGroup.GetToken(1, GLOS_DELIM).ToInt32();
if (static_cast<size_t>(nOldPath) < m_PathArr.size())
{
if (static_cast<size_t>(nOldPath) >= m_PathArr.size())
return sal_False;
String sOldFileURL(m_PathArr[nOldPath]);
sOldFileURL += INET_PATH_TOKEN;
sOldFileURL += rOldGroup.GetToken(0, GLOS_DELIM);
sOldFileURL += SwGlossaries::GetExtension();
sal_Bool bExist = FStatHelper::IsDocument( sOldFileURL );
OSL_ENSURE(bExist, "group doesn't exist!");
if(bExist)
if (!FStatHelper::IsDocument( sOldFileURL ))
{
OSL_FAIL("group doesn't exist!");
return sal_False;
}
sal_uInt16 nNewPath = (sal_uInt16)rNewGroup.GetToken(1, GLOS_DELIM).ToInt32();
if (static_cast<size_t>(nNewPath) < m_PathArr.size())
{
if (static_cast<size_t>(nNewPath) >= m_PathArr.size())
return sal_False;
String sNewFilePath(m_PathArr[nNewPath]);
String sNewFileName = lcl_CheckFileName(
sNewFilePath, rNewGroup.GetToken(0, GLOS_DELIM));
......@@ -246,15 +244,15 @@ sal_Bool SwGlossaries::RenameGroupDoc(
String sTempNewFilePath(sNewFilePath);
sTempNewFilePath += INET_PATH_TOKEN;
sTempNewFilePath += sNewFileName ;
bExist = FStatHelper::IsDocument( sTempNewFilePath );
OSL_ENSURE(!bExist, "group already exists!");
if(!bExist)
if (FStatHelper::IsDocument( sTempNewFilePath ))
{
sal_Bool bCopyCompleted = SWUnoHelper::UCB_CopyFile(
sOldFileURL, sTempNewFilePath, sal_True );
if(bCopyCompleted)
{
bRet = sal_True;
OSL_FAIL("group already exists!");
return sal_False;
}
if (!SWUnoHelper::UCB_CopyFile(sOldFileURL, sTempNewFilePath, sal_True ))
return sal_False;
RemoveFileFromList( rOldGroup );
rNewGroup = sNewFileName.Copy(0, nFileNameLen);
......@@ -274,12 +272,8 @@ sal_Bool SwGlossaries::RenameGroupDoc(
SwTextBlocks* pNewBlock = new SwTextBlocks( sNewFilePath );
pNewBlock->SetName(rNewTitle);
delete pNewBlock;
}
}
}
}
}
return bRet;
return sal_True;
}
/*------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment