amosavian/AMSMB2

Cannot extract data, move, download, copy; etc. from Linux or Windows shares with latin characters in file name

Closed this issue · 8 comments

I almost re-opened the previous issue I posted, regarding extracting data from files from Windows shares. I thought that was completely fixed by dropping the first slash in the path (not necessary for MacOSX or Linux).

… but I now find there are still problems with files containing certain latin characters, such as í, ì, ñ…; etc.

The files are listed with these characters correctly, they appear in Windows File explorer and other OS's when shared. So I can only think it is a problem with this lib.

This is a very common situation with music files, unless the user's Music lib consists of only "Anglo Saxon" music, for example. So it's a serious limitation.

The problem does seem to be with this library. These latin characters will not work for all functions that perform data fetching (copying, downloading or just fetching data).

These features are only working for MacOS smb shares. They do not work on Linux or Windows.

As per the last couple of comments on the issue I opened for libsmb2

sahlberg/libsmb2#231

… the issue does not appear to be with libsm2 as these functions are working for Linux, when using libsmb2 without this wrapper lib.

The issue appears to be with this wrapper lib.

Grateful if someone could please look into it.

It's a serious limitation of this wrapper lib.

Can you give an example filename? I tried creating a word document with the title:

Some weírd character.docx

Using AMSMB2 I was able to successfully download using:

func downloadItem(atPath path: String, to url: URL, progress: ReadProgressHandler,
                           completionHandler: SimpleCompletionHandler)

Sure, it's really any file with latin characters; e.g. "…/14 Rondeña.flac" as the last path component.

I created a BMP image and gave it the name 14 Rondeña.bmp

This was then shared using Windows 11 and I was able to successfully download it using AMSMB2 with no corruption.

Which windows version are you using for SMB sharing?

I've been using Windows 10. I had the same problem with a Synology NAS running Linux though. It shouldn't make any difference; but could you try it with an audio file? I'm working only with audio files, except for Album covers, which are usually jpeg or png.

Also, I'm attempting to use the library on IOS. Are you testing from IOS or Mac?

Just tried a FLAC file with the filename RONDEÑA.flac and again had no issues, was able to download using AMSMB2 and play it with no corruption.

I'll try to dig out a Windows 10 machine and see if I have any issues.

I'm testing using AMSMB on an iOS app, and currently using an iOS simulator on an M1 Mac.

That's encouraging thanks.

This error maybe is caused by the URL(ios),

I modified the code and it can be read normally (AMSMB2.swift),such as í, ì, ñ…; etc.

private func listDirectory(context: SMB2Context, path: String, recursive: Bool) throws
-> [[URLResourceKey: Any]]
{
var contents = [URLResourceKey: Any]
let dir = try SMB2Directory(path.canonical, on: context)
for ent in dir {
let name = String(cString: ent.name)
if [".", ".."].contains(name) { continue }
var result = URLResourceKey: Any
result[.nameKey] = name

        var resultPath = path
        if (ent.st.isDirectory)
        {
            resultPath.append("/\(name)/")
        }else {
           resultPath.append("/\(name)")
        }
        result[.pathKey] = resultPath
        
        /*result[.pathKey] =
            path.fileURL().appendingPathComponent(name, isDirectory: ent.st.isDirectory).path
        */
        ent.st.populateResourceValue(&result)
        contents.append(result)
    }

    if recursive {
        let subDirectories = contents.filter(\.isDirectory)

        for subDir in subDirectories {
            try contents.append(
                contentsOf: listDirectory(
                    context: context, path: subDir.path.unwrap(), recursive: true
                )
            )
        }
    }

    return contents
}