wxWidgets wxFile create file first round works, creating second round with overwrite flag fails with Access Denied

segmentation_fault

I can't figure out why I keep getting 'Access Denied'.

I am using wxWidgets to create a file on Windows in the following directory: C:\Users\username\Documents\MyApp. Initially the file won't exist, and it gets created and all is well. Doing this a second or more time results in the error: error 5: Access Denied. This even happens when running the application as administrator...

The file in question is a backup of a sqlite3 database file and backup can be run multiple times in a day and thus can overwrite the previous file. The filename gets today's date appended to it.

Creation of the file is as follows:

bool DatabaseBackup::CreateBackupFile(const wxString& fileName)
{
    wxFile file;
    bool success = file.Create(fileName, true, wxFile::read_write);
    if (!success) {
        pLogger->error("Failed to create file {0}", fileName.ToStdString());
    }
    file.Close();
    return success;
}

There is another function which appends the date as well as attaches the full path to the file name so the result is like so: C:\Users\username\Documents\MyApp\myapp.2020-03-29.db.

I have also tried checking if the file exists beforehand and using wxRemoveFile(fileName), but this also results in the Access Denied error... Creating files in Notepad and Notepad++ works fine.

Am I missing something? I can't figure this out, especially since it creates the file the first time round.

catalin

Remove the 3rd parameter of wxFile::Create(..., wxFile::read_write), so it can take the default wxS_DEFAULT value.

The 3rd parameter requires a value or combination of wxPosixPermissions enum type, not of wxFile::OpenMode enum type.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related