Skip to content

Remove Utils.FileExists(), Utils.DirectoryExists() and Utils.ItemExists() methods - #7100

Closed
Ilya (iSazonov) wants to merge 27 commits into
PowerShell:masterfrom
iSazonov:cleanup-file-exists
Closed

Ilya (iSazonov) wants to merge 27 commits into
PowerShell:masterfrom
iSazonov:cleanup-file-exists

Conversation

@iSazonov

Copy link
Copy Markdown
Collaborator

PR Summary

Continue #6929

Cleanup code to replace Utils.FileExists(), Utils.DirectoryExists() and Utils.ItemExists() methods with .Net Core methods.

PR Checklist

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return was within the catch block.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Aditya Patwardhan (@adityapatwardhan) Could you please clarify why we should move the return in catch block to continue recursion removal?
Previous code was trying the recursion removal if only we can not remove reparse point silently without any error and exception - is it real scenario?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ilya (@iSazonov) misread the diff. Signed off.

@adityapatwardhan

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Please have a look at the test failures.

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Rebased to get latest fixes.

Exclude GetFileSystemInfo() and Utils.FileExists()
@iSazonov
Ilya (iSazonov) force-pushed the cleanup-file-exists branch 3 times, most recently from e629b77 to 132ef5e Compare June 20, 2018 14:58
@iSazonov

Copy link
Copy Markdown
Collaborator Author

I update some commits:

  • Fix typo if ((int)item.Attributes != 1) -> if ((int)item.Attributes != -1)
  • Replace wrong pattern isDirectory = attrs.HasFlag(FileAttributes.Directory); with isDirectory = exists && attrs.HasFlag(FileAttributes.Directory);
  • Fix CodeFactor issues.

Seems I fixed all Appveyor CI issues. I can not build Unix version locally so I haven't a progress with Travis CI issues.

FileSystemInfo fsinfo = new FileInfo(path);
var attr = fsinfo.Attributes;
var exists = (int)attr != -1;
isContainer = exists && attr.HasFlag(FileAttributes.Directory);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see code like this for checking if a path exists and whether it's directory at 8 places. I think keeping the redundant code in Utils.ItemExists is better. Thoughts?

@iSazonov Ilya (iSazonov) Jun 21, 2018 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agree. I was hoping to remove "unnecessary" checks of existence at all but it's too complicated the PR. I suppose the correct approach is that an operation is performed and an exception is handled instead of up to 6 times to check for each file's existence.
I think I'll close the PR and open new one where add commit by commit to discover and fix Unix issues and replace ItemExists with CheckItemExistsAndThrowOnError .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Continue in #7129

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.

3 participants