jordanlytle / SmbAbstraction

Implements the System.IO.Abstractions interfaces for interacting with the filesystem, and adds support for interacting with UNC or SMB paths
MIT License
6 stars 8 forks source link

Fix SMBDriveInfoFactory.FromDriveName not returning drive info for Linux paths #20

Closed Jo0 closed 4 years ago

Jo0 commented 4 years ago

In SMBDriveInfoFactory we were failing to get DriveInfo for Linux paths and potentially not flowing into System.IO.DriveInfo for Windows drive names.

This PR flips the logic in SMBDriveInfoFactory.FromDriveName to flow into SMB logic if the input string is a share path or a input string[1] that does not exist in GetDrives() of the host file system or does not match the accepted DriveName input.

With the addition of logging, the --logger:"console;verbosity=detailed" flags were added to the dockerfile to help trace issues with Linux testing from a Windows host.

[1] SMBPath.GetPathRoot() returns the entire SharePath. If a consumer were to use SMBPath.GetPathRoot() or SMBDirectoryInfo.Root.FullName as input for SMBDriveInfoFactory.FromDriveName, that is supported rather than just the explicit ShareName.

Jo0 commented 4 years ago

Windows Test

            var clientFactory = new SMB2ClientFactory();
            var credentialProvider = new SMBCredentialProvider();

            var fs = new SMBFileSystem(clientFactory, credentialProvider);

            using var credential = new SMBCredential("<domain>", "<user>, "<password>", @"smb://<domain>/TestUncShare", credentialProvider);

            var shareDriveInfo = fs.DriveInfo.FromDriveName("TestUncShare");
            var sharePathDriveInfo = fs.DriveInfo.FromDriveName(@"smb://<domain>/TestUncShare");
            var cDriveInfo = fs.DriveInfo.FromDriveName("C");
            var cQualDriveInfo = fs.DriveInfo.FromDriveName("C:/");

            var sharePathWithDir = @"smb://<domain>/TestUncShare/Test";
            var localPath = @"C://temp/dir";

            var pathshareDriveInfo = fs.DriveInfo.FromDriveName(sharePathWithDir.ShareName());
            var pathsharePathDriveInfo = fs.DriveInfo.FromDriveName(fs.Path.GetPathRoot(sharePathWithDir));
            var pathcDriveInfo = fs.DriveInfo.FromDriveName(fs.Path.GetPathRoot(localPath));

            var shareDirInfo = fs.DirectoryInfo.FromDirectoryName(@"smb://<domain>/TestUncShare");
            var localDirInfo = fs.DirectoryInfo.FromDirectoryName(@"C://temp");

            var sharedirInfoDriveInfo = fs.DriveInfo.FromDriveName(shareDirInfo.Root.FullName);
            var localDirInfoDriveInfo = fs.DriveInfo.FromDriveName(localDirInfo.Root.FullName);

Linux test

            var clientFactory = new SMB2ClientFactory();
            var credentialProvider = new SMBCredentialProvider();

            var fs = new SMBFileSystem(clientFactory, credentialProvider);

            using var credential = new SMBCredential("<domain>", "<user>", "<password>", @"smb://<domain>/TestUncShare", credentialProvider);

            var shareDriveInfo = fs.DriveInfo.FromDriveName("TestUncShare");
            var sharePathDriveInfo = fs.DriveInfo.FromDriveName(@"smb://<domain>/TestUncShare");
            var rootDriveInfo = fs.DriveInfo.FromDriveName("/");
             var localDriveInfo = fs.DriveInfo.FromDriveName("/home/<host user>");

            var sharePathWithDir = @"smb://<domain>/TestUncShare/Test";
            var rootPath = @"/";
            var localPath = @"/home/<host user>";

            var pathshareDriveInfo = fs.DriveInfo.FromDriveName(sharePathWithDir.ShareName());
            var pathsharePathDriveInfo = fs.DriveInfo.FromDriveName(fs.Path.GetPathRoot(sharePathWithDir));
            var pathrootDriveInfo = fs.DriveInfo.FromDriveName(fs.Path.GetRootPath(rootPath));
            var pathrootLocalDriveInfo = fs.DriveInfo.FromDriveName(fs.Path.GetPathRoot(localPath));

            var shareDirInfo = fs.DirectoryInfo.FromDirectoryName(@"smb://<domain>/TestUncShare");
            var rootDirInfo = fs.DirectoryInfo.FromDirectoryName(@"/");
            var localDirInfo = fs.DirectoryInfo.FromDirectoryName(@"/home/<host user>");

            var sharedirInfoDriveInfo = fs.DriveInfo.FromDriveName(shareDirInfo.Root.FullName);
            var rootDirInfoDriveInfo = fs.DriveInfo.FromDriveName(rootDirInfo.Root.FullName);
            var localDirInfoDriveInfo = fs.DriveInfo.FromDriveName(localDirInfo.Root.FullName);