hack to remove empty parent dirs when remote removing a file
use remove instead of remove_all just to be conservative
Change-Id: I2b26c2baa327696b0a40aebec47f9eeaf40249a9
diff --git a/src/dispatcher.cc b/src/dispatcher.cc
index 7d6927f..717fadb 100644
--- a/src/dispatcher.cc
+++ b/src/dispatcher.cc
@@ -372,12 +372,34 @@
_LOG_DEBUG ("Action to delete " << filename);
filesystem::path absolutePath = m_rootDir / filename;
- if (filesystem::exists(absolutePath))
- {
- // need some protection from local detection of removal
- remove (absolutePath);
- }
- // don't exist
+ try
+ {
+ if (filesystem::exists(absolutePath))
+ {
+ // need some protection from local detection of removal
+ remove (absolutePath);
+
+ // hack to remove empty parent dirs
+ filesystem::path parentPath = absolutePath.parent_path();
+ while (parentPath > m_rootDir)
+ {
+ if (filesystem::is_empty(parentPath))
+ {
+ filesystem::remove(parentPath);
+ parentPath = parentPath.parent_path();
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ // don't exist
+ }
+ catch (filesystem::filesystem_error &error)
+ {
+ _LOG_ERROR ("File operations failed when removing [" << absolutePath << "] (ignoring)");
+ }
}
void