Skip to content

Poco::File::setLastModified() doesn't work #438

@bizerba-christoph-ehinger

Description

When using setLastModified() I always get an "Access Denied Exception".
Code to demonstrate:

#include <iostream>
#include <fstream>
#include "Poco/File.h"
#include "Poco/Timestamp.h"
#include "Poco/Exception.h"

int main(int argc, char** argv)
{
    {
        Poco::File file("c:\\temp\\test.txt");
        if (file.exists())
        {
            file.remove();
        }
    }
    {
        std::ofstream out("c:\\temp\\test.txt", ios::out);
        out << "test" <<endl;
        out.flush();
        out.close();
    }

    Poco::File file("c:\\temp\\test.txt");
    Poco::Timestamp ts;
    try
    {
        file.setLastModified(ts);
    }
    catch(Poco::Exception& e)
    {
        cout << e.displayText() << " " << e.message() << endl;
    }

    return 0;
}

I believe this is related to this code in File_Win32.cpp at FileImpl::setLastModifiedImpl():

    FileHandle fh(_path, FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);

When I change the FILE_ALL_ACCESS to FILE_WRITE_ATTRIBUTES the code works.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions