Skip to content

Commit

Permalink
Follow up on ignoring FILE_NOT_FOUND on volume enumeration (#45)
Browse files Browse the repository at this point in the history
Fixes #44 and is a follow-up of #41
  • Loading branch information
stan-sz authored Sep 23, 2024
1 parent 191d3d6 commit 78fbfb2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PropertyGroup>

<!-- DOCSYNC: When changing version number update README.md -->
<Version>0.3.8.0</Version>
<Version>0.3.9.0</Version>
<AssemblyVersion>0.9.9999.0</AssemblyVersion>

<Company>Microsoft</Company>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ File clones on Windows do not actually allocate space on-drive for the clone. Th

[![NuGet version (CopyOnWrite)](https://img.shields.io/nuget/v/CopyOnWrite?style=plastic)](https://www.nuget.org/packages/CopyOnWrite)

* 0.3.9 September 2024: Fix https://github.com/microsoft/CopyOnWrite/issues/44 - follow up on ignoring FILE_NOT_FOUND on volume enumeration
* 0.3.8 March 2024: Fix https://github.com/microsoft/MSBuildSdks/issues/546 - ignore FILE_NOT_FOUND on volume enumeration. Plus add SourceLink to the main library.
* 0.3.7 September 2023: Fix #30 - ignore ACCESS_DENIED on volume enumeration to avoid need to escalate privilege on Windows.
* 0.3.6 July 2023: Set AssemblyVersion to 0.9.9999.0 to allow mixing different minor-version binaries from different packages in the same appdomain/process.
Expand Down
14 changes: 13 additions & 1 deletion lib/Windows/VolumeEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ public IEnumerable<VolumePaths> GetVolumesAndVolumePaths()

while (GetNextVolume(out string? volumeName))
{
yield return new VolumePaths(volumeName!, GetVolumePathNamesForVolumeName(volumeName!, driveLetterUpperToSubstDriveLetterUpper));
IReadOnlyList<string> volumePathNames = GetVolumePathNamesForVolumeName(volumeName!, driveLetterUpperToSubstDriveLetterUpper);
if (volumePathNames.Count == 0)
{
// Skip volumes with no mount points.
continue;
}
yield return new VolumePaths(volumeName!, volumePathNames);
}
}

Expand All @@ -137,6 +143,12 @@ private static IReadOnlyList<string> GetVolumePathNamesForVolumeName(
if (!success)
{
int lastErr = Marshal.GetLastWin32Error();
if (lastErr == NativeMethods.ERROR_FILE_NOT_FOUND)
{
// No mount points for this volume.
return Array.Empty<string>();
}

if (lastErr != NativeMethods.ERROR_MORE_DATA)
{
throw new Win32Exception(lastErr,
Expand Down
6 changes: 2 additions & 4 deletions lib/Windows/VolumeInfoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public VolumeInfo GetVolumeForPath(string path)
"If the drive was added recently you may need to recreate the filesystem cache.");
}

private const int ERROR_FILE_NOT_FOUND = 2;
private const int ERROR_ACCESS_DENIED = 5;
private const int ERROR_NOT_READY = 21;
private const int ERROR_INVALID_PARAMETER = 87;
private const int ERROR_UNRECOGNIZED_VOLUME = 1005;
Expand Down Expand Up @@ -135,8 +133,8 @@ public VolumeInfo GetVolumeForPath(string path)
lastErr == ERROR_NOT_READY ||
lastErr == ERROR_INVALID_PARAMETER ||
lastErr == FVE_E_LOCKED_VOLUME ||
lastErr == ERROR_ACCESS_DENIED ||
lastErr == ERROR_FILE_NOT_FOUND)
lastErr == NativeMethods.ERROR_ACCESS_DENIED ||
lastErr == NativeMethods.ERROR_FILE_NOT_FOUND)
{
return null;
}
Expand Down

0 comments on commit 78fbfb2

Please sign in to comment.