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

Commit 73726920 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Fix media scanning in case readdir() returns type DT_UNKNOWN." into gingerbread

parents e9c5eb24 19348f1c
Loading
Loading
Loading
Loading
+26 −28
Original line number Diff line number Diff line
@@ -127,12 +127,21 @@ status_t MediaScanner::doProcessDirectory(

    while ((entry = readdir(dir))) {
        const char* name = entry->d_name;
        int nameLength = strlen(name);

        // ignore "." and ".."
        if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) {
            continue;
        }

        /* also keep space for '/' in case it's a directory */
        if (nameLength + 1 > pathRemaining) {
            // path too long!
            continue;
        }

        strcpy(fileSpot, name);

        int type = entry->d_type;
        if (type == DT_UNKNOWN) {
            // If the type is unknown, stat() the file instead.
@@ -149,17 +158,7 @@ status_t MediaScanner::doProcessDirectory(
                LOGD("stat() failed for %s: %s", path, strerror(errno) );
            }
        }
        if (type == DT_REG || type == DT_DIR) {
            int nameLength = strlen(name);
            bool isDirectory = (type == DT_DIR);

            if (nameLength > pathRemaining || (isDirectory && nameLength + 1 > pathRemaining)) {
                // path too long!
                continue;
            }

            strcpy(fileSpot, name);
            if (isDirectory) {
        if (type == DT_DIR) {
            // ignore directories with a name that starts with '.'
            // for example, the Mac ".Trashes" directory
            if (name[0] == '.') continue;
@@ -172,7 +171,7 @@ status_t MediaScanner::doProcessDirectory(
                LOGE("Error processing '%s' - skipping\n", path);
                continue;
            }
            } else if (fileMatchesExtension(path, extensions)) {
        } else if (type == DT_REG && fileMatchesExtension(path, extensions)) {
            struct stat statbuf;
            stat(path, &statbuf);
            if (statbuf.st_size > 0) {
@@ -181,7 +180,6 @@ status_t MediaScanner::doProcessDirectory(
            if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
        }
    }
    }

    closedir(dir);
    return OK;