summaryrefslogtreecommitdiff
path: root/unotools
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 /unotools
parent3d85ec29ddd73ed996debdcf118f8c32774362ed (diff)
move the removeTree function from desktop to unotools
Change-Id: I98d3f4a68abfee42dac987633878b850134671d3
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/ucbhelper/localfilehelper.cxx51
1 files changed, 51 insertions, 0 deletions
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: */