Example #1
0
/**
 * Tests for pcsl_file_get_time().
 */
void testTimes() {
    int res;
    long time1, time2;
    int fileID;
    int i, j;

    res = pcsl_file_get_time(&dummy1, PCSL_FILE_TIME_LAST_MODIFIED, &time1);
    assertTrue("Time query succeeded for non-existent file", res == -1);

    res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_TRUNC | PCSL_FILE_O_CREAT, (void **)&fileID);
    pcsl_file_close((void *)fileID);
    assertTrue("File creation failed", res == 0);

    res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time1);
    assertTrue("Time query failed", res == 0);
    res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_APPEND, (void **)&fileID);
    assertTrue("File opening failed", res == 0);
    for (i = 0; i < 1000000; i++) {
        res = pcsl_file_write((void *)fileID, (unsigned char *)&time1, 4);
        assertTrue("Write failed", res == 4);
    }
    pcsl_file_close((void *)fileID);

    /* Writing 4 MB to a file should take several seconds */
    res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time2);
    assertTrue("Time query failed", res == 0);
    assertTrue("Modification time should be greater", time2 > time1);

    for (j = 0; j < 10; j++) {
        res = pcsl_file_open(&file1, PCSL_FILE_O_RDWR | PCSL_FILE_O_APPEND, (void **)&fileID);
        assertTrue("File opening failed", res == 0);
        for (i = 0; i < 1000000; i++) {
            res = pcsl_file_read((void *)fileID, (unsigned char *)&time1, 4);
            assertTrue("Read failed", res == 4);
        }
        pcsl_file_close((void *)fileID);
    }

    /* Reading anything from a file shouldn't lead to modification time change */
    res = pcsl_file_get_time(&file1, PCSL_FILE_TIME_LAST_MODIFIED, &time1);
    assertTrue("Time query failed", res == 0);
    assertTrue("Modification time shouldn't change", time1 == time2);

    pcsl_file_unlink(&file1);
}
Example #2
0
void MidpFileSystemMonitor::timerEvent()
{
    static long last = 0;
    long time;

    if (pcsl_file_get_time(&pcslSysMounts,
            PCSL_FILE_TIME_LAST_MODIFIED, &time) == 0) {

        /* first timer event */
        if (last == 0) {
            last = time;
        }
        /* determine whether the file is changed */
        if (time != last) {
            last = time;
            mRoots->update();
        }
    }
}