directory and file permission Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Natulux
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 242
Joined: Thu Aug 03, 2017 12:20 pm

directory and file permission

Post by Natulux »

Hey guys

I like to use log files, each one created with the date of creation in its name, so that it doesn't grow to big.
Of course this needs cleaning up, so I automatically delete files older than one month.

On my windows x64 machine,
this used to work like expected, until now. Suddenly my log dir has read-only checked. And even though I, as a local admin user, am able to delete said directory, my wxWidgets app can't (access denied).

I create my log directory:

Code: Select all

wxFileName mfn_logDir = wxStandardPaths::Get().GetExecutablePath();
mfn_logDir.AppendDir("logs");
mfn_logDir.SetFullName("");
if (!wxDir::Exists(mfn_logDir.GetFullPath()))
{
	mfn_logDir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
}
And I create the log file:

Code: Select all

wxFileName fn_logfile = mfn_logDir;
wxString datetime = wxDateTime::Now().Format("%Y%m%d");
fn_logfile.AppendDir(datetime);
fn_logfile.SetName(wxDateTime::Now().Format("%Y%m%d-%H%M%S"));
fn_logfile.SetExt("log");

if (!fn_logfile.FileExists())
{
	m_logFile.Create(fn_logfile.GetFullPath(), true, wxS_DEFAULT);
}
And I can write to it:

Code: Select all

if (!m_logFile.IsOpened())
{
	m_logFile.Open(fn_logfile.GetFullPath(), wxFile::write_append);
}

unsigned long long len = strlen((const char*)sText.mb_str(wxConvUTF8));
m_logFile.Write((const char*)sText.mb_str(wxConvUTF8), len);
But I can't delete it anymore:

Code: Select all

if (!wxRemoveFile(rmDir + filename))
{
	wxString sErr = "";
	sErr = "Could not remove file \"" + rmDir + filename + "\"";
	Log(sErr, false);
	// -> Could not remove file "C:\wxWidgets-3.1.1\projects\synMedicoExporter\vc_mswu\Programm\exporterLog\20191209\20191209-154457.log"
}
I guess something that I am unaware of changed for my user profile, because if I check the log file permissions, I have a new entry (that old log files didnt have) with the current user (who created that file) who has only permission to read.
[EDIT:] To clarify: I can write to that file. I just cant delete it anymore!

Any ideas what I or a windows update did here without my knowledge ;-) ?

Thanks.
Natu
Attachments
new.png
new.png (10.6 KiB) Viewed 990 times
old.png
old.png (10.8 KiB) Viewed 990 times
Natulux
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 242
Joined: Thu Aug 03, 2017 12:20 pm

Re: directory and file permission

Post by Natulux »

I think I solved the problem.
I re-set the user permission for the root directory (and thus for all sub directories and files, now and in future) and gave full access.
At least all newly created files can now be deleted by wxW, which is good enough for me.

I guess some windows security update messed with my user profiles...
Post Reply