question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CleanDirectory does not clean readonly files.

See original GitHub issue

What 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
WrathZAcommented, Nov 23, 2016

+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.

3reactions
bjorkstrommcommented, Aug 21, 2017

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 with DeleteDirectory in #1574)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found