CleanDirectory does not clean readonly files.
See original GitHub issueWhat You Are Seeing?
Trying to run CleanDirectory()
on a folder that has had some readonly
files copied into it using CopyFiles()
The issue is that CleanDirectory()
fails with access denied on the read only files.
What is Expected?
CleanDirectory()
deletes the files even if they are readonly
.
What version of Cake are you using?
0.16.2
Are you running on a 32 or 64 bit system?
x64
What environment are you running on? Windows? Linux? Mac?
Windows
Are you running on a CI Server? If so, which one?
N\A
How Did You Get This To Happen? (Steps to Reproduce)
Add some readonly
xsd files to ./Documents/Schemas/
and run the following cake file twice…
Task("Default")
.Does(() =>
{
var schemaFolder = Argument("schemaFolder", "./artifacts/schemas");
EnsureDirectoryExists(schemaFolder);
CleanDirectory(schemaFolder);
var files = GetFiles("./Documents/Schemas/*.xsd");
CopyFiles(files, schemaFolder);
});
RunTarget("Default");
Output Log
First Run
Preparing to run build script...
Running build script...
Analyzing build script...
Processing build script...
Compiling build script...
========================================
Default
========================================
Executing task: Default
Creating directory C:/Source/Main/artifacts/schemas
Cleaning directory C:/Source/Main/artifacts/schemas
Copying file main.xsd to C:/Source/Main/artifacts/schemas/main.xsd
Copying file sub.xsd to C:/Source/Main/artifacts/schemas/sub.xsd
Finished executing task: Default
Task Duration
--------------------------------------------------
Default 00:00:00.1268127
--------------------------------------------------
Total: 00:00:00.1268127
Second Run
Preparing to run build script...
Running build script...
Analyzing build script...
Processing build script...
Compiling build script...
========================================
Default
========================================
Executing task: Default
Cleaning directory C:/Source/Main/artifacts/schemas
An Error occured when executing task 'default'.
Error: Access to the path 'C:/Source/Main/artifacts/schemas/main.xsd' is denied.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top Results From Across the Web
How do I delete a directory with read-only files in C#? - ...
The best solution is to mark all the files as non-read only, and then delete the directory. // delete/clear hidden attribute File.SetAttributes( ...
Read more >DeleteDirectory cannot delete read-only files · Issue #1564
I would like to have a possibility to remove read-only files either by default or as another option to DeleteDirectory alias.
Read more >Why does Linux not allow deletion of read only directory?
This directory is read only. When I want to delete this subdirectory it throws an error saying that can't delete this directory.
Read more >I am unable to remove "read only" from any of my drives
I am having an issue with all my drives showing up as read only, which does not allow me to change icons or...
Read more >windows 10 does not allow me to remove the read only ...
Cleared: Clear ReadOnly attribute for all files within folder; Gray Square: Take no action (Default on dialog display). It's just extremely poor ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1
I’m trying to make my builds idempotent and when cloning a repo from git, often the .git directory contains read only files which causes DeleteDirectory or CleanDirectory to fail.
What about adding a Force boolean argument (defaulted to false) to Clean/Delete Directory? I’d be happy to contribute.
Related to #1564
Now that #1574 is merged,
IFile
will support changing file attributes in v0.22. This means we could have a overload which has a force option (just like we did withDeleteDirectory
in #1574)