Skip to content

[Listing a MacOS Shared folder] smbclient.walk Generator raises StopIteration when encountering symbolic link #333

@loys-bkube

Description

@loys-bkube

Hello,

Firstly, let me thank you for this amazing project, it makes SMB communication a breeze in python.
I am sorry for my approximative english, it is indeed not my first language.

I am using your package to smbclient.walk through the full tree of a folder shared by a MacOS Sequoia 15.4.1

It works for all my cases but I have a folder where a symlink can be found.

When walk hits the symbolic link, with or without follow_symlinks=True it raises "Runtime Error : Generator raised StopIteration."

But the walk is not complete, the filesystem hasn't been fully iterated through.

Is this normal and expected ?

If it is, how should I walk through a folder using the smbclient.walk function ?

I did a few tests and it seems that :

  • Whether the symlink points outside the targeted root doesn't matter.
  • The folder I'm iterating through can be fully walked if there are no symlinks inside.
  • Tested to walk this folder with the client on a Linux machine AND a Windows, both experience the same issue
  • The error appears also when providing an "onerror" function

I did not test to host the shared folder on another operating system than MacOS 15.4.1.

Below is a reproducting snippet

⚠️ Make sure the folder you're walking through has a subfolder with a symlink inside.

I created mine with ln -s target.txt mylink

import smbclient

def onerror(e):
    print("Error occured", e)

def test_smb():
    try:
        smbclient.register_session("192.168.20.15", username="test", password="****")
        for root, _, files in smbclient.walk("\\\\192.168.20.15\\Bureau\\DossierABkp", topdown=True, onerror=onerror):
            print(root)
            
    except Exception as e:
        print("Une erreur de listing", e)
        # print("Authentication info ", ip, user, password, current_path)
        return []
        
test_smb()

Thank you for your time and this cool project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions