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
5 stars 8 forks source link

Space in path causes exception #15

Closed skether closed 4 years ago

skether commented 4 years ago

I am trying to access a file on a share with the following code:

var pathWithoutSpace = fs.FileInfo.FromFileName(@"smb://127.0.0.1/TestFolder/TestTest/file.txt");
var fileWithSpace = fs.FileInfo.FromFileName(@"smb://127.0.0.1/TestFolder/TestTest/file space.txt");
var pathWithSpace = fs.FileInfo.FromFileName(@"smb://127.0.0.1/TestFolder/Test Test/file.txt");

The first two are working as expected. The last one where the space is in a directory name fails with the following exception:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=STATUS_OBJECT_NAME_NOT_FOUND: ERRbadFile(0x0002) - EOENT - File Not Found
  Source=SmbAbstraction
  StackTrace:
   at SmbAbstraction.NTStatusExtensions.HandleStatus(NTStatus status)
   at SmbAbstraction.SMBDirectoryInfoFactory.FromDirectoryName(String path, ISMBCredential credential)
   at SmbAbstraction.SMBFileInfo..ctor(String path, IFileSystem fileSystem, FileBasicInformation fileBasicInformation, FileStandardInformation fileStandardInformation, ISMBCredential credential)
   at SmbAbstraction.SMBFileInfoFactory.FromFileName(String path, ISMBCredential credential)
   at SmbAbstraction.SMBFileInfoFactory.FromFileName(String fileName)
   at SmbAbstractionTest.Program.Main() in <REDACTED>\Program.cs:line 42

All of the files exist and accessible.

Tested with version 1.0.10 and 1.0.6 on .NetCore 3.1

Thanks in advance!

Jo0 commented 4 years ago

Just ran through the integration test project with a space in the path. I don't see failures in CanCreateFileInfo, but I see errors in other tests. I'll try to get fixes for this up as soon as I can. Thanks for letting us know about this!

Jo0 commented 4 years ago

When you get a chance, can you share your wire up for everything related to SmbAbstraction just so we can get a better picture as to why you are specifically seeing this error for FileInfo

skether commented 4 years ago

This is my whole test project:

using System;
using SmbAbstraction;

namespace SmbAbstractionTest
{
    class Program
    {
        static void Main()
        {
            var clientFactory = new SMB2ClientFactory();
            var credentialProvider = new SMBCredentialProvider();

            var credential = new SMBCredential(string.Empty, "user", "password", @"smb://127.0.0.1/TestFolder", credentialProvider);
            var fs = new SMBFileSystem(clientFactory, credentialProvider);

            var pathWithoutSpace = fs.FileInfo.FromFileName(@"smb://127.0.0.1/TestFolder/TestTest/file.txt");
            var fileWithSpace = fs.FileInfo.FromFileName(@"smb://127.0.0.1/TestFolder/TestTest/file space.txt");
            var pathWithSpace = fs.FileInfo.FromFileName(@"smb://127.0.0.1/TestFolder/Test Test/file.txt");

            Console.WriteLine("Breakpoint");
        }
    }
}

I have SmbAbstraction v1.0.10 and System.IO.Abstractions v10.0.8 nugets installed.

I have tried on a remote domain joined server as well with the same results.

Jo0 commented 4 years ago

Just fixed this issue with https://github.com/jordanlytle/SmbAbstraction/pull/16

When using paths with the smb:// scheme paths still included the Uri escape symbols and were breaking when being operated against in the SMB client library.

Creating new package version now

Jo0 commented 4 years ago

Version 1.0.11 has these fixes. https://www.nuget.org/packages/SmbAbstraction/1.0.11