summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-12-16 12:54:24 -0800
committerMike Lockwood <lockwood@android.com>2010-12-16 15:35:36 -0800
commit3e9f9f1596d4225ddd9288b4f7b24a15221374dc (patch)
tree1c88af9da88152b3d499d6a0a92f1a0349bddff9
parent5a7f242cfc0bd3b5208c21c27c0f5f348e98a0dc (diff)
downloadframeworks_av-3e9f9f1596d4225ddd9288b4f7b24a15221374dc.zip
frameworks_av-3e9f9f1596d4225ddd9288b4f7b24a15221374dc.tar.gz
frameworks_av-3e9f9f1596d4225ddd9288b4f7b24a15221374dc.tar.bz2
MediaScanner: Add support for scanning empty directories
Currently the media scanner does not create database entries for directories unless they contain a file that is scanned. Fixing this so we provide a consistent view of the world to MTP. Change-Id: Ia776acfeae23192183e7192d63cdc34d830ea889 Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r--include/media/mediascanner.h3
-rw-r--r--media/libmedia/MediaScanner.cpp16
2 files changed, 12 insertions, 7 deletions
diff --git a/include/media/mediascanner.h b/include/media/mediascanner.h
index 74c9d5d..df5be32 100644
--- a/include/media/mediascanner.h
+++ b/include/media/mediascanner.h
@@ -71,7 +71,8 @@ public:
bool addStringTag(const char* name, const char* value);
void endFile();
- virtual bool scanFile(const char* path, long long lastModified, long long fileSize) = 0;
+ virtual bool scanFile(const char* path, long long lastModified,
+ long long fileSize, bool isDirectory) = 0;
virtual bool handleStringTag(const char* name, const char* value) = 0;
virtual bool setMimeType(const char* mimeType) = 0;
virtual bool addNoMediaFolder(const char* path) = 0;
diff --git a/media/libmedia/MediaScanner.cpp b/media/libmedia/MediaScanner.cpp
index c31b622..5ec573e 100644
--- a/media/libmedia/MediaScanner.cpp
+++ b/media/libmedia/MediaScanner.cpp
@@ -84,6 +84,7 @@ status_t MediaScanner::doProcessDirectory(
// place to copy file or directory name
char* fileSpot = path + strlen(path);
struct dirent* entry;
+ struct stat statbuf;
// ignore directories that contain a ".nomedia" file
if (pathRemaining >= 8 /* strlen(".nomedia") */ ) {
@@ -125,7 +126,6 @@ status_t MediaScanner::doProcessDirectory(
// If the type is unknown, stat() the file instead.
// This is sometimes necessary when accessing NFS mounted filesystems, but
// could be needed in other cases well.
- struct stat statbuf;
if (stat(path, &statbuf) == 0) {
if (S_ISREG(statbuf.st_mode)) {
type = DT_REG;
@@ -142,8 +142,15 @@ status_t MediaScanner::doProcessDirectory(
// for example, the Mac ".Trashes" directory
if (name[0] == '.') continue;
+ // report the directory to the client
+ if (stat(path, &statbuf) == 0) {
+ client.scanFile(path, statbuf.st_mtime, 0, true);
+ }
+
+ // and now process its contents
strcat(fileSpot, "/");
- int err = doProcessDirectory(path, pathRemaining - nameLength - 1, client, exceptionCheck, exceptionEnv);
+ int err = doProcessDirectory(path, pathRemaining - nameLength - 1, client,
+ exceptionCheck, exceptionEnv);
if (err) {
// pass exceptions up - ignore other errors
if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
@@ -151,11 +158,8 @@ status_t MediaScanner::doProcessDirectory(
continue;
}
} else {
- struct stat statbuf;
stat(path, &statbuf);
- if (statbuf.st_size > 0) {
- client.scanFile(path, statbuf.st_mtime, statbuf.st_size);
- }
+ client.scanFile(path, statbuf.st_mtime, statbuf.st_size, false);
if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
}
}