-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Cleanup Utils.FileExists(), Utils.DirectoryExists() and Utils.ItemExists() methods #7129
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
Changes from all commits
9e4faba
0305aee
24d0bac
00ac7e2
c05bf39
71b7e8f
469d7c0
08f3c5a
519474a
cb237d2
53211d1
f38b900
e51e85a
a6dfa41
d4da5f0
3ec7825
adbdb0a
59b0956
201748f
19f1c17
a412981
97bedc7
41cda4b
1075f9f
c53aaa3
ff80c28
b975731
92eaca0
1f065fd
5b04c07
558cd50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1627,32 +1627,33 @@ internal static string LoadStringFromPath(PSCmdlet cmdlet, string path, PSCreden | |
| /// <returns></returns> | ||
| internal static string GetFilePath(string path) | ||
| { | ||
| FileInfo item = new FileInfo(path); | ||
|
|
||
| // We use 'FileInfo.Attributes' (not 'FileInfo.Exist') | ||
| // because we want to get exceptions | ||
| // like UnauthorizedAccessException or IOException. | ||
| if ((int)item.Attributes != -1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please explain how do you decide which
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to keep the logic of the previous code. And I tried to make as few changes as possible. I'm afraid that this PR will grow many times if we try to correct the previous logic in all places where Here I'm afraid that we'll get issues in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think this method
The previous code just used
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Utils.FileExists and Utils.DirectoryExists can throw but File.Exists and Directory.Exists don't throw.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Does this mean for all the places you changed to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I did this commit by commit. [daxian-dbw] #Closed |
||
| { | ||
| return path; | ||
| } | ||
| #if UNIX | ||
| // On Linux, file paths are case sensitive. | ||
| // The user does not have control over the files (HelpInfo.xml, .zip, and cab) that are generated by the Publishing team. | ||
| // The logic below is to support updating help content via sourcepath parameter for case insensitive files. | ||
| FileInfo item = new FileInfo(path); | ||
| string directoryPath = item.Directory.FullName; | ||
| var dirInfo = item.Directory; | ||
| string fileName = item.Name; | ||
|
|
||
| // Prerequisite: The directory in the given path must exist and it is case sensitive. | ||
| if (Utils.DirectoryExists(directoryPath)) | ||
| if (dirInfo.Exists) | ||
| { | ||
| // Get the list of files in the directory. | ||
| string[] fileList = Directory.GetFiles(directoryPath); | ||
| foreach (string filePath in fileList) | ||
| FileInfo[] fileList = dirInfo.GetFiles(searchPattern: fileName, new System.IO.EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive }); | ||
|
|
||
| if (fileList.Length > 0) | ||
| { | ||
| if (filePath.EndsWith(fileName, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return filePath; | ||
| } | ||
| return fileList[0].FullName; | ||
| } | ||
| } | ||
| #else | ||
| if (Utils.FileExists(path)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part was in windows-only section. You moved it above at the beginning of the method, but that's not made "compile-only-windows"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed that we will always receive the path with the right case. (Seems we get the path in code not from user). So the first block will always return a value on all platforms. The code below will only search the file on Unix with ignoring case.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it makes sense to to always have that check on all plats. #closed |
||
| { | ||
| return path; | ||
| } | ||
| #endif | ||
| return 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.
Should this be
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.
Seems original code is easier to understand.