Skip to content
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

Merged
merged 1 commit into from
Aug 1, 2017

Conversation

DixonDs
Copy link
Contributor

@DixonDs DixonDs commented Apr 18, 2017

Fixes #1564

@dnfclas
Copy link

dnfclas commented Apr 18, 2017

@DixonDs,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@bjorkstromm
Copy link
Member

@DixonDs
Thanks for your PR.

We have been discussing this internally and would rather see this behavior as opt-in. What do you think of creating overloads for all DeleteDirectory aliases?

Preferred solution could be:

DeleteDirectories(ICakeContext, IEnumerable<DirectoryPath>, DeleteDirectorySettings)
DeleteDirectories(ICakeContext, IEnumerable<string>, DeleteDirectorySettings)
DeleteDirectory(ICakeContext, DirectoryPath, DeleteDirectorySettings)

Where DeleteDirectorySettings could look like this:

public class DeleteDirectorySettings
{
   public bool Recursive { get; set; }
   public bool Force { get; set; }
}

@toddstewart
Copy link

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.

Copy link
Member

@bjorkstromm bjorkstromm left a 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

@toddstewart
Copy link

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.

@bjorkstromm
Copy link
Member

@toddstewart sorry, didn't see your comment. Just submitted a review comment 😄

Is there any better name to use than force? Force is quite commonly used in same situtations.. Even though it's called force, it might fail miserably if a) user doesn't have rights to remove files/directories, b) files/directories are in use c) anything else..

@devlead
Copy link
Member

devlead commented Apr 18, 2017

@mholo65 @toddstewart I think Force is an excellent name.

@devlead devlead changed the title Allow deletion of read-only files GH1564: Allow deletion of read-only files Apr 18, 2017
@DixonDs
Copy link
Contributor Author

DixonDs commented Apr 19, 2017

@mholo65 I've added overloads with DeleteDirectorySettings, but removed the ones with bool recursive which is a breaking change. Let me know if I need to put back those overloads with the boolean recursive flag.

Copy link
Member

@bjorkstromm bjorkstromm left a 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.

@@ -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);
Copy link
Member

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.

Copy link
Contributor Author

@DixonDs DixonDs Apr 19, 2017

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

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@bjorkstromm bjorkstromm Apr 19, 2017

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DixonDs IFileprovides the Path so you can create a System.IO.FileInfo from that.

Copy link
Contributor Author

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?

Copy link
Member

@devlead devlead left a 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.

@DixonDs
Copy link
Contributor Author

DixonDs commented Apr 30, 2017

@mholo65 @devlead Could you please review the latest changes?

Copy link
Member

@bjorkstromm bjorkstromm left a 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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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.

@@ -158,9 +164,11 @@ private long GetPosition(FileMode fileMode, out bool fileWasCreated)
case FileMode.Truncate:
Length = 0;
return 0;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line

case FileMode.Open:
case FileMode.OpenOrCreate:
return 0;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line

@@ -176,6 +184,7 @@ private long GetPosition(FileMode fileMode, out bool fileWasCreated)
fileWasCreated = true;
Exists = true;
return Length;

Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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

@DixonDs
Copy link
Contributor Author

DixonDs commented May 16, 2017

@mholo65 @devlead Could you please review again?

@bjorkstromm
Copy link
Member

@DixonDs

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!

@DixonDs
Copy link
Contributor Author

DixonDs commented May 16, 2017

@mholo65

would you @DixonDs mind squashing commits before we do the final review

I will do later, but I am just wondering if it makes much sense if you can just complete PR with merge-squash.

@gep13
Copy link
Member

gep13 commented May 16, 2017

@DixonDs no, that is not the process that we follow on this repository, as the git timeline isn't as clear.

@DixonDs
Copy link
Contributor Author

DixonDs commented May 25, 2017

@mholo65 Could you please do the final review?

@bjorkstromm bjorkstromm self-assigned this May 26, 2017
Copy link
Member

@bjorkstromm bjorkstromm left a 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.

@bjorkstromm bjorkstromm changed the title GH1564: Allow deletion of read-only files [HOLD] GH1564: Allow deletion of read-only files May 26, 2017
@bjorkstromm bjorkstromm changed the title [HOLD] GH1564: Allow deletion of read-only files GH1564: Allow deletion of read-only files Jul 29, 2017
Copy link
Member

@bjorkstromm bjorkstromm left a 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; }
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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 😉

@bjorkstromm
Copy link
Member

@DixonDs are you in position to rebase and fix changes requested? Thanks!

@DixonDs
Copy link
Contributor Author

DixonDs commented Jul 31, 2017

@mholo65 done

@devlead
Copy link
Member

devlead commented Jul 31, 2017

@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

Copy link
Member

@devlead devlead left a 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.

@devlead devlead merged commit ba42369 into cake-build:develop Aug 1, 2017
@devlead
Copy link
Member

devlead commented Aug 1, 2017

@DixonDs your changes have been merged, thanks for your contribution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants