A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/microsoft/STL/issues/1511 below:

remove does not delete read-only files · Issue #1511 · microsoft/STL · GitHub

Descibe the bug
std::filesystem::remove() does not remove read-only files
The issue with this is that STL sets the FILE_ATTRIBUTE_READONLY bit when we remove the write permissions for a file.
remove should remove such files also.

Command-line test case

C:\Temp>type repro.cpp
#include <filesystem>
#include <iostream>
#include <fstream>

using namespace std;
namespace fs = std::filesystem;

int main()
{
	fs::path testfile("testfile");

	// Create the file
	fstream file;
	file.open(testfile, ios::out);
	file.close();

	// Remove write permissions
	fs::permissions(testfile,
				fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write,
				fs::perm_options::remove);

	error_code E;
	//POSIX remove should remove this as well.
	fs::remove(testfile, E);
	//Should print '5 Access is denied.'
	cout << E.value() << " " << E.message() << endl;
}


C:\Temp>cl /EHsc /std:c++17 /W4 /WX .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.23.28019.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.23.28019.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

C:\Temp>.\repro.exe
5 Access is denied.

Expected behavior
std::filesystem::remove() should remove 'testfile'

STL version
Versions that support std::filesystem


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4