-
-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH1564: Allow deletion of read-only files #1574
Conversation
@DixonDs, |
@DixonDs We have been discussing this internally and would rather see this behavior as opt-in. What do you think of creating overloads for all Preferred solution could be: DeleteDirectories(ICakeContext, IEnumerable<DirectoryPath>, DeleteDirectorySettings)
DeleteDirectories(ICakeContext, IEnumerable<string>, DeleteDirectorySettings)
DeleteDirectory(ICakeContext, DirectoryPath, DeleteDirectorySettings) Where public class DeleteDirectorySettings
{
public bool Recursive { get; set; }
public bool Force { get; set; }
} |
I like the idea of the Force property but you have to take into mind files that are in use. I have run into where a file in the packages directory is in use and cannot be deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior should be opt-in. Please create overloaded aliases where it's possible to remove read-only files. See Comment above
Yes I agree with opt-in but if the property is called Force it does not indicate it is only to delete read only files. Just wanted to point that out. |
@toddstewart sorry, didn't see your comment. Just submitted a review comment 😄 Is there any better name to use than |
@mholo65 @toddstewart I think |
@mholo65 I've added overloads with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DixonDs yes, don't delete the aliases with bool recursive
, becouse as you said, this will be a breaking change.
Just add new aliases with DeleteDirectorySettings settings
and let the old aliases (with bool recursive
) call the new alias with correct settings.
src/Cake.Core/IO/IDirectory.cs
Outdated
@@ -32,7 +32,8 @@ public interface IDirectory : IFileSystemInfo | |||
/// Deletes the directory. | |||
/// </summary> | |||
/// <param name="recursive">Will perform a recursive delete if set to <c>true</c>.</param> | |||
void Delete(bool recursive); | |||
/// <param name="force">Will delete read-only files if set to <c>true</c></param> | |||
void Delete(bool recursive, bool force); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mholo65 I am not sure if there is anything that can be done here to avoid a breaking change. Even I added a separate Delete
overload, that would be a breaking change since all implementations would have to implement that new method from the interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed all interface changes are breaking changes, this would break a few addins an modules. When possible use extension methods or alternatively we need to set a minimum supported cake version going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DixonDs yes, exactly.
Just wondering if the attribute modification should be done elsewhere? E.g. introduce new interface for that.
Thoughts on this @patriksvensson @devlead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mholo65 don't want to litter code base with allot of interfaces either, so one option could be to get this in a milestone/release whilst we have other breaking changes that need a minimum cake version set, i.e. the bigger roslyn refactoring 0.21:isch time frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If doing so that would involve IFile::Delete() too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devlead @mholo65 It could be done in internal DirectoryDeleter
if IFile
provided access to file attributes but it doesn't. But if exposing getting/setting attributes in IFile
deserves a breaking change on its own, that could be an alternative way to go.
Please, advise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devlead Sounds good to me (i.e. having merged in 0.21) when we have other breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DixonDs IFile
provides the Path
so you can create a System.IO.FileInfo
from that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mholo65 Doesn't that defeat the purpose of abstraction? WillDirectoryAliasesTests
work where the fake file system is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few code style issues too
.\src\Cake.Common\IO\DeleteDirectorySettings.cs(1,1): error SA1633: The file header is missing or not located at the top of the file.
.\src\Cake.Common\IO\DeleteDirectorySettings.cs(11,21): error SA1623: The property's documentation summary text must begin with: 'Gets or sets a value indicating whether'
.\src\Cake.Common\IO\DeleteDirectorySettings.cs(16,21): error SA1623: The property's documentation summary text must begin with: 'Gets or sets a value indicating whether'
Running release build should surface these locally.
@mholo65 @devlead Could you please review the latest changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor cosmetic changes.
Could you also add tests which proves that attributes are modified when using Force
option.
@@ -67,7 +67,39 @@ public static ConvertableDirectoryPath Directory(this ICakeContext context, stri | |||
/// <param name="recursive">Will perform a recursive delete if set to <c>true</c>.</param> | |||
[CakeMethodAlias] | |||
[CakeAliasCategory("Delete")] | |||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<DirectoryPath> directories, bool recursive = false) | |||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<DirectoryPath> directories, | |||
bool recursive = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this back up to the previous line.
public static void DeleteDirectories(this ICakeContext context, IEnumerable<DirectoryPath> directories, | ||
bool recursive = false) | ||
{ | ||
if (directories == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant null check. This is also checked in overload.
@@ -97,7 +129,39 @@ public static void DeleteDirectories(this ICakeContext context, IEnumerable<Dire | |||
/// <param name="recursive">Will perform a recursive delete if set to <c>true</c>.</param> | |||
[CakeMethodAlias] | |||
[CakeAliasCategory("Delete")] | |||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<string> directories, bool recursive = false) | |||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<string> directories, | |||
bool recursive = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this back up to the previous line.
public static void DeleteDirectories(this ICakeContext context, IEnumerable<string> directories, | ||
bool recursive = false) | ||
{ | ||
if (directories == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant null check. This is also checked in overload.
src/Cake.Testing/FakeFile.cs
Outdated
@@ -158,9 +164,11 @@ private long GetPosition(FileMode fileMode, out bool fileWasCreated) | |||
case FileMode.Truncate: | |||
Length = 0; | |||
return 0; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra line
src/Cake.Testing/FakeFile.cs
Outdated
case FileMode.Open: | ||
case FileMode.OpenOrCreate: | ||
return 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra line
src/Cake.Testing/FakeFile.cs
Outdated
@@ -176,6 +184,7 @@ private long GetPosition(FileMode fileMode, out bool fileWasCreated) | |||
fileWasCreated = true; | |||
Exists = true; | |||
return Length; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra line
[CakeMethodAlias] | ||
[CakeAliasCategory("Delete")] | ||
public static void DeleteDirectory(this ICakeContext context, DirectoryPath path, | ||
DeleteDirectorySettings settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this up one line
[CakeMethodAlias] | ||
[CakeAliasCategory("Delete")] | ||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<string> directories, | ||
DeleteDirectorySettings settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this up one line
[CakeMethodAlias] | ||
[CakeAliasCategory("Delete")] | ||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<DirectoryPath> directories, | ||
DeleteDirectorySettings settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this up one line
@mholo65 @devlead Could you please review again? |
Looks good to me. I was thinking if we should obsolote the old aliases at the same time. Thoughts @cake-build/cake-team? If @devlead or any other in team doesn't have any opinions on this, would you @DixonDs mind squashing commits before we do the final review. Thanks! |
@mholo65
I will do later, but I am just wondering if it makes much sense if you can just complete PR with merge-squash. |
@DixonDs no, that is not the process that we follow on this repository, as the git timeline isn't as clear. |
fa56863
to
1d169f5
Compare
@mholo65 Could you please do the final review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DixonDs Looks good to me. Thanks for your contribution.
As this PR introduces a breaking change in Cake.Core
, which will most likely break some addins and modules, we won't merge it for the upcoming release. Instead I'll put this on hold and get back to this for the 0.21.0 release.
1d169f5
to
7cf28af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
/// <summary> | ||
/// Gets or sets a value indicating whether to delete read-only files if set to <c>true</c>. | ||
/// </summary> | ||
public bool Force { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should add <remarks>
here that this is false
by default.
@@ -99,6 +129,31 @@ public static void DeleteDirectories(this ICakeContext context, IEnumerable<Dire | |||
[CakeAliasCategory("Delete")] | |||
public static void DeleteDirectories(this ICakeContext context, IEnumerable<string> directories, bool recursive = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cake-build/team should we obsolete these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @cake-build/cake-team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mholo65 Yes, I think we should. Obsolete with a warning message for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mholo65 I am on the fence on this one. They are still valid, as they can be easily mapped into the new way of doing things, so part of me says to leave them. Having said that, would also be happy to see them removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gep13 yes, leave them for a release or two. But obsolete with warning 😉
@DixonDs are you in position to rebase and fix changes requested? Thanks! |
7cf28af
to
48dafcf
Compare
@mholo65 done |
@DixonDs CS0618 needs to be disabled case by case in the test project i.e. #pragma warning disable CS0618 // Type or member is obsolete
var result = Record.Exception(() => DirectoryAliases.DeleteDirectory(null, "/Temp/DoNotExist"));
#pragma warning restore CS0618 // Type or member is obsolete |
48dafcf
to
8c8cf3f
Compare
8c8cf3f
to
2a2c417
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM I'll merge once CI finishes.
2a2c417
to
ba42369
Compare
@DixonDs your changes have been merged, thanks for your contribution 👍 |
Fixes #1564