Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Implement GetLogicalDrives for Unix#9745

Merged
stephentoub merged 1 commit into
dotnet:dev/apifrom
JeremyKuhne:GetLogicalDrives2
Jul 3, 2016
Merged

Implement GetLogicalDrives for Unix#9745
stephentoub merged 1 commit into
dotnet:dev/apifrom
JeremyKuhne:GetLogicalDrives2

Conversation

@JeremyKuhne
Copy link
Copy Markdown
Member

Implement and unify code for getting drives/mount points

Split the Interop.MountPoints file to avoid pulling in additional dependencies

@stephentoub, @ericstj

@@ -152,35 +152,11 @@ public long TotalSize

public static DriveInfo[] GetDrives()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that the Unix implementation was so simple it seemed silly to call DriveInfoInternal (and keep wrapping/unwrapping )

Implement and unify code for getting drives/mount points

public override string[] GetLogicalDrives()
{
return DriveInfoInternal.GetLogicalDrives();
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.

Do we need the unix version of DriveInfoInternal? Couldn't this just use:

return Interop.Sys.GetAllMountPoints().ToArray();

and then you can delete that other file? If it was multiple lines and was going to be used in several places, it would make sense to centralize it, but the wrapper is just one line, and this file already calls into Interop.* stuff all over the place. Seems like an unnecessary level of indirection.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I need to use the same exact code in System.Environment. I know it's one line, but it still would be duplicated- which I don't want to do to facilitate keeping them in sync. (Say if Windows decides to allow this API in the Store- which isn't unlikely.)

Copy link
Copy Markdown
Member

@stephentoub stephentoub Jun 30, 2016

Choose a reason for hiding this comment

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

I need to use the same exact code in System.Environment

You won't be able to do that currently: Environment is in coreclr, not corefx. See dotnet/coreclr#6006.

I know it's one line, but it still would be duplicated

I get that, but there's going to be duplication regardless. If there are two calls sites, either you have:

// call site 1
return Interop.Sys.GetAllMountPoints().ToArray();

// call site 2
return Interop.Sys.GetAllMountPoints().ToArray();

or you have:

// call site 1
return DriveInfoInternal.GetLogicalDrives();

// call site 2
return DriveInfoInternal.GetLogicalDrives();

// Separate file containing helper implementation
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Text;

namespace System.IO
{
    /// <summary>Contains internal volume helpers that are shared between many projects.</summary>
    internal static partial class DriveInfoInternal
    {
        internal static string[] GetLogicalDrives()
        {
            return Interop.Sys.GetAllMountPoints().ToArray();
        }
    }
}

I'm not seeing how the latter is better than the former.

GetAllMountPoints itself is the shared helper; there's no need to layer another one on top.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not seeing how the latter is better than the former.

And I'm not seeing the reverse. Even without needing to do it in System.Environment there is still the view from common- it's confusing to see just one platform specific file there. I still think it's far better from a repo comprehension standpoint to keep any implementation that has platform variants in one spot.

I know we have just one line for some of them now, but there is no guarantee that they will stay that way. There also isn't a guarantee on how many consumers there will be in the future. I'd rather see us be strict about the pattern in Common so we don't have auditing headaches as the repo grows. Without a strong argument to not keep variants together in Common I can't see giving that benefit up. Right now the only argument I'm seeing is that it looks silly in FileSystem (and I totally agree it does)- but I don't think is enough to trump a clearer Common.

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.

there is still the view from common- it's confusing to see just one platform specific file there

There are lots of platform-specific files already in Common and that don't have counterparts for other platforms, e.g. the PersistedFiles files in Common/src/System/IO, RowConfigReader in Common/src/System/IO. all of the files under Common/src/System/Net/Security, etc., nevermind all of the files under each platform's Interop folder, which are all by-definition platform-specific and without counterparts. The "view from Common" is not meant to be one where every platform-specific file has a counterpart; it's simply an organized location of files that are shared between assemblies, nothing more, nothing less.

There also isn't a guarantee on how many consumers there will be in the future

The number of consumers will go down in the future, not up. There should really only be at most one assembly in corefx with this functionality compiled into it. Once Environment.GetLogicalDrives() is implemented and exposed in a contract, both System.IO.FileSystem.dll and System.IO.FileSystem.DriveInfo.dll can and should be implemented in terms of that, rather than recompiling this functionality into each assembly. So the functionality you're adding to Common will likely just be deleted, and the more files you add, the more files are going to need to be cleaned up and deleted.

@stephentoub
Copy link
Copy Markdown
Member

Thanks for updating. A couple of more comments about how I think we should simplify it, but once that's done LGTM.

@stephentoub
Copy link
Copy Markdown
Member

I still believe we shouldn't do the factoring of the Common helper, but we don't need to block this PR on that and can address it subsequently.

@stephentoub stephentoub merged commit 1f361a8 into dotnet:dev/api Jul 3, 2016
@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
@JeremyKuhne JeremyKuhne deleted the GetLogicalDrives2 branch January 3, 2017 21:27
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Implement GetLogicalDrives for Unix

Commit migrated from dotnet/corefx@1f361a8
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants