summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2013-07-21 16:06:38 +0200
committerCaolán McNamara <caolanm@redhat.com>2013-07-30 08:27:47 +0000
commitc3967de41502f973104b8d42c53f9faf932e2bd7 (patch)
tree108c6d931dc44819ac87793f02ebb00aa4a24512
parentb40012bd6d0b5387005253f1d3f03929ce4d1ac6 (diff)
Bail out early
Change-Id: I4b80a029d5342b180a9f53777f714527b4d3f982 Reviewed-on: https://gerrit.libreoffice.org/5180 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/source/ui/misc/glosdoc.cxx126
1 files changed, 60 insertions, 66 deletions
diff --git a/sw/source/ui/misc/glosdoc.cxx b/sw/source/ui/misc/glosdoc.cxx
index 11c8dc87acf6..63dc8a6e176f 100644
--- a/sw/source/ui/misc/glosdoc.cxx
+++ b/sw/source/ui/misc/glosdoc.cxx
@@ -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 );
- aTemp.EnableKillingFile();
-
- INetURLObject aTempURL( aTemp.GetURL() );
- sRet = aTempURL.GetBase();
- }
- return sRet;
+ OUString rSG = SwGlossaries::GetExtension();
+ //generate generic name
+ utl::TempFile aTemp(OUString("group"), &rSG, &rNewFilePath );
+ aTemp.EnableKillingFile();
+
+ INetURLObject aTempURL( aTemp.GetURL() );
+ return aTempURL.GetBase();
}
/*------------------------------------------------------------------------
@@ -223,63 +218,62 @@ 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();
+ if (!FStatHelper::IsDocument( sOldFileURL ))
{
- 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)
- {
- sal_uInt16 nNewPath = (sal_uInt16)rNewGroup.GetToken(1, GLOS_DELIM).ToInt32();
- if (static_cast<size_t>(nNewPath) < m_PathArr.size())
- {
- String sNewFilePath(m_PathArr[nNewPath]);
- String sNewFileName = lcl_CheckFileName(
- sNewFilePath, rNewGroup.GetToken(0, GLOS_DELIM));
- const sal_uInt16 nFileNameLen = sNewFileName.Len();
- sNewFileName += SwGlossaries::GetExtension();
- String sTempNewFilePath(sNewFilePath);
- sTempNewFilePath += INET_PATH_TOKEN;
- sTempNewFilePath += sNewFileName ;
- bExist = FStatHelper::IsDocument( sTempNewFilePath );
- OSL_ENSURE(!bExist, "group already exists!");
- if(!bExist)
- {
- sal_Bool bCopyCompleted = SWUnoHelper::UCB_CopyFile(
- sOldFileURL, sTempNewFilePath, sal_True );
- if(bCopyCompleted)
- {
- bRet = sal_True;
- RemoveFileFromList( rOldGroup );
+ OSL_FAIL("group doesn't exist!");
+ return sal_False;
+ }
- rNewGroup = sNewFileName.Copy(0, nFileNameLen);
- rNewGroup += GLOS_DELIM;
- rNewGroup += OUString::number(nNewPath);
- if (m_GlosArr.empty())
- {
- GetNameList();
- }
- else
- {
- m_GlosArr.push_back(rNewGroup);
- }
+ sal_uInt16 nNewPath = (sal_uInt16)rNewGroup.GetToken(1, GLOS_DELIM).ToInt32();
+ if (static_cast<size_t>(nNewPath) >= m_PathArr.size())
+ return sal_False;
- sNewFilePath += INET_PATH_TOKEN;
- sNewFilePath += sNewFileName ;
- SwTextBlocks* pNewBlock = new SwTextBlocks( sNewFilePath );
- pNewBlock->SetName(rNewTitle);
- delete pNewBlock;
- }
- }
- }
- }
+ String sNewFilePath(m_PathArr[nNewPath]);
+ String sNewFileName = lcl_CheckFileName(
+ sNewFilePath, rNewGroup.GetToken(0, GLOS_DELIM));
+ const sal_uInt16 nFileNameLen = sNewFileName.Len();
+ sNewFileName += SwGlossaries::GetExtension();
+ String sTempNewFilePath(sNewFilePath);
+ sTempNewFilePath += INET_PATH_TOKEN;
+ sTempNewFilePath += sNewFileName ;
+ if (FStatHelper::IsDocument( sTempNewFilePath ))
+ {
+ OSL_FAIL("group already exists!");
+ return sal_False;
}
- return bRet;
+
+ if (!SWUnoHelper::UCB_CopyFile(sOldFileURL, sTempNewFilePath, sal_True ))
+ return sal_False;
+
+ RemoveFileFromList( rOldGroup );
+
+ rNewGroup = sNewFileName.Copy(0, nFileNameLen);
+ rNewGroup += GLOS_DELIM;
+ rNewGroup += OUString::number(nNewPath);
+ if (m_GlosArr.empty())
+ {
+ GetNameList();
+ }
+ else
+ {
+ m_GlosArr.push_back(rNewGroup);
+ }
+
+ sNewFilePath += INET_PATH_TOKEN;
+ sNewFilePath += sNewFileName ;
+ SwTextBlocks* pNewBlock = new SwTextBlocks( sNewFilePath );
+ pNewBlock->SetName(rNewTitle);
+ delete pNewBlock;
+
+ return sal_True;
}
/*------------------------------------------------------------------------