aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Amland <thomas.amland@gmail.com>2016-03-02 19:36:12 +0100
committerfritsch <Peter.Fruehberger@gmail.com>2016-03-22 08:17:48 +0100
commit6a76f60e3fc439d9ef919471deb573a06920174b (patch)
treeb08b3f2097100e9d4dbde5c61ce2f8945a84de8a
parent47d207a96b141a40fb7435e7767f8abb75ddaa8b (diff)
AndroidStorageProvider: avoid calling Exists from PumpDriveChangeEvents
and compare all mount points for better change detection
-rw-r--r--xbmc/storage/android/AndroidStorageProvider.cpp39
-rw-r--r--xbmc/storage/android/AndroidStorageProvider.h4
2 files changed, 27 insertions, 16 deletions
diff --git a/xbmc/storage/android/AndroidStorageProvider.cpp b/xbmc/storage/android/AndroidStorageProvider.cpp
index dc0c4189ab..9d2f9dc5d6 100644
--- a/xbmc/storage/android/AndroidStorageProvider.cpp
+++ b/xbmc/storage/android/AndroidStorageProvider.cpp
@@ -55,7 +55,6 @@ static const char * deviceWL[] = {
CAndroidStorageProvider::CAndroidStorageProvider()
{
- m_removableLength = 0;
PumpDriveChangeEvents(NULL);
}
@@ -117,8 +116,10 @@ void CAndroidStorageProvider::GetLocalDrives(VECSOURCES &localDrives)
localDrives.push_back(share);
}
-void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
+std::set<std::string> CAndroidStorageProvider::GetRemovableDrives()
{
+ std::set<std::string> result;
+
// mounted usb disks
char* buf = NULL;
FILE* pipe;
@@ -210,15 +211,7 @@ void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
if(devok && (fsok || mountok))
{
- // Reject unreadable
- if (XFILE::CDirectory::Exists(mountStr))
- {
- CMediaSource share;
- share.strPath = unescape(mountStr);
- share.strName = URIUtils::GetFileName(mountStr);
- share.m_ignore = true;
- removableDrives.push_back(share);
- }
+ result.insert(mountStr);
}
}
}
@@ -226,6 +219,23 @@ void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
}
free(buf);
}
+ return result;
+}
+
+void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
+{
+ for (const auto& mountStr : GetRemovableDrives())
+ {
+ // Reject unreadable
+ if (XFILE::CDirectory::Exists(mountStr))
+ {
+ CMediaSource share;
+ share.strPath = unescape(mountStr);
+ share.strName = URIUtils::GetFileName(mountStr);
+ share.m_ignore = true;
+ removableDrives.push_back(share);
+ }
+ }
}
std::vector<std::string> CAndroidStorageProvider::GetDiskUsage()
@@ -269,9 +279,8 @@ bool CAndroidStorageProvider::Eject(const std::string& mountpath)
bool CAndroidStorageProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
{
- VECSOURCES drives;
- GetRemovableDrives(drives);
- bool changed = drives.size() != m_removableLength;
- m_removableLength = drives.size();
+ auto drives = GetRemovableDrives();
+ bool changed = m_removableDrives != drives;
+ m_removableDrives = std::move(drives);
return changed;
}
diff --git a/xbmc/storage/android/AndroidStorageProvider.h b/xbmc/storage/android/AndroidStorageProvider.h
index 876d478f98..d405c206ed 100644
--- a/xbmc/storage/android/AndroidStorageProvider.h
+++ b/xbmc/storage/android/AndroidStorageProvider.h
@@ -19,6 +19,7 @@
*
*/
+#include <set>
#include "storage/IStorageProvider.h"
class CAndroidStorageProvider : public IStorageProvider
@@ -40,6 +41,7 @@ public:
virtual bool PumpDriveChangeEvents(IStorageEventsCallback *callback);
private:
+ static std::set<std::string> GetRemovableDrives();
std::string unescape(const std::string& str);
- unsigned int m_removableLength;
+ std::set<std::string> m_removableDrives;
};