Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 028eb852 authored by Mike Lockwood's avatar Mike Lockwood Committed by Android Git Automerger
Browse files

am fb623263: DO NOT MERGE MediaScanner: reimplement the ".nomedia" feature for...

am fb623263: DO NOT MERGE MediaScanner: reimplement the ".nomedia" feature for hiding files from the media provider

* commit 'fb6232635d339c83ca100e472b159f103dafb6e2':
  DO NOT MERGE MediaScanner: reimplement the ".nomedia" feature for hiding files from the media provider
parents 0102f691 d691679b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ private:

    status_t doProcessDirectory(
            char *path, int pathRemaining, MediaScannerClient &client,
            ExceptionCheck exceptionCheck, void *exceptionEnv);
            bool noMedia, ExceptionCheck exceptionCheck, void *exceptionEnv);

    MediaScanner(const MediaScanner &);
    MediaScanner &operator=(const MediaScanner &);
@@ -72,10 +72,9 @@ public:
    void endFile();

    virtual bool scanFile(const char* path, long long lastModified,
            long long fileSize, bool isDirectory) = 0;
            long long fileSize, bool isDirectory, bool noMedia) = 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;

protected:
    void convertValues(uint32_t encoding);
+11 −13
Original line number Diff line number Diff line
@@ -70,8 +70,7 @@ status_t MediaScanner::processDirectory(
    client.setLocale(locale());

    status_t result =
        doProcessDirectory(
                pathBuffer, pathRemaining, client, exceptionCheck, exceptionEnv);
        doProcessDirectory(pathBuffer, pathRemaining, client, false, exceptionCheck, exceptionEnv);

    free(pathBuffer);

@@ -80,20 +79,18 @@ status_t MediaScanner::processDirectory(

status_t MediaScanner::doProcessDirectory(
        char *path, int pathRemaining, MediaScannerClient &client,
        ExceptionCheck exceptionCheck, void *exceptionEnv) {
        bool noMedia, ExceptionCheck exceptionCheck, void *exceptionEnv) {
    // 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
    // Treat all files as non-media in directories that contain a  ".nomedia" file
    if (pathRemaining >= 8 /* strlen(".nomedia") */ ) {
        strcpy(fileSpot, ".nomedia");
        if (access(path, F_OK) == 0) {
            LOGD("found .nomedia, skipping directory\n");
            fileSpot[0] = 0;
            client.addNoMediaFolder(path);
            return OK;
            LOGD("found .nomedia, setting noMedia flag\n");
            noMedia = true;
        }

        // restore path
@@ -138,19 +135,20 @@ status_t MediaScanner::doProcessDirectory(
        }
        if (type == DT_REG || type == DT_DIR) {
            if (type == DT_DIR) {
                // ignore directories with a name that starts with '.'
                // set noMedia flag on directories with a name that starts with '.'
                // for example, the Mac ".Trashes" directory
                if (name[0] == '.') continue;
                if (name[0] == '.')
                    noMedia = true;

                // report the directory to the client
                if (stat(path, &statbuf) == 0) {
                    client.scanFile(path, statbuf.st_mtime, 0, true);
                    client.scanFile(path, statbuf.st_mtime, 0, true, noMedia);
                }

                // and now process its contents
                strcat(fileSpot, "/");
                int err = doProcessDirectory(path, pathRemaining - nameLength - 1, client,
                        exceptionCheck, exceptionEnv);
                        noMedia, exceptionCheck, exceptionEnv);
                if (err) {
                    // pass exceptions up - ignore other errors
                    if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
@@ -159,7 +157,7 @@ status_t MediaScanner::doProcessDirectory(
                }
            } else {
                stat(path, &statbuf);
                client.scanFile(path, statbuf.st_mtime, statbuf.st_size, false);
                client.scanFile(path, statbuf.st_mtime, statbuf.st_size, false, noMedia);
                if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
            }
        }