Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Closed
iSazonov wants to merge 27 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:cleanup-file-existsiSazonov/PowerShell:cleanup-file-existsCopy head branch name to clipboard
Closed

Remove Utils.FileExists(), Utils.DirectoryExists() and Utils.ItemExists() methods#7100
iSazonov wants to merge 27 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:cleanup-file-existsiSazonov/PowerShell:cleanup-file-existsCopy head branch name to clipboard

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.

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

@iSazonov misread the diff. Signed off.

@adityapatwardhan

Copy link
Copy Markdown
Member

@iSazonov Please have a look at the test failures.

@iSazonov iSazonov force-pushed the cleanup-file-exists branch from 4b63525 to a0acbd0 Compare June 20, 2018 05:56
@iSazonov

Copy link
Copy Markdown
Collaborator Author

Rebased to get latest fixes.

@iSazonov iSazonov force-pushed the cleanup-file-exists branch from a0acbd0 to 68d9f25 Compare June 20, 2018 08:05
@iSazonov iSazonov force-pushed the cleanup-file-exists branch from 68d9f25 to 2d28133 Compare June 20, 2018 10:10
Exclude GetFileSystemInfo() and Utils.FileExists()
@iSazonov iSazonov force-pushed the cleanup-file-exists branch 3 times, most recently from e629b77 to 132ef5e Compare June 20, 2018 14:58
@iSazonov iSazonov force-pushed the cleanup-file-exists branch from 132ef5e to 0172040 Compare June 20, 2018 15:28
@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 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.

Thanks @iSazonov

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Continue in #7129

@iSazonov iSazonov closed this Jun 21, 2018
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.