summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-10-10 17:37:08 +0200
committerMichael Stahl <mstahl@redhat.com>2014-10-11 00:28:48 +0200
commit124a29f0f8dd805ef1d67bd062e1978a8a88e759 (patch)
tree8b6f8e5f26455396c482d45bb952f8959199453f
parent3d85ec29ddd73ed996debdcf118f8c32774362ed (diff)
move the removeTree function from desktop to unotools
Change-Id: I98d3f4a68abfee42dac987633878b850134671d3
-rw-r--r--desktop/source/app/app.cxx54
-rw-r--r--include/unotools/localfilehelper.hxx3
-rw-r--r--unotools/source/ucbhelper/localfilehelper.cxx51
3 files changed, 56 insertions, 52 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index b2c3433dc4cf..537470442956 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -81,6 +81,7 @@
#include <unotools/bootstrap.hxx>
#include <unotools/configmgr.hxx>
#include <unotools/moduleoptions.hxx>
+#include <unotools/localfilehelper.hxx>
#include <officecfg/Office/Common.hxx>
#include <officecfg/Office/Recovery.hxx>
#include <officecfg/Setup.hxx>
@@ -163,57 +164,6 @@ namespace {
#if HAVE_FEATURE_EXTENSIONS
-void removeTree(OUString const & url) {
- osl::Directory dir(url);
- osl::FileBase::RC rc = dir.open();
- switch (rc) {
- case osl::FileBase::E_None:
- break;
- case osl::FileBase::E_NOENT:
- return; //TODO: SAL_WARN if recursive
- default:
- SAL_WARN("desktop.app", "cannot open directory " << dir.getURL() << ": " << +rc);
- return;
- }
- for (;;) {
- osl::DirectoryItem i;
- rc = dir.getNextItem(i, SAL_MAX_UINT32);
- if (rc == osl::FileBase::E_NOENT) {
- break;
- }
- if (rc != osl::FileBase::E_None) {
- SAL_WARN( "desktop.app", "cannot iterate directory " << dir.getURL() << ": " << +rc);
- break;
- }
- osl::FileStatus stat(
- osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
- osl_FileStatus_Mask_FileURL);
- rc = i.getFileStatus(stat);
- if (rc != osl::FileBase::E_None) {
- SAL_WARN( "desktop.app", "cannot stat in directory " << dir.getURL() << ": " << +rc);
- continue;
- }
- if (stat.getFileType() == osl::FileStatus::Directory) { //TODO: symlinks
- removeTree(stat.getFileURL());
- } else {
- rc = osl::File::remove(stat.getFileURL());
- SAL_WARN_IF(
- rc != osl::FileBase::E_None, "desktop.app",
- "cannot remove file " << stat.getFileURL() << ": " << +rc);
- }
- }
- if (dir.isOpen()) {
- rc = dir.close();
- SAL_WARN_IF(
- rc != osl::FileBase::E_None, "desktop.app",
- "cannot close directory " << dir.getURL() << ": " << +rc);
- }
- rc = osl::Directory::remove(url);
- SAL_WARN_IF(
- rc != osl::FileBase::E_None, "desktop.app",
- "cannot remove directory " << url << ": " << +rc);
-}
-
// Remove any existing UserInstallation's extensions cache data remaining from
// old installations. This addresses at least two problems:
//
@@ -285,7 +235,7 @@ bool cleanExtensionCache() {
SAL_WARN( "desktop.app", "cannot open " << fr.getURL() << " for reading: " << +rc);
break;
}
- removeTree(extDir);
+ utl::removeTree(extDir);
OUString userRcFile(
"$UNO_USER_PACKAGES_CACHE/registry/"
"com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc");
diff --git a/include/unotools/localfilehelper.hxx b/include/unotools/localfilehelper.hxx
index 6f695800dfa9..84d5a88994ab 100644
--- a/include/unotools/localfilehelper.hxx
+++ b/include/unotools/localfilehelper.hxx
@@ -52,6 +52,9 @@ namespace utl
static ::com::sun::star::uno::Sequence< OUString >
GetFolderContents( const OUString& rFolder, bool bFolder );
};
+
+ /// recursively remove directory and all contents
+ UNOTOOLS_DLLPUBLIC void removeTree(OUString const & url);
}
#endif
diff --git a/unotools/source/ucbhelper/localfilehelper.cxx b/unotools/source/ucbhelper/localfilehelper.cxx
index 665f6526d42f..1d2dedb36a8c 100644
--- a/unotools/source/ucbhelper/localfilehelper.cxx
+++ b/unotools/source/ucbhelper/localfilehelper.cxx
@@ -193,6 +193,57 @@ typedef ::std::vector< OUString* > StringList_Impl;
return Sequence < OUString > ();
}
+void removeTree(OUString const & url) {
+ osl::Directory dir(url);
+ osl::FileBase::RC rc = dir.open();
+ switch (rc) {
+ case osl::FileBase::E_None:
+ break;
+ case osl::FileBase::E_NOENT:
+ return; //TODO: SAL_WARN if recursive
+ default:
+ SAL_WARN("desktop.app", "cannot open directory " << dir.getURL() << ": " << +rc);
+ return;
+ }
+ for (;;) {
+ osl::DirectoryItem i;
+ rc = dir.getNextItem(i, SAL_MAX_UINT32);
+ if (rc == osl::FileBase::E_NOENT) {
+ break;
+ }
+ if (rc != osl::FileBase::E_None) {
+ SAL_WARN( "desktop.app", "cannot iterate directory " << dir.getURL() << ": " << +rc);
+ break;
+ }
+ osl::FileStatus stat(
+ osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
+ osl_FileStatus_Mask_FileURL);
+ rc = i.getFileStatus(stat);
+ if (rc != osl::FileBase::E_None) {
+ SAL_WARN( "desktop.app", "cannot stat in directory " << dir.getURL() << ": " << +rc);
+ continue;
+ }
+ if (stat.getFileType() == osl::FileStatus::Directory) { //TODO: symlinks
+ removeTree(stat.getFileURL());
+ } else {
+ rc = osl::File::remove(stat.getFileURL());
+ SAL_WARN_IF(
+ rc != osl::FileBase::E_None, "desktop.app",
+ "cannot remove file " << stat.getFileURL() << ": " << +rc);
+ }
+ }
+ if (dir.isOpen()) {
+ rc = dir.close();
+ SAL_WARN_IF(
+ rc != osl::FileBase::E_None, "desktop.app",
+ "cannot close directory " << dir.getURL() << ": " << +rc);
+ }
+ rc = osl::Directory::remove(url);
+ SAL_WARN_IF(
+ rc != osl::FileBase::E_None, "desktop.app",
+ "cannot remove directory " << url << ": " << +rc);
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */