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

Commit 6b98328f authored by Jerry Zhang's avatar Jerry Zhang Committed by Android (Google) Code Review
Browse files

Merge "Call access(2) on all files/dirs modified by Mtp" into pi-dev

parents f824853e dc148de2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -809,7 +809,7 @@ MtpResponseCode MtpServer::doGetObject() {
    uint64_t finalsize = sstat.st_size;
    ALOGV("Sent a file over MTP. Time: %f s, Size: %" PRIu64 ", Rate: %f bytes/s",
            diff.count(), finalsize, ((double) finalsize) / diff.count());
    close(mfr.fd);
    closeObjFd(mfr.fd, filePath);
    return result;
}

@@ -887,7 +887,7 @@ MtpResponseCode MtpServer::doGetPartialObject(MtpOperationCode operation) {
        else
            result = MTP_RESPONSE_GENERAL_ERROR;
    }
    close(mfr.fd);
    closeObjFd(mfr.fd, filePath);
    return result;
}

@@ -1043,7 +1043,7 @@ MtpResponseCode MtpServer::doMoveObject() {

    if (info.mStorageID == storageID) {
        ALOGV("Moving file from %s to %s", (const char*)fromPath, (const char*)path);
        if (rename(fromPath, path)) {
        if (renameTo(fromPath, path)) {
            PLOG(ERROR) << "rename() failed from " << fromPath << " to " << path;
            result = MTP_RESPONSE_GENERAL_ERROR;
        }
@@ -1226,7 +1226,7 @@ MtpResponseCode MtpServer::doSendObject() {
    }

    fstat(mfr.fd, &sstat);
    close(mfr.fd);
    closeObjFd(mfr.fd, mSendObjectFilePath);

    if (ret < 0) {
        ALOGE("Mtp receive file got error %s", strerror(errno));
+25 −0
Original line number Diff line number Diff line
@@ -36,6 +36,13 @@ namespace android {

constexpr unsigned long FILE_COPY_SIZE = 262144;

static void access_ok(const char *path) {
    if (access(path, F_OK) == -1) {
        // Ignore. Failure could be common in cases of delete where
        // the metadata was updated through other paths.
    }
}

/*
DateTime strings follow a compatible subset of the definition found in ISO 8601, and
take the form of a Unicode string formatted as: "YYYYMMDDThhmmss.s". In this
@@ -101,6 +108,7 @@ int makeFolder(const char *path) {
    } else {
        chown((const char *)path, getuid(), FILE_GROUP);
    }
    access_ok(path);
    return ret;
}

@@ -181,6 +189,7 @@ int copyFile(const char *fromPath, const char *toPath) {
    LOG(DEBUG) << "Copied a file with MTP. Time: " << diff.count() << " s, Size: " << length <<
        ", Rate: " << ((double) length) / diff.count() << " bytes/s";
    chown(toPath, getuid(), FILE_GROUP);
    access_ok(toPath);
    return ret == -1 ? -1 : 0;
}

@@ -212,6 +221,7 @@ void deleteRecursive(const char* path) {
        } else {
            success = unlink(childPath.c_str());
        }
        access_ok(childPath.c_str());
        if (success == -1)
            PLOG(ERROR) << "Deleting path " << childPath << " failed";
    }
@@ -236,7 +246,22 @@ bool deletePath(const char* path) {
    }
    if (success == -1)
        PLOG(ERROR) << "Deleting path " << path << " failed";
    access_ok(path);
    return success == 0;
}

int renameTo(const char *oldPath, const char *newPath) {
    int ret = rename(oldPath, newPath);
    access_ok(oldPath);
    access_ok(newPath);
    return ret;
}

// Calls access(2) on the path to update underlying filesystems,
// then closes the fd.
void closeObjFd(int fd, const char *path) {
    close(fd);
    access_ok(path);
}

}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -34,7 +34,9 @@ int makeFolder(const char *path);
int copyRecursive(const char *fromPath, const char *toPath);
int copyFile(const char *fromPath, const char *toPath);
bool deletePath(const char* path);
int renameTo(const char *oldPath, const char *newPath);

void closeObjFd(int fd, const char *path);
}; // namespace android

#endif // _MTP_UTILS_H